You are creating a LiveCycle/XFA-based form. This is NOT compatible with the
PdfCopy (or PdfSmartCopy) features of iText.
Read the book and the archives for information about why.
Leonard
From: Sean Parsons [mailto:parson...@sbcglobal.net]
Sent: Wednesday, January 20, 2010 7:05 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] PDF Form size
Well, before I do that, let me give some background (I don't want to remove all
the items out of the PDF because they are confidential).
However, I took a form from Word and used LiveCycle to convert it to PDF Form.
I then went into the form and setup the proper field names so that I could
insert values into those fields via iText.
The basic conversion of the saved LiveCycle form ends up being approximately
350K in size.
I had coded all of the stamper, sets, etc to setup those form fields to their
proper values without issue, however the file either remains slightly larger
than the original, or it grows another 75K. Today, I thought I would try to
simply open the PDF, make a copy and be done. This is the code to do this:
public void processLetter2( String pdfLetter )
{
try
{
PdfReader reader = new PdfReader( pdfLetter + PDF );
Document document = new Document( reader.getPageSizeWithRotation( 1
) );
//-- create a new file, removing the directory /letters from the
file name
String sub = StringUtils.substringAfterLast( pdfLetter, "letters/"
);
//sub += strDate;
File file = new File( sub + PDF );
PdfCopy writer = new PdfCopy( document, new FileOutputStream( file
) );
document.open();
for( int i = 1; i < reader.getNumberOfPages() + 1; i++ )
{
writer.addPage( writer.getImportedPage( reader, i ) );
}
writer.setFullCompression();
document.close();
}
catch( Exception e )
{
e.printStackTrace();
}
}
The amazing thing is, this resulted in files being approximately 30 to 70K in
size. I was stunned to say the least. Now, this seems to remove all access to
the form fields which of course is not what I want. However, I thought, I will
run through my original code with the stamper and set my fields to their
appropriate values, and then just take the "newly created file" and run though
the method shown above (hoping there was some odd magic occurring in the write).
However, this doesn't seem to do much of anything to the 3rd file's size
whatsoever. It seems as if the stamper is the issue here. As soon as I use
it, the file size cannot be shrunk.
Am I missing something here?
Thanks
Sean Parsons
Re: [iText-questions] PDF Form size From: Mark Storer <msto...@au...> -
2010-01-20 16:40
Attachments:
HTML-Email.html<https://sourceforge.net/mailarchive/attachment.php?list_name=itext-questions&message_id=bf89f5874ed0cb4797d7f19b932b2ccc043...@sd-ex1.verity.com&counter=1>
Show us your PDF. We'll poke around and see what we can see. You might be
building the
form inefficiently, in which case a code change on your end may produce similar
results.
Might not, too... but we can't tell unless we see a PDF.
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-----Original Message-----
From: sean_pars...@bc... [mailto:sean_pars...@bc...]
Sent: Tuesday, January 19, 2010 11:35 AM
To: itext-questi...@li...
Subject: [iText-questions] PDF Form size
Is there any way to reduce the size of these files? The file I'm generating
winds up being
anywhere from 250 to 300K in size. I can open the file in Acrobat, and select
Optimize, and
it shrinks it to ~32K. Does iText have a way to do this that I'm missing? I've
set
writer.setFullCompression() and it helps, but only takes it from 300 to
270K(ish).
Thanks...
Sean Parsons
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/