02-07-2017 07:55 AM
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?
03-19-2017 03:53 PM
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.
03-28-2017 07:31 PM
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:
Explore our Alfresco products with the links below. Use labels to filter content by product module.