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?
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.
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:
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.