2

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Do you have a converter active for DOCX to PDF, eg JODConverter of the paid-for transformation service add-in? – Gagravarr Feb 07 '17 at 16:53
  • @Gagravarr am I wrong or there must be also an open office server or instance running ? – Leonardo Feb 07 '17 at 22:01
  • Yes, you must have LibreOffice running, but if you installed with the binary installer, the Alfresco startup script should launch LibreOffice for you. Do a ps -ef|grep soffice to see if it is running. – Jeff Potts Feb 13 '17 at 17:01

2 Answers2

1

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();
Sanjay
  • 2,481
  • 1
  • 13
  • 28
0

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.