AnsweredAssumed Answered

Conversion from docx to pdf using java

Question asked by sanjaybandhniya on Feb 2, 2019
Latest reply on Feb 14, 2019 by skushnerenko

I am trying to convert docx file to pdf using java.

I have tried following code.

 

String fileName=new Date().getTime()+".pdf";
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_NAME, fileName);

ContentService contentService = serviceRegistry.getContentService();
NodeRef pdfNodeRef = this.nodeService.createNode(nodeService.getPrimaryParent(nodeRef).getParentRef(), ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName), ContentModel.TYPE_CONTENT, props)
.getChildRef();

ContentReader pptReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
ContentWriter pdfWriter = contentService.getWriter(pdfNodeRef, ContentModel.PROP_CONTENT, true);
pdfWriter.setMimetype(MimetypeMap.MIMETYPE_PDF);
contentService.transform(pptReader, pdfWriter);

It is giving me error like this.

 

 No transformation exists between mimetypes application/vnd.openxmlformats-officedocument.wordprocessingml.document and application/pdf.

 

Am I missing something here?

Is there any other to convert docx to pdf?

Outcomes