Conversion from docx to pdf using java

Showing results for 
Search instead for 
Did you mean: 

Conversion from docx to pdf using java

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)

ContentReader pptReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
ContentWriter pdfWriter = contentService.getWriter(pdfNodeRef, ContentModel.PROP_CONTENT, true);
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?

4 Replies
Active Member II

Re: Conversion from docx to pdf using java

You can use libreoffice api bootstrap by yourself

There is also docx4j, but as libreoffice should already be installed on your alfresco instance, it is more prefferable.

Active Member II

Re: Conversion from docx to pdf using java

Hi Sanjay Bandhniya‌,

The best option to transform docx files to pdf files is deploying your own Microsoft Transformation Server and integrating it with your Alfresco.

Basically, you will be able to transform docx file to pdf with libreoffice, but files with tables, lists... won’t be exactly similar in the result pdf file because you need libraries from Microsoft.


Active Member II

Re: Conversion from docx to pdf using java

Nevertheless, Alfresco uses the libreoffice to convert docx to pdf, doesn't it?

As far as I understand, as Microsoft Transformation Server you mean instance of installed Microsoft Office, used for convertion.

According to this description Techno: A high quality transformation server based on Microsoft Office ⋆ Contezza 

I suppose it's a good idea to combine libreoffice as fast convertion tool and Microsoft Office as a tool for pure pdf.

We use both docx4j and libreoffice for the conversion,

I should say, quality of free docx4j conversion is close to that of libreoffice.

But  docx4j has a commercial option with declared pure docx to pdf conversion. I suppose using docx4j for pure pdf would be more natural for Alfresco, than Microsoft Office instance.

Besides docx4j is platform independent.

Active Member

Re: Conversion from docx to pdf using java

Have you got running transform-core-aio? If you dont connect some transform core (like on local dev where thumbnails don't work too) then no transform is possible.