Page 1 of 1

how to convert docx to pdf?

PostPosted: Thu Sep 04, 2014 9:16 pm
by sp2801
Hi,

I am using this api to generate PDF from a word document. When my word document contains bold bullet point I am getting # in the output. Also, the indentation changes in the PDF. Just want to know what is this normal or I am committing some sort of mistake.

Shashank

Re: how to convert docx to pdf?

PostPosted: Thu Sep 04, 2014 11:37 pm
by jason
What version of docx4j?

If not 3.2.0, please try that.

If 3.2.0, you can attach your docx and I will take a look.

Re: how to convert docx to pdf?

PostPosted: Fri Sep 05, 2014 8:30 pm
by sp2801
Thanks for your reply Jason. I will test this and let you know. I have attached the word document for the reference. I was using earlier version. Below is the code which I am using
Ones in Red are showing as Deprecated. Seems this can be the issue.

public void generatePDF(WordprocessingMLPackage wordMLPackage, String fileName,String objectName,String baseLocation) throws Exception
{
inputfilepath = baseLocation + "Report/"+objectName+"/"+fileName;
wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath+".docx"));
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
((org.docx4j.convert.out.pdf.viaXSLFO.Conversion)c).setSaveFO(new java.io.File(inputfilepath+".fo"));
((org.docx4j.convert.out.pdf.viaXSLFO.Conversion)c).setSaveFO(new java.io.File(inputfilepath + ".fo"));
OutputStream os = new java.io.FileOutputStream(inputfilepath.substring(0,inputfilepath.length()-2) + ".pdf");
c.output(os, new PdfSettings());
System.out.println("Saved " + inputfilepath + ".pdf");
}

Shashank

Re: how to convert docx to pdf?

PostPosted: Sat Sep 06, 2014 2:42 pm
by jason
Tested your docx with 3.2.0; looks ok to me.

The updated ConvertOutPDF sample uses Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL)
but the older deprecated interface should still be fine.

Re: how to convert docx to pdf?

PostPosted: Fri Sep 26, 2014 9:35 pm
by sp2801
HI Jaosn,

I am getting
java.lang.IllegalAccessError: tried to access field org.docx4j.openpackaging.Base.partName from class com.plutext.merge.PartUtils
com.plutext.merge.PartUtils.setPartName(PartUtils.java:45)
com.plutext.merge.CopyGeneric.cloneJaxbXmlPart(CopyGeneric.java:248)
com.plutext.merge.FontHandler.init(FontHandler.java:54)
com.plutext.merge.DocumentBuilder.copyReferences(DocumentBuilder.java:1138)
com.plutext.merge.DocumentBuilder.appendDocument(DocumentBuilder.java:792)
com.plutext.merge.DocumentBuilder.buildDocument(DocumentBuilder.java:433)
com.plutext.merge.DocumentBuilder.buildOpenDocument(DocumentBuilder.java:244)
error at below line. I am using docx4j3.2 version JAR file.

WordprocessingMLPackage output = documentBuilder.buildOpenDocument(<List Variable>);

Shashank

Re: how to convert docx to pdf?

PostPosted: Fri Sep 26, 2014 11:29 pm
by jason
Hi Shashank,

That public setter was added 19 August:

https://github.com/plutext/docx4j/commi ... c86a1fb131

and is in docx4j 3.2.0, so could you please double check you don't have an old docx4j jar on your classpath?

Since this involves com.plutext.merge.DocumentBuilder, if you continue to have problems, please contact support@plutext.com

Re: how to convert docx to pdf?

PostPosted: Tue Jan 13, 2015 9:08 pm
by sp2801
Hi Jason,

I have added 3.2 version of docx4j JAR file and also I have updated the docx4j property file however I am getting the below error

java.lang.IllegalAccessError: tried to access field org.docx4j.openpackaging.Base.partName from class com.plutext.merge.PartUtils
com.plutext.merge.PartUtils.setPartName(PartUtils.java:45)
com.plutext.merge.CopyGeneric.cloneJaxbXmlPart(CopyGeneric.java:248)
com.plutext.merge.FontHandler.init(FontHandler.java:54)
com.plutext.merge.DocumentBuilder.copyReferences(DocumentBuilder.java:1138)
com.plutext.merge.DocumentBuilder.appendDocument(DocumentBuilder.java:792)
com.plutext.merge.DocumentBuilder.buildDocument(DocumentBuilder.java:433)
com.plutext.merge.DocumentBuilder.buildOpenDocument(DocumentBuilder.java:244)
com.jdsu.pqm.customUtil.WordFileGenerator.mergeLabel(WordFileGenerator.java:1603)
com.jdsu.pqm.customUtil.WordFileGenerator.generateWord(WordFileGenerator.java:448)
com.jdsu.pqm.comp.JDSUPDFReportGenerator.loadAttributesAndGeneratePDF(JDSUPDFReportGenerator.java:394)
com.jdsu.pqm.comp.JDSUPDFReportGenerator.generatePDFReport(JDSUPDFReportGenerator.java:136)
com.jdsu.pqm.servlet.PDFReportServlet.processRequest(PDFReportServlet.java:59)
com.jdsu.pqm.servlet.PDFReportServlet.doGet(PDFReportServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Can you please share some thoughts on this. Thanks for your help.

Shashank

Re: how to convert docx to pdf?

PostPosted: Thu Jan 15, 2015 10:53 am
by jason
Did you remove the old docx4j jar from your class path?

Please:-

jason wrote:Since this involves com.plutext.merge.DocumentBuilder, if you continue to have problems, please contact support@plutext.com