by Ridhdhi » Mon May 30, 2016 2:28 pm
I am using docx4j 3.2.1 and docx4j-importXHTML 3.2.1.
I am using chunk for the conversion from html to docx4j.
here is my code snipet :
String docx_path = "C:\\Users\\Riddhi\\Desktop\\Downloads\\header.docx";
String pdf_path = "C:\\Users\\Riddhi\\Desktop\\Downloads\\header.pdf";
InputStream is = new FileInputStream(new File(docx_path));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
AlternativeFormatInputPart afiPart = null;
afiPart = new AlternativeFormatInputPart(new PartName("/hw.html"));
String html = "<html><head></head><body><p style='page-break-after: always;'></p> <p style='width: 100%; text-align: center;'><b>NBSP TEST</b></p></body></html>";
afiPart.setBinaryData(html.getBytes("UTF-8"));
afiPart.setContentType(new ContentType("text/html"));
mdp.addAltChunk(AltChunkType.Xhtml, html.getBytes());
Relationship altChunkRelE788 = null;
altChunkRelE788 = mdp.addTargetPart(afiPart);
CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
ac.setId(altChunkRelE788.getId());
OutputStream os = new FileOutputStream(pdf_path);
WordprocessingMLPackage pkgOut = mdp.convertAltChunks();
pkgOut.save(os);
OutputStream os1 = new java.io.FileOutputStream(pdf_path);
Docx4J.toPDF(pkgOut, os1);
Please reply as soon as possible.