Now that I've done a bit more playing, here is what I've seemed to come across.
I can do the following:
public void processLetter2( String pdfLetter )
{
try
{
//-- 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 );
PdfReader reader1 = new PdfReader( pdfLetter + PDF );
PdfStamper stamper = new PdfStamper( reader1, new FileOutputStream(
file ) );
stamper.setFullCompression();
AcroFields form = stamper.getAcroFields();
setFieldsBackgroundColor( form );
Name name= new Name();
name.setFirstName( "William" );
name.setLastName( "Turner" );
String fullname = formFirstLastName( name);
//form.setField( NAME_POSITION_1, fullname );
stamper.setFormFlattening( true );
stamper.setFullCompression();
stamper.close();
reader1.close();
PdfReader reader = new PdfReader( file.getName() );
Document document = new Document( reader.getPageSizeWithRotation( 1
) );
File file2 = new File( "TEST_" + file.getName() );
PdfCopy writer = new PdfCopy( document, new FileOutputStream( file2
) );
document.open();
for( int i = 1; i < reader.getNumberOfPages() + 1; i++ )
{
writer.addPage( writer.getImportedPage( reader, i ) );
}
writer.setFullCompression();
document.close();
reader.close();
//file.delete();
}
catch( Exception e )
{
e.printStackTrace();
}
}
This alone will make the new TEST_xxx.pdf 300K(as was the original PDF document
size). However, by simply commenting the line
// form.setField(...);
then
The newly created file is only 60K in size. I will point out that I am
re-creating a third copy of the file...because oddly enough in my testing and
playing around, I found the first file created is the same size, and simply
running this through PdfCopy appears to allow the final file to be quite small
by comparison. Again, simply setting a form field value doesn't allow the file
to be shrunk any...so what stupid thing do I just not see here?
Re: [iText-questions] PDF Form size From: Mark Storer <msto...@au...> -
2010-01-20 16:40
Attachments: HTML-Email.html
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/