*
The moose likes Other Open Source Projects and the fly likes iText: Reduce size of PDFs generated from PDF forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "iText: Reduce size of PDFs generated from PDF forms" Watch "iText: Reduce size of PDFs generated from PDF forms" New topic
Author

iText: Reduce size of PDFs generated from PDF forms

Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Hej,

we are evaluating to use iText for invoice generation. Right now we have PDF forms that work as layout templates. Filling in and generating the PDFs works. But as soon as fields are filled in the generated PDFs get quite large, from a few kilobytes to megabytes. What is the best way to avoid this? The generated invoices do not need to have any form-related functionality; is it a bad idea to use forms as templates?

Thanks.
Bruno Lowagie
author
Ranch Hand

Joined: Oct 23, 2006
Posts: 88
Hauke Ingmar Schmidt wrote:Hej,

we are evaluating to use iText for invoice generation. Right now we have PDF forms that work as layout templates. Filling in and generating the PDFs works. But as soon as fields are filled in the generated PDFs get quite large, from a few kilobytes to megabytes. What is the best way to avoid this? The generated invoices do not need to have any form-related functionality; is it a bad idea to use forms as templates?

Thanks.


Let me give you an example:

I have a datasheet that is 56.54 KB.
I want to use this template to create a document with 120 pages: one page per movie in my moviedatabase.
If I don't read the documentation, I end up with this document with file size 4.84 MB.
If I read the documentation, I end up with a document containing the same information and file size 304.36 KB.

In the first case, the document size consists of 120 times the size of the template + the size of the content of the fields + some necessary overhead. In the second case, the document size consists of 1 times the size of the template + the size of the content of the fields + some necessary overhead. Not using a template will result in a file with about the same size.

Is this more or less the problem you're experiencing?

If not, there are some other reasons why the filesize of a template that is filled in can get huge: are you adding high resolution images? Are you embedding complete fonts? (See the thread about optimization, more specifically about font subsets.)
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Thank you.

I am not the implementing this, so I will have to talk to the developer to get hard facts.

The document consists of different pages with different templates. The pages are merged into one document after processing. If I regenerate the PDFs as pure pages, i.e. if I print them with a PDF writer or let the media designer do some Adobe magic, the file size is much smaller than the files generated by iText. This lead me to the assumption that there is a form overhead that could be removed by a (simple?) conversion.
Bruno Lowagie
author
Ranch Hand

Joined: Oct 23, 2006
Posts: 88
Hauke Ingmar Schmidt wrote:Thank you.

I am not the implementing this, so I will have to talk to the developer to get hard facts.

The document consists of different pages with different templates. The pages are merged into one document after processing. If I regenerate the PDFs as pure pages, i.e. if I print them with a PDF writer or let the media designer do some Adobe magic, the file size is much smaller than the files generated by iText. This lead me to the assumption that there is a form overhead that could be removed by a (simple?) conversion.


If fonts are the culprit, then the Adobe magic will beat iText. (You need better font management to solve this.)
If redundant templates and/or images are causing the problem, then the developer should use PdfSmartCopy instead of PdfCopy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: iText: Reduce size of PDFs generated from PDF forms