Question
CapGemini
IN
Last activity: 22 Oct 2024 2:27 EDT
Docx stream to PDF stream Conversion, getting org.docx4j.openpackaging.exceptions.Docx4JException: error
Hi All,
We are trying to convert Docx Byte stream to PDF Byte stream by using below code. But we are getting below error with much details. Could you please help us with your experience.
Input: DocX Base64 Encoded Byte stream (DocStream)
Output: PDF Byte Stream
try{ byte[] DocBytes2 = Base64.getDecoder().decode(DocStream); ByteArrayInputStream instream = new ByteArrayInputStream(DocBytes2); ByteArrayOutputStream pdfstream = new ByteArrayOutputStream();
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(instream); Docx4J.toPDF(wordMLPackage, pdfstream); // Getting error at this step String PDFS = pdfstream.toString(); return PDFS; } catch (Exception e) { String Error = e.toString(); return Error; }