10-11-2016 05:39 AM
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?
10-11-2016 06:39 AM
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.
10-11-2016 05:48 AM
Why not just use rendition service ?
10-11-2016 06:39 AM
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.
10-11-2016 12:13 PM
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?
10-11-2016 05:54 PM
Correct.
10-12-2016 02:53 AM
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
10-12-2016 03:00 AM
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.
10-12-2016 11:37 AM
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.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.