Ensure print double-sided to ensure that reports added with pdf-utils always start on a new page



  • My client does double-sided printing, and wants each report to start on a new page. He has some reports that use pdf-utils to attach reports on append/prepend, but if a report has an odd number of pages, the next report starts on the back of the previous one.

    I evaluated adding an empty page via a pagebreak at the end of each report, but I can't find a way to figure out what page I'm on. I also tried to do this in the headers/footers added via the util, first using $pdf.pageNum in the case of renderForEveryPage, then using the mergewholedocument strategy, but if I add a page here and not in the report on which the merge is made there is no kind of rendering.

    How can I manage this? Any ideas or suggestions?



  • So you append multiple reports using pdf utils.
    And if the individual inner report ends on an odd page, you need to add a page break to avoid the next report gets printed at the back of the previous one.
    You don't know the count of pages of individual reports in advance.
    Right?



  • Correct. I could know the number of page if i'm in the header/footer, but not in the main report so i can't add the last empty page.



  • I am afraid there is no solution for this at this moment. I can be wrong, but at least I don't see it so far.
    The problem is that you can't add a page break using merge operation.
    And append operation always adds at least one page.

    There is a small chance this limited solution satisfy you. However, one option is that append operation adds one or two page breaks.
    This means it would work as expected for odd page numbers, but for even number of pages it would add two blank pages instead of 0.
    Demo here
    https://playground.jsreport.net/w/anon/lj4y6LRe

    I submitted to github task which would solve such cases in general.
    However we will need some time to think it through so don't expect we will solve it in the next weeks.
    https://github.com/jsreport/jsreport/issues/490

    If you are in urgent need, you can always fork jsreport-pdf-utils repository and add what you need.



  • Okay, thanks, I'll think of a solution based on your proposal until I wait for the next release. Thanks again!



  • Hi @dfiorentin could this solve your problem : https://playground.jsreport.net/w/MI53RE/ymmZxJ0F ?
    (did use @jan_blaha solution as base) in this case we only add a blank page to documents with odd number of page without having to edit jsreport-pdf-utils directly



  • Unfortunately, no, because you're manually introducing a counter on the pages. In case the content inserted is too long (You can simulate it by inserting a very long text (such as lorem ipsum) ), you would incur in an automatic pagebreak, and your case does not handle it, while with the solution of jan_blaha yes because the control is done on the number of pages and not on a counter. Thanks anyway for the proposal.



  • Indeed, I didn't realised this aspect, apologies.
    Here is an updated version that will be, again, based on jan_blaha way AND tested against a lorem as you suggested before getting back to you
    https://playground.jsreport.net/w/MI53RE/C3~M5Vyo



  • Yes, it's a good start! If I have n documents in the app you will have to add the function at the beginning of each but it is not a big problem, thank you!

    Remaining on the subject, there are 2 other issues related to double-sided management:

    1. If I am within a cycle in a single report, how do I manage the jump page? Let me explain: let's suppose that I have to print a section in a report several times, and I want it to always start on an even page. Not having the $pdf.pages and not being able to use counters because we do not know how long the previous page can be, how could you do?
    2. In the case of headers added via pdf utils using the merge whole document option, these are also rendered over the blank pages. Is there a workaround to prevent this from happening?

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.