Changing page size/orientation

2,427 views
Skip to first unread message

Craig Francis

unread,
Mar 23, 2013, 1:51:15 PM3/23/13
to dom...@googlegroups.com
Is it possible to have a multi-page PDF document, where the first page is in portrait, and subsequent pages in landscape?

And likewise, the first page in A4, and subsequent pages in A3?

Was thinking perhaps calling set_paper/load_html/render() functions multiple times... but it seems "$this->_pdf" in DOMPDF is replaced each time you call render(), and it passes in the paper size/orientation once with Canvas_Factory::get_instance(), which loads the CPDF_Adapter (CPDF) class.

Alternatively could there be an inline <script type="text/php">... which perhaps calls the CPDF class directly, possibly changing 'mediaBox' and $this->currentPageSize?

BrianS

unread,
Mar 24, 2013, 11:55:13 PM3/24/13
to dom...@googlegroups.com
Currently there is no way to do this with dompdf. That's not to say it's impossible, just not with a standard dompdf installation. There is a script that was created by a dompdf user that's supposed to be able to do what you want. It requires some minor modification to some of the dompdf files. I have not had a chance to try it out, so I can't say how well it works. Also, it was developed for 0.6.0 beta 2, so some of the code may need to be updated.

There is a request for this in the issue tracker:

You can find the user script here:

Craig Francis

unread,
Mar 26, 2013, 4:23:46 PM3/26/13
to dom...@googlegroups.com
Thanks Brian for the pointers... got it working in the end.

I can't find a way to simply post the updated code on GitHub, but its on the GoogleGroups post.

I've also trued hacking the CPDF library to support multiple documents via newDocument()... I don't think its complete, but have attached it here anyway.

For reference, I immediately got issues with dompdf frames not being able to find the parent element, and as this involved looking at a second library, I thought it best to leave it there.

Thanks for the pointer, and the really very useful library.

Craig
class.pdf.diff
example.php

BrianS

unread,
Mar 26, 2013, 6:51:49 PM3/26/13
to dom...@googlegroups.com
Glad to hear you got it working. And thanks for posting the code. Github seems to only allow image attachments right now. Which is a bit of an impediment to working out issues, but it's fine to post files here (or elsewhere) and link. git is great for sharing complete code updates, but since we don't have any branches it's hard to share works-in-progress such as this. When I have a moment I'll look at creating "feature" branches for some of the bigger development tasks (like page orientation switching) so that not-quite-complete code can be shared.

Craig Francis

unread,
Mar 27, 2013, 6:44:25 AM3/27/13
to dom...@googlegroups.com
Also forgot last night, while the above may also be useful with the @page ruleset idea...

If you instead want to go down the route of calling set_paper() and render() multiple times, the attached is also a starting point for that (incomplete), as it will call the newDocument() on cpdf instead of creating a new instance... the idea being that the second call to render() should just continue to add to the existing pdf (on a new page), however this is where I had issues with dompdf finding the parent element.
cpdf_adapter.cls.php.diff
dompdf.cls.php.diff

Craig Francis

unread,
Mar 28, 2013, 10:20:32 AM3/28/13
to dom...@googlegroups.com
Have also found a small issue with Adobe Reader, so have decided to put changes on GitHub:


And added a pull request:

Reply all
Reply to author
Forward
0 new messages