saveToBase64() corrupting pptx images on node

Home Forums Open-Xml-Sdk-JavaScript saveToBase64() corrupting pptx images on node

This topic contains 9 replies, has 2 voices, and was last updated by  Eric White 7 years, 9 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #3429

    amita-trantor
    Participant

    Hi,

    I am using openXmlSdkJs Version: 1.01.01.

    I am trying to simply open a pptx with some images as OpenXml instance and save it back as such through node .

    below is the sample code:

      var openTestPpt = fs.readFileSync("Testpresentation.pptx").toString('base64');
      var openAsXmlInstance = new openXml.OpenXmlPackage(openTestPpt);
      var saveInstance = openAsXmlInstance.saveToBase64();
      var buffer = new Buffer(saveInstance, "base64");
      fs.writeFileSync("newppt.pptx", buffer);

    When I see the saved pptx, I find some image dispalying and some missing.

    When I try the code through browser which use saveToBlob() to save a openXml instance, it work fine and all the images get render perfectly.

    Is there some problem with saveToBase64() when working on node .

    #3469

    Eric White
    Keymaster

    Hi,

    I am not sure about the issues with saving to Base 64 when working on node.

    What I would do in this situation is to do this operation using the browser, save to a file, then do this operation using node, save to a file, and then unzip both files, and look at the binary parts, and see if I could determine a pattern to the differences. Is there an issue associated with some binary parts being partially written but not fully written?

    Following that experiment, I would go into the Open-Xml-Sdk-JavaScript code, find the place where it is writing the binary parts, and examine the data in memory, see if I had the right data.

    I would also probably write a super-small example program that experiments with the appropriate low-level APIs and see if I could get node to behave / misbehave in the same way as you observe when using the Open-Xml-Sdk-JavaScript.

    Unfortunately, my current schedule / commitments prohibit me from doing this work. But that is the good thing about open source – you have the source code.

    Wish I had a better answer for you, but unfortunately, I don’t.

    #3482

    amita-trantor
    Participant

    Thanks Eric for your reply.

    I have solved the issue by commenting the “compression: “deflate” line in saveToBase64 function inside openxml.js.

    Thanks
    Amita

    #3486

    Eric White
    Keymaster

    Thanks, Amita.

    I will make a note of this, and when possible will update the Open-Xml-Sdk-JavaScript

    Cheers, Eric

    #3488

    amita-trantor
    Participant

    Hi Eric,

    I am facing one more issue with openxml sdk, when trying to parse larger file e.g (i am parsing 73MB pptx file) then I am getting out of memory issue with nodejs.

    Issue is coming at this line of code
    var sourceDocument = new openXml.OpenXmlPackage(document);

    Your help would be appreciated.

    Thanks
    Amita

    #3497

    amita-trantor
    Participant

    Hi Eric,

    I have debugged the code of openxml for out of memory issue and found there is issue with jszip. jszip issue.

    Can you please look into it or use some other library with instead of jszip ?

    Your help would be appreciated.

    Thanks
    Amita

    #3498

    Eric White
    Keymaster

    Hi Amita,

    I was afraid of this situation.

    The problem with replacing jszip is that this would be a pretty major project.

    There is a newer version of jszip, I believe. It would be interesting to try this out.

    My issue is that I have too much work right now. I would need to try this out, test in depth.

    I will check with the folks at Microsoft, see if anything can be done.

    Thanks, Eric

    #3499

    Eric White
    Keymaster

    Hi Amita,

    I think that it may be possible to increate the amount of memory for the JavaScript VM in node. Have you tried this?

    -Eric

    #3500

    amita-trantor
    Participant

    Yes, Eric.

    I have tried by increasing memory it is still giving ot of memory issue. My file is of 73 MB and getting out of memory issue.

    Can you suggest a way to resolve this error ?

    Thanks
    Amita

    • This reply was modified 7 years, 9 months ago by  amita-trantor.
    #3502

    Eric White
    Keymaster

    Hi Amita,

    I would guess that the issue is loading the images that are stored in the document – that the XML is not too big.

    If I were to have time to take this on as a project, the first thing I would look at is attempting to never load images, until such time as it is necessary to save the file. Further, I would examine the code carefully to make sure that the references to the image data are freed immediately after loading from the original, and saving to the new file. It seems necessary to reduce the memory footprint that JsZip uses.

    Thanks, Eric

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.