Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] size of the pdf created with PdfCopy is larger
 than original pdf

new2pdf

2007-08-07



Hi!

I use PdfCopy create a new pdf document by extracting few pages from another
pdf document. But the newly created pdf has a larger file size than the
original even though it has lesser number pages. Could any one help me
understand why is it like this? This is the code that I am using to create
the pdf.

  public void extractPdfPages(String inFile, String outFile, int[]
pagesToExclude) throws Exception
  {
    // create a reader for the input document
    PdfReader reader = new PdfReader(inFile);
    int pages = reader.getNumberOfPages();
    // create a new document
    Document document = new Document(reader.getPageSizeWithRotation(1));
    PdfCopy copy = new PdfCopy(document, new FileOutputStream(outFile));
    document.open();
    // copy selected pages
    PdfImportedPage page;
    boolean isIncludeThisPage;
    for (int i = 0; i < pages; )
    {
       ++i;
       isIncludeThisPage = true;

       if (pagesToExclude != null && pagesToExclude.length > 0)
       {
          for (int j = 0; j < pagesToExclude.length; j++)
          {
            if (i == pagesToExclude[j])
            {
               isIncludeThisPage = false;
               break;
            }
          }
       }

       if (isIncludeThisPage)
       {
          page = copy.getImportedPage(reader, i);
          copy.addPage(page);
       }
    }
    // close new document
    document.close();
  }
--
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/
©2008 junlu.com - Jax Systems, LLC, U.S.A.