On Sunday, January 22, 2012 1:03:07 PM UTC-5, Gabriel wrote:
I'm looking at setting up a pdf where the back page of each printout
has content that is not part of the main HTML document. This is the
terms and conditions for an invoice on the back of each sheet. The
main content can vary in length but the Ts&Cs are fixed
So if I understand ... the front side of each page would be a multi-page document and the backside would be the same one-page document over and over. And to print you would want the odd pages to be the front side and the even pages to be the back side.
I'm guessing this isn't possible with the dompdf class as is but am
sure I should be able to modify the class to intercept the page
breaking and insert the Ts&Cs.
If I could be given a few pointers of where to best start looking at
modifying the class I'd be more than happy to contribute any code I
write.
As things are current designed you would not be able to do this with a clean copy of dompdf. We'd be happy to help you out.
I have two possible idea for how to acheive the end result. Which do
you think is the best approach?
1. Parse two separated DOM inputs simultaneously and generate
alternate pdf pages from the two inputs
2. Pregenerate and cache the back page then splice it in as a new page
each time the NewPage method is called.
Actually, I was thinking of a third option but it depends on the
structure of your Ts&Cs. If the back page is not too complex you
could build it in script. Then all you would need to do is modify dompdf
to run the script at the beginning/end of each page. The script would
build the back page and then start a new page as its last step,
whereupon dompdf would process the next page of your document. This
would require less modification up front, though if your back page is
long and/or complex generating it manually would be a chore. So I would
maybe vote for #2 overall.
Considering the second option I can think of a few ways to try this. The difficult aspect in combining two separately rendered documents is that object references would have to be redone. Perhaps if you could render two document in sequence to the same PDF. Here's what I was thinking for the process: 1) render your back page, 2) copy the page contents to a new object, 3) delete the back page from the pdf, 4) render your main document, 5) have a per-page script that inserts the object and starts a new page. So you would need to modify dompdf to: a) process multiple document in sequence, and b) store and run scripts before/after a page has rendered.
This is all kind of off the top of my head, so I don't know if this will really work. Just tossing it out there...
Check out the enhancement request in
issue 225 for someone's take on rendering multiple HTML segments in sequence.
How intertwined is the DOM parsing and PDF page rendering?
Fabien would be better able to speak to this, but from my understanding things are fairly intertwined. There are basically two passes: first dompdf parses the document to apply styles and other non-rendering tasks; second pass dompdf builds the PDF from the object hierarchy created in the first step.