Mathieu,

doing

> stamper.getReader().removeAnnotations();
> stamper.getReader().removeFields();
> stamper.getReader().removeUnusedObjects();
> [...]
> stamper.setFormFlattening(true);
> stamper.setFullCompression();
> stamper.close();

is a bad idea because you at the same time tell the stamper to eventually
flatten a form and remove the information concerning the form fields. Thus,
no wonder you get a corrupt document after the form is flattened based on
removed objects.

I would propose to do all that in two steps, first stamp with form
flattening and store the result (in memory if possible), then read it again,
remove unused objects in a second stamping.

The background: PdfReader.removeUnusedObjects can only remove objects unused
in the PDF as present then in the reader, but the form flattening happens
during stamping, actually at the very end of it, while closing the stamper.

Regards,   Michael



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/How-to-reduce-size-of-PDF-with-form-fields-tp3356683p4659099.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to