Page 1 of 1

nbsp not working

PostPosted: Fri May 27, 2016 3:40 pm
by Ridhdhi
I am trying to convert docx to pdf where docx includes html strings.
i am facing problem with some basic html tag &nbsp; <br> i got exception in both the case and pdf creating is not working after this.
please help me with this as soon as possible. :?:

Re: nbsp not working

PostPosted: Fri May 27, 2016 9:50 pm
by jason
Which version of docx4j? Is the PDF being created via XSL FO, or Plutext's converter?

Is your HTML in an altChunk?

I recommend you use docx4j-XHTMLImport to convert the XHTML to real docx content, then generate the PDF.

Re: nbsp not working

PostPosted: Mon May 30, 2016 2:28 pm
by Ridhdhi
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>&nbsp;<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.

Re: nbsp not working

PostPosted: Fri Jun 03, 2016 10:10 am
by jason