Here's my sample. It completes without errors, but the output pdf file is 
not readable by Acrobat8 - file damaged and cannot be repaired.

// ATTN, this sample is not funcional!
public class MakePackage {
    public static void main(String args[]) {
        String packageItem[] = {
                "c:\\Attch1.pdf"
        };
        try {
            PdfReader reader = new PdfReader("C:\\60 pdfs\\small doc.pdf"); 
// start package creating with a small pdf file
            FileOutputStream outputStream = new 
FileOutputStream("c:\\test.package.pdf"); // this is the result pdf package
            PdfStamper stamp = new PdfStamper(reader, outputStream); // this 
class will create a package
            Document document = new 
Document(reader.getPageSizeWithRotation(1)); // create a doc with the layout 
of the small pdf file
            PdfWriter attachment = new PdfCopy(document, outputStream); // 
this will be the file we are attaching
            attachment.open(); // we have to open, otherwise 
PdfIndirectReference getPdfIndirectReference() fails
            PdfFileSpecification pdfAttch = 
PdfFileSpecification.fileEmbedded(attachment, packageItem[0], "Attch1.pdf", 
null); // make a reference to the first file to attach
            stamp.addFileAttachment("Attch1.pdf", pdfAttch);// attach the 
file
            stamp.makePackage(new PdfName("Attch1.pdf")); // convert the 
file with attachments to a package
            outputStream.close(); // done
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
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