ralfstuckert / pdfbox-layout

MIT License
156 stars 74 forks source link

File Compression #22

Closed atown45 closed 7 years ago

atown45 commented 7 years ago

Is there a way to compress the resulting PDF file prior to writing it to a ServletOutputStream? I've noticed the resulting files are much larger than expected.

ralfstuckert commented 7 years ago

Well, you could just use a GZIPOutputStream, but you got to set the content-encoding response header to gzip. Have a look at http://tutorials.jenkov.com/java-servlets/gzip-servlet-filter.html.

Is that your point?

atown45 commented 7 years ago

No, not really. I have a PDF doc I generated with iText. I am now generating it using pdfbox-layout. When I compare the size of the docs, the one created with pdfbox-layout is much larger than one created with iText. From what I'm able to find online it appear the underlying pdfbox is bloating the file size. It was suggested to compress the file using PDStream but I can't seem to get it to work. Does pdfbox-box have a way to do this or do you have some code snippet using PDSteam on how to do it? My users aren't happy with the bloated file size.

atown45 commented 7 years ago

Sorry, just saw a typo. It should be PDStream not PDSteam.

ralfstuckert commented 7 years ago

Well, I am already setting the compress flag when creating the PDPageContentStream, is there another place to do so? As far as I know there is no global setting in PDFBox

ralfstuckert commented 7 years ago

All I found is an open issue on that: https://issues.apache.org/jira/browse/PDFBOX-2690 Any hints from your side?

ralfstuckert commented 7 years ago

I guess there is nothing much I can do here. Reopen if there is anything I can do