2

I have the Data.xml file and a pdf file filled with informations. I'm trying to embed the data.xml file in the XMP metadata stream of the PDF because this data should be hidden.

I used iText to create the pdf and to add the usual metadata such as author etc. But I'm not able to understand how to add the xml as metadata in the xmp stream. Is there a function in the iText or xmlworker library that allows me to do this? I've tried but I can't fin the way to do this.

(I have no code to post because all code written to create the pdf and so on works perfectly, just dunno how to proceed to do what I described before. Is there something in the iText library that provides it, or i should use other tools?)

Igr
  • 965
  • 4
  • 13
  • 26
  • Maybe you can convert xml to string and add it as element of XmpArray. http://itextpdf.com/examples/iia.php?id=217 – user1516873 Jun 10 '13 at 12:00
  • @user1516873 you mean to convert all the xml content into a big String, put it into the array and than extract the string when needed reconstructing the xml file? Is it a good solution? – Igr Jun 10 '13 at 12:39
  • Yeah, i really mean it. Maybe you can store that big string directly as one of your custom properties, without wrap it in array. I think it is not a best or even good solution, but i don't see other possible ways to do it with iText. – user1516873 Jun 10 '13 at 13:08
  • @user1516873 Ok, this could be one solution. Do you have any idea of a better solution provided by using another library? – Igr Jun 10 '13 at 13:14
  • No, i have no idea. If your xml is very big you can zip it and convert to Base64 before put in XMP, that's all i can suggest. – user1516873 Jun 10 '13 at 13:36
  • 1
    Also: why would you put actual data (not metadata) in an XMP stream? In PDF/A-3, the data is added as a document-level attachment. That makes much more sense than to put it into an XMP stream. – Bruno Lowagie Jun 10 '13 at 13:43
  • @BrunoLowagie Maybe I miunderstood something, but I wanna add some hidden data to the file.. if I just put it as an attachment isn't it visible? Can I set a document_level attachment easly with iText as a better solution? – Igr Jun 10 '13 at 14:56
  • 1
    The document-level attachment won't be visible on any page, but people will be able to select it in the attachment panel, just like they'll be able to see the contents of the XMP (and yes, it's easy to add a document-level attachment with iText). There are of course many other ways to add data to a PDF that isn't visible. For instance Adobe Illustrator adds proprietary artifacts as a /PieceInfo entry in the root dictionary of the PDF. That's also possible with iText. There are many solutions I can think of; all are better than abusing the XMP stream. – Bruno Lowagie Jun 10 '13 at 15:27
  • I misunderstood the meaning of the XMP stream. Thank you, I'll surely use better the document level attachment – Igr Jun 10 '13 at 15:47

1 Answers1

2

"In PDF/A-3, the data is added as a document-level attachment. That makes much more sense than to put it into an XMP stream.

The document-level attachment won't be visible on any page, but people will be able to select it in the attachment panel, just like they'll be able to see the contents of the XMP (it's easy to add a document-level attachment with iText). There are of course many other ways to add data to a PDF that isn't visible. For instance Adobe Illustrator adds proprietary artifacts as a /PieceInfo entry in the root dictionary of the PDF. That's also possible with iText. There are many solutions, all are better than abusing the XMP stream"

Attaching at the document level solved the problem.

Igr
  • 965
  • 4
  • 13
  • 26
  • If you finally developed a code using iText to embed a XML file in a PDF file it would be great if you share it here! – Felipe Apr 21 '21 at 14:12