alfresco - convert docx to pdf and create a new version

cancel
Showing results for 
Search instead for 
Did you mean: 
spyridon_xantho
Member II

alfresco - convert docx to pdf and create a new version

I' m trying to convert a docx document to pdf and store the newly created pdf file as a new version. This is the test code:

var document = search.findNode("workspace://SpacesStore/30f334f3-d357-4ea6-a09f-09eab2da7488"); 

var folder = document.parent 

var pdf = document.transformDocument('application/pdf');


document.name = "new-" + document.name + ".pdf"; d

ocument.mimetype = "application/pdf";

document.content = pdf.content;

document.save();

The document ends up empty. Is this type of conversion possible with javaScript?

2 Replies
douglascrp
Advanced II

Re: alfresco - convert docx to pdf and create a new version

I don't think you will be able to use JavaScript for what you want to achieve.

Check this project's source code. In it you will find lots of samples for content related operations, but using Java.

alfresco-pdf-toolkit/pdf-toolkit-repo/src/main/java/org/alfresco/extension/pdftoolkit/repo/action/ex... 

mehe
Senior Member II

Re: alfresco - convert docx to pdf and create a new version

I think the main problem is that you use the content property. Using the properties.content.write method should work

var pdfNode=document.transformDocument("application/pdf");
var version=document.createVersion("new version pdf",true); //true=create major version
document.properties.content.write(pdfNode.properties.content,true,false);
document.name+=".pdf";
document.save();
pdfNode.remove();
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

1: create the pdf Version of the file

2: we create a new major version (you could also create a minor using false) and automatically add the versioned aspect if needed.

3: copies the content from pdf to new version, applymimetype=true, guessencoding=false 

docs:

write | Alfresco Documentation 

createVersion | Alfresco Documentation