cancel
Showing results for 
Search instead for 
Did you mean: 

How transformation to PDF is done?

imphilippesimo
Champ on-the-rise
Champ on-the-rise

Hello,

i'm trying to find a suitable way to convert a file (a docx in my case) to a PDF one.

i took as reference this link https://community.alfresco.com/docs/DOC-5359-noderef-cookbook#w_transformingappttopdf

where we have this snippet:

ContentReader pptReader = contentService.getReader(pptNodeRef, ContentModel.PROP_CONTENT);

       ContentWriter pdfWriter = contentService.getWriter(pdfNodeRef, ContentModel.PROP_CONTENT, true);

       ContentTransformer pptToPdfTransformer =

           contentService.getTransformer(MimetypeMap.MIMETYPE_PPT, MimetypeMap.MIMETYPE_PDF);

       pptToPdfTransformer.transform(pptReader, pdfWriter);

I know  that pdfNodeRef has to be a nodeRef with a non null mimetype, implying a non null metadata.

So this means pdfNodeRef should already be existing with a consequent content.

I then wonder if this snippet is about crushing pdfNodeRef or just converting   pptNodeRef?

Help me understand please?

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

The NodeRef "pdfNodeRef" can be any node that is compatible with the cm:content type. It does not matter what mimetype the node has - it only has to exist.

The snippet you have is about taking the contents of pptNodeRef, converting it into PDF and storing that PDF content via pdfNodeRef. So the old content remains unchanged. If pdfNodeRef already has content, it will be replaced with the transformed PDF. If pdfNodeRef has versioning enabled, this should also create a new version so you can always access the previous content of pdfNodeRef and restore it. If versioning is not enabled than that content is "lost" (not technically yet, but effectively).

The rendition service may also be used to convert documents, but only into predefined target formats (including pre-defined transformation options). The way you are converting the file is the more generic approach and perfectly valid.

View answer in original post

7 REPLIES 7

kaynezhang
World-Class Innovator
World-Class Innovator

Why not just use rendition service ?

afaust
Legendary Innovator
Legendary Innovator

The NodeRef "pdfNodeRef" can be any node that is compatible with the cm:content type. It does not matter what mimetype the node has - it only has to exist.

The snippet you have is about taking the contents of pptNodeRef, converting it into PDF and storing that PDF content via pdfNodeRef. So the old content remains unchanged. If pdfNodeRef already has content, it will be replaced with the transformed PDF. If pdfNodeRef has versioning enabled, this should also create a new version so you can always access the previous content of pdfNodeRef and restore it. If versioning is not enabled than that content is "lost" (not technically yet, but effectively).

The rendition service may also be used to convert documents, but only into predefined target formats (including pre-defined transformation options). The way you are converting the file is the more generic approach and perfectly valid.

Thanks for the reply.

If i'm getting well, you mean that even if "pdfNodeRef" has a null content data (fileFolderService.getFileInfo(pdfNodeRef).getContentData() returning null), the snippet is still working?

In other words, is it not required for "pdfNodeRef" to have some content, to get this working?

Correct.

It's weird,  cause i'm not getting it working for me.

Alfresco complains saying that the convertion failed cause "pdfNodeRef" mime type is null

It may be necessary to set the mimetype on the pdfWriter - that is what the transform operation may check. That alone won't save the mimetype on the pdfNodeRef - only the transform operation will save the content and mimetype.

imphilippesimo
Champ on-the-rise
Champ on-the-rise

Axel Faust

You were right!

we just have to set the writer mimeType.

On the other hand, i have another issue, is about getting available content transformer from the content service for a source mimetype to a target one.

For example, i am not able to get a transformer for plain/text to application/pdf.nevertheless from this link: Content Transformers (and Renditions) | Alfresco Documentation, the transformation i want to perform is listed. So i guess it's because i am not implementing the transformation with suitable third party software (libre office in my case) which provides such content transformer.

am i right? if yes, Can someone give me an advice about which softwares can i use depending of the available possibilities of transformation.