Unfortunately, my first patch was not perfect. It correctly switches paper sizes so that the printer switches trays, but because I am setting the page size in every page header, in every page header the duplex gets reset to the front side of the sheet, which makes the back sides never being used. So all jobs come out one-sided. The attached patch replaces my first one and fixes the problem. It simply compares the size of the current page with the size of the previous page and only adds a page size request when the page size changes.
Unfortunately, my first patch was not perfect. It correctly switches paper sizes so that the printer switches trays, but because I am setting the page size in every page header, in every page header the duplex gets reset to the front side of the sheet, which makes the back sides never being used. So all jobs come out one-sided. The attached patch replaces my first one and fixes the problem. It simply compares the size of the current page with the size of the previous page and only adds a page size request when the page size changes.