msd 5 Posted May 24, 2022 Hello, We need to create an XML document file for an online document exchange system, and that XML file must include attachments. I can show you how it appears, but I'm not sure how to add/encode documents into a string that will be used to represent documents in an XML file (like attachment). In other words, how to encode a file into a string that may be used to represent it in an XML structure. Thank you very much... Share this post Link to post
Alexander Sviridenkov 356 Posted May 24, 2022 Use Base64 encoding (SOAP.EncdDcd unit) Share this post Link to post
FPiette 383 Posted May 24, 2022 Are you writing both ends of the document exchange system? If you must access an existing system, then you must get the specification of the attachment. 2 Share this post Link to post
msd 5 Posted May 24, 2022 Hello, This is an example from an existing document... <cbc:EmbeddedDocumentBinaryObject mimeCode="application/pdf" filename="document_name.pdf">JVBERi0xLjcNCiW.....EmbeddedDocumentBinaryObject> This is a universal app, so there is no specific need for some encoding or decoding, just a simple representation of the binary representation of the document... Share this post Link to post
FPiette 383 Posted May 24, 2022 You have not answered the question I asked: Are you writing both ends of the document exchange system? Quote mimeCode="application/pdf" Look at: https://www.rfc-editor.org/rfc/rfc3778.txt Share this post Link to post
msd 5 Posted May 24, 2022 I wrote that this is a universal doc exchange web app. I'm from the client side. I need to push XML to the web app in XML format with an embedded PDF document. Share this post Link to post
FPiette 383 Posted May 24, 2022 I'm probably stupid, but you still don't clearly tell if you write the server side. If you write the server side and the client side, you can define things like you prefer. For example encoding the PDF file as a base64 stream which is just text and put it in the XML document. If you don't write the server side, then contact the author of the server to get the requirements he selected. Share this post Link to post
msd 5 Posted May 24, 2022 Because I only work on the client side, I have no experience with server-side encoding. I'm aware that the documentation specifies that nodes with attachments must be document/pdf in binary format. My initial question was about how to convert PDF files to binary and then put it into XML. I'll try Base64 Encoding first, and if it works, I'll put a bit of code here for the other members to see. Thank you for your suggestions... 1 Share this post Link to post
Tommi Prami 130 Posted May 25, 2022 5 hours ago, msd said: I'm aware that the documentation specifies that nodes with attachments must be document/pdf in binary format. I am pretty sure it can't be (RAW) binary (will most certainly contain characters that are illegal in XML file) . Most likely Base64 encoded. But should check from Server side developers/docs Share this post Link to post
FPiette 383 Posted May 25, 2022 I'm aware that the documentation specifies that nodes with attachments must be document/pdf in binary format. Would you reproduce that part of the documentation here? I ask because what you tell is largely incomplete and confusing. If you show us a complete XML document with a PDF file attached, that could help. Someone could be able to recognize the encoding format. Maybe me. 1 Share this post Link to post
msd 5 Posted May 26, 2022 This is a link: https://base64.guru/converter/encode/pdf where you can find how to encode PDF and the correct way to add it to XML. This link was given to us by the developer, and when we use this online tool and generate an XML tag, everything works fine:-) It looks like a simple Base64 encode from Delphi is OK, so if you can give me a sample (only encode/decode part of code). Share this post Link to post
msd 5 Posted May 26, 2022 I was made function that works the job 🙂 if someone need it... function EncodePDF(const AFileName: string): string; var inStream: TStream; outStream: TStringStream; begin inStream := TFileStream.Create(AFileName, fmOpenRead); try outStream := TStringStream.Create; try TNetEncoding.Base64.Encode(inStream, outStream); finally Result := outStream.DataString; outStream.Free; end; finally inStream.Free; end; end; if someone has better idea, please post it here 😉 Share this post Link to post
David Heffernan 2345 Posted May 26, 2022 The try/finally coding in the above is incorrect. It should be: function EncodePDF(const AFileName: string): string; var inStream: TStream; outStream: TStringStream; begin inStream := TFileStream.Create(AFileName, fmOpenRead); try outStream := TStringStream.Create; try TNetEncoding.Base64.Encode(inStream, outStream); Result := outStream.DataString; finally outStream.Free; end; finally inStream.Free; end; end; 1 Share this post Link to post