saveToBase64() corrupting pptx images on node
Tagged: pptx openXml nodejs saveTobase64
June 2, 2016 at 8:08 am #3429
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 .June 13, 2016 at 4:07 pm #3469
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?
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.June 14, 2016 at 10:24 am #3482
Thanks Eric for your reply.
I have solved the issue by commenting the “compression: “deflate” line in saveToBase64 function inside openxml.js.
AmitaJune 15, 2016 at 4:50 am #3486
Cheers, EricJune 15, 2016 at 7:19 am #3488
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.
AmitaJune 17, 2016 at 7:24 am #3497
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.
AmitaJune 17, 2016 at 8:38 am #3498
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, EricJune 17, 2016 at 8:39 am #3499
-EricJune 17, 2016 at 8:43 am #3500
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 ?
June 17, 2016 at 8:53 am #3502
- This reply was modified 9 months, 1 week ago by amita-trantor.
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.
You must be logged in to reply to this topic.