Your problem is that you do NOT want XMP - you want FDF (or XFDF).

From: Benjamin Nutting [mailto:benja...@nutting.info]
Sent: Thursday, June 16, 2011 8:21 PM
To: itext-questions@lists.sourceforge.net
Subject: [iText-questions] iText Open PDF and apply annotations from XML

Hey everyone,

I am very stuck on this problem. Have been working on it for a few days. I have 
a PDF and what looks like a standard Adobe XMP annotations XML file. I want to 
open the PDF with iText and put the annotations onto the pdf, and save it to 
the file system. The annotations are what I call overlays. Say there is a price 
for a product, one of our AP reps puts an annotation over the price with the 
correct price. When they save it in the tool it saves the regular PDF and the 
annotations XML file.

Below are my two examples. Any and all help is much appreciated! Thanks in 
advance
--Ben


Try #1:
PdfReader reader = new PdfReader("D:\\Temp\\Ann\\
00005CCB.pdf");
PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream("D:\\Temp\\Ann\\ben.pdf"));

File ssaFile = new File("D:\\Temp\\Ann\\00005CCB.xml");
FileInputStream ssaFIN = new FileInputStream(ssaFile);
byte ssaFileContent[] = new byte[(int)ssaFile.length()];
ssaFIN.read(ssaFileContent);

stamper.setXmpMetadata(ssaFileContent);
stamper.close();



Try #2:
Document document = new Document();

File pdfFile = new File("D:\\Temp\\Ann\\00005CCB.pdf");
File ssaFile = new File("D:\\Temp\\Ann\\00005CCB.ssa");
String outputFilename = "D:\\Temp\\Ann\\ben.pdf";
PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream(outputFilename));
document.open();
PdfContentByte cb = writer.getDirectContent();

PdfReader reader = new PdfReader("D:\\Temp\\Ann\\00005CCB.pdf");
int n = reader.getNumberOfPages();
PdfImportedPage page = null;
for (int i = 1; i <= n; i++) {
       document.newPage();
       page = writer.getImportedPage(reader, i);
       cb.addTemplate(page, 0, 0);
}

FileInputStream ssaFIN = new FileInputStream(ssaFile);
byte ssaFileContent[] = new byte[(int)ssaFile.length()];
ssaFIN.read(ssaFileContent);

writer.setXmpMetadata(ssaFileContent);

document.close();
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to