Xml to base64 pdf

I have an xml invoice. At the bottom of this xml, I want to add the base64 (pdf). How can I do this ?

So you want convert a PDF to a base64 string and add it to an element inside your XML file?
You may run into memory issues trying to read a PDF, convert it to base64 and then add it to an arbitrary XML file.

May I ask why you need to do that? Is it because you want to display the PDF as part of your document?

I have an xml and I want to add the pdf code inside my xml file. My customer asked for it because he needs to import my invoice in his erp. He already gets these kind of invoices from another supplier. Here is part of a sample he sent me


A script like this should work. You may have to adjust according to your own requirements:

var pdfName = "C:/myTests/PDFTest.pdf";
var xmlName = Watch.GetJobFileName();

// Open PDF as binary stream
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 1;       // 1=Binary, 2=Text

// Open XML as XML Document Object
var xmlDoc = new ActiveXObject("MSXML.DOMDocument");
// Create empty PDFBinary element and set its type to base64
var elem = xmlDoc.createElement("PDFBinary");
elem.dataType = "bin.base64";

// Read binary stream and store it in element. The binary stream gets
// converted automatically to base64 because of the element's data type
elem.nodeTypedValue = stream.Read();
// append new element as last child of XML's root element, then save the file