Include a PDF-file in a XML-file

sanojsanoj Member Posts: 19
Hi,

I want to include a pdf-document in a XML-file (base64-coded ?). Is there a way to do that in NAV?

Br,
Jonas

Comments

  • nunomaianunomaia Member Posts: 1,153
    Save PDF convert base64 to BigString and then export has an XMLport.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • sanojsanoj Member Posts: 19
    Thanks for the reply, but how do I do that?

    How do I convert to base64?
    How do I include the base64 data in the xmldocument?

    As a note: I should send this data via MSMQ to a web server.

    Br,

    Jonas
  • nunomaianunomaia Member Posts: 1,153
    In Codeunit EP Format Functions you have a sample to convert to Base64

    Convert Base64 to BigText and export it to XML.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • jlandeenjlandeen Member Posts: 524
    One small note on MSMQ - especially if you are planning on embedding files & PDFs in your XML. There are some size limits to the Messages that you can place in the Queue. It depends on how you're encoding the data (Unicode characters take up double the space) but I think there's a 4 or 8mb limit.

    You should check the documentation of MSMQ in MSDN. I have yet to ever hit this limit when simply sending transactional data between systems through MSMQ, but if you're going to be PDF'ing reports to send...they can get big quickly (depending on how many pages in the report & how complicated the data).
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • sanojsanoj Member Posts: 19
    Thanks both of you for your reply.

    I tried the following code:
    CREATE(xmldoc2); 
    xmldoc2.loadXML('<root/>'); 
    xmlNode2 := xmldoc2.documentElement; 
    CREATE(Picture); 
    xmlNode := Picture.GetPictureAsBase64('C:\file.pdf', 100, 'VALUE'); 
    NewChildNode := xmlNode2.ownerDocument.createNode('element', 'VALUE', ''); 
    
    NewChildNode.text := xmlNode.text; 
    
    xmlNode2.appendChild(NewChildNode); 
    xmldoc2.save('c:\xmlfile.xml'); 
    
    

    Xmlfile.xml contains a VALUE element, but it is empty.

    What am I doing wrong?
  • jlandeenjlandeen Member Posts: 524
    Just taking a quick look at your code and some of my old code here is my suggestions.
    NewNode := XMLDoc2.createElement('VALUE');
    NewValue := XMLDoc2.createTextNode(<data string>);
    NewNode.appendChild(NewValue);
    XMLDoc2.appendChild(NewNode);
    
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • sanojsanoj Member Posts: 19
    I tried you code and replaced <data string> with xmlnode.text returned from Picture.GetPictureAsBase64. But still empty...

    I think the problem has to do with Picture.GetPictureAsBase64...
  • jlandeenjlandeen Member Posts: 524
    Have you tried the code sample with just plain text to make sure that it lays it down correctly in the XML file?

    Have you checked that your GetPictureAsBase64 actually returns a useable text string? Maybe just printing the first few characters to a confirm prompt?

    One other thing to check with some of these string/streams/file IO operations is to move the pointer back to the beginning of the data (I think thats more for File IO & in .Net...but maybe something to check)
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • nunomaianunomaia Member Posts: 1,153
    yes, confirm the return value of GetPictureAsBase64
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • sanojsanoj Member Posts: 19
    GetPictureAsBase64.HasErrors is true and when I look into Event Viewer I got an error saying:

    Error during image processing:Parameter is not valid.

    Are you sure GetPictureAsBase64 can handle all types of files, not just images?
Sign In or Register to comment.