cancel
Showing results for 
Search instead for 
Did you mean: 

Updating pdf from javascript

stebans
Champ in-the-making
Champ in-the-making
Hi,

I would like to add some info onto pdf files, updating their metadata and adding a cover page for example. I'm using the iText library (http://www.lowagie.com/iText/). As far as I know, IText expects accessing the file, or an InputStream, or a byte[]. I thought this could be easily solved, but I'm not able to access the pdf file. So what are the solutions for loading pdf file from JS scripts as "document.content" is only good for text content?  Therefore, the only way I see is using document.url. Unfortunately, accessing the content needs authentication, and without authentication, only the login page is returned.

Could anybody suggest a way to authenticate from within JS Script for accessing content, with simple authentication or maybe using session ticket (I need a way to save content back to document, but that's another question!) -or another way to do it?

Another side question about javascript is how to load a config file (eg an xml file present in alfresco/extension/myFile.xml). Is it possible to use the "classpath:" value (no success as of now)?

Thanks for any help,
best regards,
Stéphane
9 REPLIES 9

stebans
Champ in-the-making
Champ in-the-making
Hi,

I'm partially replying to myself.
To get the pdf file from within the JS script, I need to use the ticket:
tck = session.getTicket();
var url = "http://localhost:8080/alfresco/" + document.downloadUrl + "?ticket=" + tck;
this time, the document is accessible.

stebans
Champ in-the-making
Champ in-the-making
Hi,

I haven't found any way to update binary content through javascript API. I can access it, process it, but not write it back. There seems to be a
node.properties.content.write(content);
in Alfresco-2.1E for dealing with binary content, but will it be part of 2.9CE? if not, what solution could I chose from JS scripts to deal with binary or streams?

Thanks!
Regards
Stéphane

pmonks
Star Contributor
Star Contributor
I believe this is a limitation of Javascript (or perhaps Rhino, the Javascript interpreter Alfresco uses) - it has poor support for binary data.  Even if there is some support, you'll be able to process binary data far more effectively in Java.

Cheers,
Peter

sbuckle
Champ in-the-making
Champ in-the-making
You should be able to update it. I have done something similar before.

Try something like this:


var updatedVersion = document.transformDocument("application/pdf", tempFolder);

// Check it out and update content on the working copy - "pdf" is the current version
var workingCopy = pdf.checkout();
workingCopy.properties.content.write(updatedVersion.properties.content);

// Check it back in
workingCopy.checkin("Document updated", true);

Simon

reddy
Champ in-the-making
Champ in-the-making
HI, I am unable to convert .doc or .docx file to pdf using transformDocument method in alfresco javascript,this method is able to convert to pdf only if the input file is plain text.Does any one hav solution for this?

Thanks in Advance,
Reddy

pmonks
Star Contributor
Star Contributor
That likely indicates that OpenOffice isn't installed and/or configured correctly - Alfresco delegates most Microsoft Office format transformations to OpenOffice.  http://wiki.alfresco.com/wiki/Setting_up_OpenOffice_for_Alfresco has more details.

Cheers,
Peter

reddy
Champ in-the-making
Champ in-the-making
Hi peter Thanks for the Reply,I already solved the issue

p3d3r0s0
Champ in-the-making
Champ in-the-making
Is it possible to use this method to add/edit an annotation in a pdf file?
from what i understand this method solves the save and upload the pdf we wanted to change, but how to access something like an annotation?
is this even possible?
Best regards,
Pedro

pmonks
Star Contributor
Star Contributor
The transformation functionality is used purely for literal translation of one MIME type to another MIME type - it isn't intended to change the content in the process.

For that you might want to look at something like rendition services [1] (added in Alfresco 3.3), or the "embedders" forge project [2].

Cheers,
Peter

[1] http://wiki.alfresco.com/wiki/Rendition_Service
[2] http://forge.alfresco.com/projects/embedders/