Is there a way (ideally using the Prince PHP class) to get the number of pages for a generated PDF? I'm trying to find a way to create documents that fit on one page. I know Prince has the ability to fit content by width, but I haven't found a way to also fit by height. So my hope was there was a get method for the Prince object to would tell me the number of pages of a PDF doc, and then in a loop I could incrementally decrease the text font-size until the resulting document is 1-page.
Is there anyway to do this? Ideally without the overhead of another lib to re-open the PDF and find out that way. Thanks for any help.
Thanks for the prompt response. I need to do this PDF generation server-side so not entirely sure this will work for us. Basically, I'm doing a nightly cron to generate a bunch of PDFs based on customer data in our system. Would I be able to, server-side only, find the page count in the newly created $dats argument. e.g.
Doesn't that still require a Javascript invocation of the event listener and the call to the function to add total-page-count? That is to say, without some client side JS (this running thru a browser or some complex browser emulator setup), the total-page-count data would not be captured and accessible in the $dats array? Unless I'm missing something... Is there any simple mod you can make to the PHP library so a config can be set to add the event listener and capture the data purely from PHP?
Thanks again for all your help (and patience) Mike.
Oops you will also need to call $prince->setJavascript(1); before performing the conversion, to enable JavaScript. This is an absolutely crucial detail which I completely forgot to mention.
Following up with this, our printing company can't test print the outputted PDFs - their print software doesn't recognize them. I'm guessing I should try the various PDF profile options. I'm just a little confused from the forums on where this stands with the latest Prince code.
2) Should I be duplicating the modifications to the PDF wrapper a user made here http://www.princexml.com/forum/topic/2899/icc-profile-for-the-pdf to avoid losing the modifications you made to prince.php for me earlier in this thread? Though seems like his mods set --profile... I should change it to --pdf-profile?
3) Is there a complete list of profile settings supported in this alpha?
Also, when setting the file to the currently supported PDF/A-1b, and validate, I get the following:
Validating file for conformance level pdfa-1b * The key F is required but missing. * The document does not conform to the requested standard. * The document contains hidden, invisible, non-viewable or non-printable annotations.
All that is gibberish to me... but wondering if there are other settings I need to consider. Also,my version isn't licensed yet. Just want to make sure this will all work for us before plunking down the cash. Is the prince watermark to blame?
The watermark is to blame for the non-printable annotation warning. Not sure about the "key F" issue, any clue as to which object in the file it applies to?
Don't really know enough about the "key F" to know what object it would be. I've attached a PDF that doesn't open right and one that does. Our printer says their software mirrors (in terms of potential errors) this program:
If you open card_331_back1.pdf in a text editor it has a fragment of HTML at the beginning:
<br />
<b>Notice</b>: Undefined index: rotate in <b>/var/www/vhosts/zwrw-2pgp.accessdomain.com/httpdocs/princetest.php</b> on line <b>23</b><br />
<br />
<b>Notice</b>: Undefined index: color in <b>/var/www/vhosts/zwrw-2pgp.accessdomain.com/httpdocs/princetest.php</b> on line <b>28</b><br />