I've tried to make an copy of an existing PDF and add new attachments. It
works with the following code, but I lose the old attachments and the old
bookmarks, although I used PdfCopy, like described in the book from 2006.
I'am using iText 2.1.7
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfFileSpecification;
import com.lowagie.text.pdf.PdfReader;
public class insert_attachment {
public static void main(String[] args) throws IOException,
DocumentException{
PdfReader reader = new PdfReader("/tmp/a.pdf");
int pages = reader.getNumberOfPages();
Document document = new
Document(reader.getPageSizeWithRotation(1));
PdfCopy copy = new PdfCopy(document, new
FileOutputStream("/tmp/b.pdf"));
document.open();
for (int i = 0; i < pages; ) {
++i;
copy.addPage(copy.getImportedPage(reader, i));
}
PdfFileSpecification fs =
PdfFileSpecification.fileEmbedded(copy, "/tmp/a.xml", "a.xml", null);
copy.addFileAttachment(fs);
copy.close();
document.close();
}
}
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Lose-existing-Bookmarks-and-Attachments-with-PdfCopy-tp2239965p2239965.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
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/