Thursday, March 22, 2012

Duplex printing in reporting services

I have been working on this problem for days. I have a report that is grouped
and will be printed duplex (front and back). There is a page break after each
group. I want to ensure that the start of a new group does not end up printed
on the back side of an old group. For example:

Page 1 (printed on front side of paper): group 1
Page 2 (printed on back side of paper): more group 1
Page 3 (printed on front side of paper): more group 1
Page 4 (printed on on back side of paper): group 2 < This is a problem

I need:

Page 1 (front side): group 1
Page 2 (back side): more group 1
Page 3 (front side): more group 1
Page 4 (back side): <This Page Intentionally Left Blank>
Page 5 (front side): group 2

Issues that I've run into include the fact that SSRS renders the entire body
first, before rendering the header/footer. This prevents the body of the
report from knowing which page it will end up on when it is rendered (and is
also why you cannot reference Globals!PageNumber from the body).

The restriction above also prevents using a variable in custom code to know
when to generate a page break. If you set this variable in the header/footer
then the body will never see it as the entire body is rendered first and will
therefore only see the initial state of the variable.

I have seen this issue posted in a number of places,
but no one ever has a solution to this (except switching back to
Crystal Reports). Have any MVPs ever addressed this issue? I am
really hoping someone can offer a good solution or work-around.


Finally - I have resolved this problem. We are writing the results to a pdf file, and was therefore able to use PDFSharp to update the output file before making it available to our users. With PDFSharp, I loop through each page of the exported report and determine whether it is the start of a new group (by checking the contents of the page). If it is a new group and the page number is EVEN, then I insert a blank page just before. So while there is no way to determine page numbers in Reporting Services, there is a way to manipulate the pdf output to be correct for duplex printing.

No comments:

Post a Comment