Spyridon Xanthopoulos
Spyridon Xanthopoulos

Reputation: 33

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');
pdf.name = "tranformed-" + pdf.name;
pdf.save();

document.name = "new-" + document.name + ".pdf";
document.mimetype = "application/pdf";
document.content = pdf.content;
document.save();

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

Upvotes: 2

Views: 1031

Answers (2)

Spyridon Xanthopoulos
Spyridon Xanthopoulos

Reputation: 33

Thanks for your support.

The problem was assigning the pdf content.

The following code seems to work only with plain text content:

document.content = pdf.content;

Paradoxically, the following is needed when assigning pdf content to a document.

document.properties.content.write(pdf.properties.content);

Thanks.

Upvotes: 0

Sanjay
Sanjay

Reputation: 2503

This Code create new pdf from docx and created pdf stored as version 1.0

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

var pdf = document.transformDocument('application/pdf');
pdf.name = "tranformed-" + pdf.name;
pdf.save();

Upvotes: 1

Related Questions