0

I have a PDF file and I want to attach / merge / embed an XML file what containt the same datas like PDF but readable for computers. Is there any way in PHP to do this?

I don't have any code or idea how to start this.

Thanks!

netdjw
  • 5,419
  • 21
  • 88
  • 162
  • You would also need to design a client that knows how to extract the attached xml. – Anthony Aug 14 '14 at 10:29
  • 3
    @Anthony Its pretty clear, that you have no clue about this topic and have not read my answer. **What has this question to do with a client?** I've already described a reader/writer in my answer. You are implicitly adding something, which was never asked and is not the problem. So why did you close this? And all the others: this is lemming like close clicking. Open your eyes. – Jens A. Koch Aug 14 '14 at 13:45
  • 2
    why is my question off-topic? This is a programmer q-a forum... isn't it? Where I need to ask my question if not here when I don't have idea how to start? by the way... here on the stackoverflow isn't answer to my question. And to the end: this is not a server-client problem. This is a programming problem. – netdjw Aug 14 '14 at 15:52
  • @jens - if the OP adds an attachment and sends it to 100 people and none of them have a client that can detach the data, then whether a client exists is pretty important. Kind if like not making an HTML page with extra elements no browser supports. And I wrote one sentence as a comment, maybe you need to chill out. – Anthony Aug 14 '14 at 19:01
  • 1
    @Anthony: but I want not to extract the attached xml. I want to attach a xml. – netdjw Aug 15 '14 at 08:05
  • And what will happen later with the attached data? – Anthony Aug 15 '14 at 09:06
  • @Anthony: other softwares read and parse it, that is not my business. I just looking for a simple and clear way to transfer my offers, orders, invocies, etc datas what can read softwares and humans too. The PDF is a simple and clear way to read for humans. XML is a good solution for sowftwares. And now I want to combine both solutions. – netdjw Aug 17 '14 at 17:55
  • I don't think this is off topic. I think the question just needs edited. My customer is asking me to embed XML in a pdf invoice so they can write software to pull the information straight into a system - isn't that what this question is about? – Enigma Plus Apr 01 '19 at 13:58

1 Answers1

1

One solution would be to store the XML inside a XMP block in the PDF. XMP is a metadata extension. It allows to define own Schemas. Basically it's RDF/XML.

SPEC: http://partners.adobe.com/public/developer/en/xmp/sdk/XMPspecification.pdf

I have not seen a XMP writer for PDF in PHP, yet. But it can't be that hard to implement it. When looking at the reader, it's basically RDF content wrapped inside a <x:xmpmeta block.

Some pointers:


Another solution would be to use PDF "attachments".

You could work with the PHP lib FPDF. Here is an example to add an attachment:

Community
  • 1
  • 1
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141