Discussion

2
Replies
327
Views
ponnl Member since 2018 2 posts
PEGA
Posted: 5 months ago
Last activity: 2 months 2 weeks ago

Convert Docx (Word document) to PDF in 8.1 and above

Hi All,

in 8.4 we have a new Case step to Generate Documents based on a word template. If you want to convert that word document to PDF we have to add the following Jars in to the platform 

Docx4j jar was updated in 8.X from 3.3.0 to 6.1.1 because of this Docx4J.toPDF will not work the way it used to work in previous version. To make it work we need to add following jars.

Add this dependency https://mvnrepository.com/artifact/org.docx4j/docx4j-export-fo/8.1.6 docx4j-export-fo in to platform along with its transitive dependencies. 

Transitive dependencies required for docx4j-export-fo:

antlr-2.7.7.jar
antlr-runtime-3.5.2.jar
avalon-framework-api-4.3.1.jar
avalon-framework-impl-4.3.1.jar
batik-anim-1.10.jar
batik-awt-util-1.10.jar
 batik-bridge-1.10.jar
batik-constants-1.10.jar
batik-css-1.10.jar
batik-dom-1.10.jar
 batik-ext-1.10.jar
 batik-extension-1.10.jar
 batik-gvt-1.10.jar
 batik-i18n-1.10.jar
 batik-parser-1.10.jar
 batik-script-1.10.jar
 batik-svg-dom-1.10.jar
 batik-svggen-1.10.jar
 batik-transcoder-1.10.jar
 batik-util-1.10.jar
 batik-xml-1.10.jar
 checker-qual-2.8.1.jar
commons-codec-1.12.jar
 commons-compress-1.18.jar
 commons-io-2.6.jar
commons-lang3-3.9.jar
 docx4j-core-8.1.6.jar
docx4j-export-fo-8.1.6.jar
 docx4j-openxml-objects-8.1.6.jar
docx4j-openxml-objects-pml-8.1.6.jar
 docx4j-openxml-objects-sml-8.1.6.jar
 error_prone_annotations-2.3.3.jar
 fontbox-2.0.7.jar
fop-2.3.jar
httpclient-4.5.8.jar
 httpcore-4.4.11.jar
jackson-annotations-2.9.0.jar
 jackson-core-2.9.9.jar
 jackson-databind-2.9.9.jar
jakarta.activation-api-1.2.1.jar
 jakarta.xml.bind-api-2.3.2.jar
 jaxb-svg11-1.0.2.jar
 jcl-over-slf4j-1.7.26.jar
libs.txt
 mbassador-1.3.2.jar
 slf4j-api-1.7.26.jar
stringtemplate-3.2.1.jar
 wmf2svg-0.9.8.jar
xalan-interpretive-8.0.0.jar
xalan-metainf-8.0.0.jar
 xalan-serializer-8.0.0.jar
 xmlgraphics-commons-2.3.jar

Sample code to convert an inputstream of docx to a pdf

InputStream is = new FileInputStream("sample.docx");
WordprocessingMLPackage pack = WordprocessingMLPackage.load(is);
pack.getMainDocumentPart().addParagraphOfText("Sample text");
OutputStream os = new FileOutputStream("tes.pdf");
Docx4J.toPDF(pack, os);

           

***Edited by Moderator Marissa to add the Developer Knowledge Share tag***

Pega Platform 8.4 Case Management Developer Knowledge Share
Share this page LinkedIn