I'm using PdfCopy to bring in a batch of disparate types to a destination PDF
file.  I'm currently seeing a problem where PdfWriter works fine, but
PdfCopy (a subclass of PdfWriter) fails.

Here's a small piece of code that replicates the problem:

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class IText
{
    public static void main( String[] args )
    {
        try
        {
            OutputStream out =  new BufferedOutputStream(new
FileOutputStream( "cow.pdf" ));
            Document doc =  new Document(PageSize.LETTER);

            //PdfWriter writer = PdfWriter.getInstance(doc, out);  // using
this works
            PdfCopy writer = new PdfCopy(doc, out);              // using
this fails

            doc.open();
            try
            {
                File jpgFile = new File( "cow.jpg" );
                Image image = Image.getInstance(jpgFile.getAbsolutePath());
                doc.newPage();

                boolean added = doc.add( image );
                if ( !added )
                {
                    throw new IllegalStateException( "Failed to add image"
);
                }
            }
            finally
            {
                doc.close();
            }
        }
        catch( Throwable t )
        {
            t.printStackTrace( System.out );
        }
    }
}


So, what am I doing wrong?  Can I fix this without using PdfWriter?

The reason I don't want to use PdfWriter is that I've found a set of PDF
files that don't copy over correctly when PdfWriter is used. PdfWriter fails
silently and brings over the PDF pages as blanks.  PdfCopy doesn't have this
problem.

-- 
View this message in context: 
http://www.nabble.com/Using-PdfCopy-with-image-results-in-%22The-document-has-no-pages%22-tf3801508.html#a10755895
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to