Forum How do I...?

Flatten PDF on output?

j2fly
I have a web page that uses exclusively PNG images, some of which need to be transparent in order for the layout to work. In the digital PrinceXML PDF version the transparency works great, but when I try to print the PDF from a windows machine using Acrobat Reader 9.0 it must first flatten the PDF page by page (a very slow process). The "flattening..." dialog is what I see during this process.

Is there a way for PrinceXML to do that flattening so that my windows users can simply print the PDF without the extremely long wait to flatten client side? I looked through the documentation and searched the forums but haven't been able to find anything about prince doing the flattening. Right now I'm looking into perhaps sending the rendered PDF through pdftk or something similar to try to flatten it. I just don't know if I can do that all programmaticaly so the user clicks 1 button and is presented with a flattened version for download, which is a requirement.

Thank you very much!
-Jon
mikeday
I don't think we've seen this printing delay issue before. Could you send me (mikeday@yeslogic.com) a sample PDF file that demonstrates this issue?
j2fly
Thanks Mike, I have sent you 2 PDFs. Please let me know if you can help!

Thanks again,
-Jon
j2fly
Well, for some reason that email you gave me isn't working. I've uploaded the 2 PDFs here: http://drop.io/princetest

The guest password is your name all lower with no space between (just like the prefix to your email).

Thanks,
-Jon
mikeday
Thanks, I've downloaded the PDFs. Sorry about the email, they must have been too big to be accepted as attachments.
j2fly
Hi Mike,

Any luck looking into those PDFs? I could get you a login to our staging box so you can see the HTML/CSS that is being used to create it as well if that would help.

I have since removed all transparency from all of my PNG images, re-worked the layout and have a new PDF file that I expected to print fast. Unfortunately (even with no transparency) it is not printing fast at all... from PC or Mac, color laser, black & white laser, etc... it just hangs on sending the data to the printer. The hanging used to be on the PC in the "...flattening" stage. That has since been eliminated because the transparency is gone, but now it seems that it is hanging at the printer level (the light just blinks "data"..."data"..."data"). It will eventually print, but 10-15 min print times is not acceptable in the context of how this app is being used in production. Patients are sitting waiting for this report to print out while their doctor stalls for time... not a good situation for anyone (and I look like an idiot :-)

If these files can't print I have no idea what I'm going to do. This web app requires high quality printed reports and I sort of bet the farm on PrinceXML being up for the job. We haven't yet purchased the license, but if/when this gets sorted out my client will be in for the full server license, if that makes any difference in what you're willing to do support wise.

I've uploaded this new 3rd PDF to the drop.io site and it's called "new_layout_no_transparency.pdf"

Thank you so much for your time and I hope that this is identifiable/fixable.

-Jon
mikeday
Thanks! I've taken a look, and the problem seems to start on page 5 of test_transparent.pdf, as testing printing each page individually reveals that the first four pages seem to print much quicker. My first thought was that this could be an issue with a small transparent background image, eg. a 1x1 pixel PNG that is repeated over a wide area, that perhaps Acrobat is having trouble with. But it's going to take some further investigation to figure out exactly what the problem is. By the way, the new_layout_no_transparency.pdf still appears to have some transparency in it. Perhaps it would be helpful to take a look at the HTML and CSS as well, if you can make it available?
j2fly
I didn't see any transparency in the new_layout_no_transparent.pdf file when I checked it's preflight information in Acrobat Pro on my mac: http://grab.by/2FIT. I also ran a ruby script against my folder of pngs that tells me if any of the individual png files contained any transparency and none of them do (that is how I knew which ones I needed to fix in the first place).

Conversely here is the preflight transparency check from the test_transparent.pdf file: http://grab.by/2FIq

I was unable to get the new_layout_no_transparent.pdf file to print at my office from my mac, but when I got home I tried it on my monochrome laser here and it was done printing in under a minute. I am quite unsure what is causing such drastic disparities in the print times with some of these different printers.

I will email you with a login to our staging box so you can see the html/css in context.

Thanks again,
-Jon
_savage
Was there any progress on the flattening problem here? The thread seems a little old now; do new versions of PrinceXML support flattening a layered PDF?
j2fly
Hi _savage,

I don't recall how exactly I fixed this issue, or if I did (I'm at a new job these days and this project is long behind me)... so I know this reply isn't super helpful, but I wanted to ping you back to at least let you know that I do not have an answer. Perhaps if Mike is still around he can respond about the current capabilities.

Good luck!
Jon
mikeday
Prince does not support automatically flattening PDF files that contain transparency at this time. Adding support for this would be a lot of work, I suspect. :)
_savage
It turns out that replacing the PNGs (which had transparent background) with JPG images worked fine.

As far as "flattening" is concerned though, the PDFtk seems to do this on existing PDF documents: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

I haven't tried it out myself yet though...

Edited by _savage

mikeday
Right, flattening the PNG files to remove the alpha channel should also work.