Strange things with PDFToolkit

cancel
Showing results for 
Search instead for 
Did you mean: 
pjcaracuel_2349
Active Member II

Strange things with PDFToolkit

Jump to solution

Hi

I am using two scripts to add images to a pdf. One of them works fine but in the other whose code is the same I get the following error:

021-09-02 14:51:54,757 ERROR [extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-4] Exception from executeScript: 08020357 Failed to execute script 'workspace://SpacesStore/e736071d-eda0-44e9-9985-f8bb7c5a1790': nodeRef is a mandatory parameter
org.alfresco.scripts.ScriptException: 08020357 Failed to execute script 'workspace://SpacesStore/e736071d-eda0-44e9-9985-f8bb7c5a1790': nodeRef is a mandatory parameter

Code is:

var userlogged = userhome.properties.name;
var query = "TYPE:\"cm:content\" AND @CM\\:name:"+ userlogged + ".png";
var nodes=search.luceneSearch(query);

var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters.inplace = true;
watermark_action.parameters["watermark-type"] = "image";
watermark_action.parameters["watermark-image"] = eval(nodes[0]);
watermark_action.parameters["watermark-image"] = eval("rubrica_" + userlogged);
watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
watermark_action.parameters["watermark-font"] = "Helvetica";
watermark_action.parameters["watermark-size"] = "12";
watermark_action.parameters.page = "all";
watermark_action.parameters["watermark-depth"] = "over";
watermark_action.parameters.position = "manual";
watermark_action.parameters["location-x"] = step;
watermark_action.parameters["location-y"] ="1";
watermark_action.execute(doc);
logger.system.out("***************************Incluida firma en : " + doc.name );

 

Ok, if I //watermark_action.execute(doc);

The script run ok and the name of the document is shown in log. Therefore doc is a valid node.

If I execute watermark_action.execute(doc);

the error of the beginning is shown in the log

Any idea? 

Thanks in Advanced

 

1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: Strange things with PDFToolkit

Jump to solution

@pjcaracuel_2349 wrote:

Hi.

I am very sorry, I have not posted for a long time and I have forgotten the good practices.
Your code has been very useful to me but the error persists.
It is strange but if I run it in the console, only javascript works correctly however when the script is run it doesn't.

Script code:

addWaterMark.js

var userlogged = userhome.properties.name;
try {
	var pdfDocNode = document;
	ver step = "100!;
	logger.system.out("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.system.out("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.system.out("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.system.out("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	} 
	catch (ex) {
   logger.system.out("Exception occurred: " + ex.message);
}
	

Log Error:

PDFDocNodeRef: workspace://SpacesStore/fa7e24d6-d178-4bea-b814-fdf661f4f9fe | PDFDocName: 5766774840.pdf
LoggedInUser: rcanovas
Executing SearchQuery: TYPE:"cm:content" AND @cm\:name:"rcanovas.png"
Exception occurred: Cannot read property "nodeRef" from undefined

Javascript Console Code:

var userlogged = "rcanovas";
try {
	var pdfDocNode = document;
	var step = "100";
	logger.log("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.log("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.log("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.log("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	}
	catch (ex) {
   logger.logt("Exception occurred: " + ex.message);
}
	

JavaScript Console Log

PDFDocNodeRef: workspace://SpacesStore/a46d1938-4cb5-4da2-963a-1ed91300ea2f | PDFDocName: 5766774840.pdf
LoggedInUser: rcanovas
ImageNodeRef: workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b | ImageName: rcanovas.png
***************************Incluida firma en :  5766774840.pdf 100

using userhome.properties.name to get username logged is ok because it shown in the log.

I feel lost because I don't understand the behavior of the query. It works in the console but not in the script

 


"userhome" gives you the info for current user’s Home Space. "person" root object is the correct way to get anything pertaining to a user, however- can you tell where exactly you are trying to execute the "addWaterMark.js" ? Are you creating a repository webscript (based on naming of the file it can't be used as webscript) ? or rulescript (possible to use the 'addWaterMark.js' file as rule script or can be loaded in jsconsole as well by uploading it to Repository > Data Dictionary > Scripts folder. When you upload it, make sure the content / mime type is set to Mimetype: Java Script, changing it in Edit Properties if needed)?

It should work in jsconsole as well as a script executed either via rules or via jsconsole. If i compare your code (script vs jsconsole) i see some syntactical issues with it. See the one highlighted in red above.

ver step = "100!; --> var step = "100";

Result of the query seems null, could be because no image exist with the out of the 'userlogged ' variable or output itself is null:

var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"';  that is what this error indicates: Exception occurred: Cannot read property "nodeRef" from undefined

I suggest you use var userlogged = person.properties.userName; to get the name of currently logged in user and make sure a ".png" file exists in the repository with name e.g.: "admin.png"

pdfDocNode.save(); --> Not required, you are executing a backend action and not modifying the node in script. Backend action is doing the job.

In jsconsole code you have hardcoded userlogged and step variable is also correct.

var userlogged = "rcanovas";

var step = "100";

Corrected code below addWaterMark.js:

var userlogged = person.properties.userName;
try {
	var pdfDocNode = document;
	var step = "100";
	logger.system.out("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.system.out("LoggedInUser: "+ userlogged);
	
	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
    var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"';
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};
	
	logger.system.out("Executing SearchQuery: " + query);
	
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.system.out("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);
	
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	watermark_action.parameters["watermark-type"] = "image";
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	
} catch(ex) {
	logger.system.out("Exception occurred: " + ex.message);
}

I would suggest debugging your code and check for basic syntactical errors as well instead.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

12 Replies
cristinamr
Advanced

Re: Strange things with PDFToolkit

Jump to solution

Hi!

I think you have missing at least, one parameter. Try adding this line:

watermark_action.parameters["destination-folder"] = document.parent;

BTW, I've found this script (it's working), in case you have other issue, please compare them:

var watermark_action = actions.create("pdf-watermark");

watermark_action.parameters["inplace"] = true;
watermark_action.parameters["destination-folder"] = document.parent;
watermark_action.parameters["watermark-type"] = "text";
watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
// wrong parameter
//watermark_action.parameters["watermark-pages"] = "all";
watermark_action.parameters["page"] = "all";

watermark_action.parameters["watermark-depth"] = "over";

// missing parameters
watermark_action.parameters["watermark-font"] = "Courier";
watermark_action.parameters["watermark-size"] = "10";
// END missing parameters

watermark_action.parameters["position"] = "center";

watermark_action.execute(document);

Link.

Let us know your results.

Cheers,

Cris.

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
abhinavmishra14
Advanced

Re: Strange things with PDFToolkit

Jump to solution

Can you try below code, issue may not with the doc, it may be the image node you are passing and search may be returning empty. Consider checking the query. Document parent is not mandatory  though for inplace operation 

https://github.com/OrderOfTheBee/alfresco-pdf-toolkit/blob/master/pdf-toolkit-repo/src/main/java/org...

var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters["inplace"] = true;
watermark_action.parameters["watermark-type"] = "image"; watermark_action.parameters["watermark-image"] = nodes[0].nodeRef; watermark_action.parameters["watermark-text"] = "Lorem Ipsum"; watermark_action.parameters["watermark-font"] = "Helvetica"; watermark_action.parameters["watermark-size"] = "12"; watermark_action.parameters["page"] = "all"; watermark_action.parameters["watermark-depth"] = "over"; watermark_action.parameters["position"] = "manual"; watermark_action.parameters["location-x"] = step; watermark_action.parameters["location-y"] ="1"; watermark_action.execute(document);

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
pjcaracuel_2349
Active Member II

Re: Strange things with PDFToolkit

Jump to solution

Thanks both,

First, the error is due firma is null. Therefore PDFToolKit is running ok.

This code in JavaScript Console run ok but when run the script which contains this code firma=null I don´t understand!!

var userlogged = "rcanovas";
var firma="";

if (userlogged === "rcanovas") {
firma=search.findNode('workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b');
}
logger.log("***************************Documento a firmar : " + document.name + " " + firma);

Console.PNG

pjcaracuel_2349
Active Member II

Re: Strange things with PDFToolkit

Jump to solution

In summary, the question is

Why this code line run ok in console javascript but not in script?

firma=search.findNode('workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b');

 

TIA!!

abhinavmishra14
Advanced

Re: Strange things with PDFToolkit

Jump to solution

You should share the full code instead of multiple variations. Here are few things to note::

You are using wrong root object to get user, it should be: var userlogged = person.properties.userName;

Your search query has "CM" , it should be "cm" (lowercase), and you should use fts-alfresco instead.

Here is a full example: 

var pdfDocNodeStr = "workspace://SpacesStore/2c4b6829-3992-4990-9f8b-04f3c535dbce"
try {
	var pdfDocNode = search.findNode(pdfDocNodeStr);
	logger.log("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name)
	
	var userlogged = person.properties.userName;
	logger.log("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND =@cm\\:name:"'+ userlogged + '.jpg"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.log("Executing SearchQuery: " + query)
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0]
	logger.log("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"])

	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters["inplace"] = true;
	watermark_action.parameters["watermark-type"] = "image";
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	watermark_action.parameters["watermark-font"] = "Helvetica";
	watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters["page"] = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters["position"] = "manual";
	watermark_action.parameters["location-x"] = "1";
        watermark_action.parameters["location-y"] ="1";

	watermark_action.execute(pdfDocNode);
} catch (ex) {
   logger.log("Exception occurred: " + ex.message);
}

I am not sure what and how you have written your script, its better to share full code to avoid confusion and waste of time when asking questions in the forum.

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
pjcaracuel_2349
Active Member II

Re: Strange things with PDFToolkit

Jump to solution

Hi,

I am so sorry. I have not posted for a long time and I have forgotten the good practices. 

Very good your code will help me to improve but the error still persists.

In the Javascript Console it works perfect but when executing the attached script it fails. Attached log.

 

var userlogged = userhome.properties.name;
try {
	var pdfDocNode = document;
	ver step = "100!;
	logger.system.out("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.system.out("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.system.out("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.system.out("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	} 
	catch (ex) {
   logger.system.out("Exception occurred: " + ex.message);
}
	

Log

PDFDocNodeRef: workspace://SpacesStore/fa7e24d6-d178-4bea-b814-fdf661f4f9fe | PDFDocName: 5766774840.pdf
LoggedInUser: rcanovas
Executing SearchQuery: TYPE:"cm:content" AND @CM\:name:"rcanovas.png"
Exception occurred: Cannot read property "nodeRef" from undefined

 

In JavaScriptConsole

var userlogged = "rcanovas";
try {
	var pdfDocNode = document;
	var step = "100";
	logger.log("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.log("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.log("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.log("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	}
	catch (ex) {
   logger.logt("Exception occurred: " + ex.message);
}

 

Output Console

PDFDocNodeRef: workspace://SpacesStore/a46d1938-4cb5-4da2-963a-1ed91300ea2f | PDFDocName: 5766774840.pdf LoggedInUser: rcanovas ImageNodeRef: workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b | ImageName: rcanovas.png ***************************Incluida firma en : 5766774840.pdf 100

 

Except userlogged var that in Console is "hardcode" the code is equal, but the behavour is diferent.

 

pjcaracuel_2349
Active Member II

Re: Strange things with PDFToolkit

Jump to solution

Hi.

I am very sorry, I have not posted for a long time and I have forgotten the good practices.
Your code has been very useful to me but the error persists.
It is strange but if I run it in the console, only javascript works correctly however when the script is run it doesn't.

Script code:

addWaterMark.js

var userlogged = userhome.properties.name;
try {
	var pdfDocNode = document;
	ver step = "100!;
	logger.system.out("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.system.out("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.system.out("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.system.out("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	} 
	catch (ex) {
   logger.system.out("Exception occurred: " + ex.message);
}
	

Log Error:

PDFDocNodeRef: workspace://SpacesStore/fa7e24d6-d178-4bea-b814-fdf661f4f9fe | PDFDocName: 5766774840.pdf
LoggedInUser: rcanovas
Executing SearchQuery: TYPE:"cm:content" AND @cm\:name:"rcanovas.png"
Exception occurred: Cannot read property "nodeRef" from undefined

Javascript Console Code:

var userlogged = "rcanovas";
try {
	var pdfDocNode = document;
	var step = "100";
	logger.log("PDFDocNodeRef: "+ pdfDocNode.nodeRef+" | PDFDocName: "+pdfDocNode.name);
	logger.log("LoggedInUser: "+ userlogged);

	//Assuming you have an image named after the logged in user somewhere in repo. e.g.: 'admin.jpg'
	var query = 'TYPE:\"cm:content\" AND @cm\\:name:"'+ userlogged + '.png"'; //get the image exactly with matching name
	var searchQuery = {
		query: query,
		language: "fts-alfresco"
	};

	logger.system.out("Executing SearchQuery: " + query);
	var imagenodes = search.query(searchQuery);
	var imagenodeForWatermarking = imagenodes[0];
	logger.log("ImageNodeRef: "+ imagenodeForWatermarking.nodeRef+" | ImageName: "+imagenodeForWatermarking.properties["cm:name"]);

	//Inserta el gráfico en el pedido en función del firmante al que corresponda
	var watermark_action = actions.create("pdf-watermark");
	watermark_action.parameters.inplace = true;
	//watermark_action.parameters["destination-folder"] = doc.parent;
	watermark_action.parameters["watermark-type"] = "image";
	//watermark_action.parameters["watermark-image"] = eval(nodes[0]);
	watermark_action.parameters["watermark-image"] = imagenodeForWatermarking.nodeRef;
	//watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
	//watermark_action.parameters["watermark-font"] = "Helvetica";
	//watermark_action.parameters["watermark-size"] = "12";
	watermark_action.parameters.page = "all";
	watermark_action.parameters["watermark-depth"] = "over";
	watermark_action.parameters.position = "manual";
	watermark_action.parameters["location-x"] = step;
	watermark_action.parameters["location-y"] ="1";
	watermark_action.execute(pdfDocNode);
	pdfDocNode.save();
	logger.log("***************************Incluida firma en :  " + pdfDocNode.name + " " + step);
	}
	catch (ex) {
   logger.logt("Exception occurred: " + ex.message);
}
	

JavaScript Console Log

PDFDocNodeRef: workspace://SpacesStore/a46d1938-4cb5-4da2-963a-1ed91300ea2f | PDFDocName: 5766774840.pdf
LoggedInUser: rcanovas
ImageNodeRef: workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b | ImageName: rcanovas.png
***************************Incluida firma en :  5766774840.pdf 100

using userhome.properties.name to get username logged is ok because it shown in the log.

I feel lost because I don't understand the behavior of the query. It works in the console but not in the script

 

cristinamr
Advanced

Re: Strange things with PDFToolkit

Jump to solution

firma=search.findNode('workspace://SpacesStore/7b48a76d-ebfb-44ea-9a18-9e32540d250b');


findNode function is waiting as parameter a nodeRef not a string:

Snag_29f3480a.png

Instead, you can try with utils.getNodeFromString.

Cheers,

Cristina.

--
VenziaIT: helping companies since 2005! Our ECM products: AQuA & Seidoc
pjcaracuel_2349
Active Member II

Re: Strange things with PDFToolkit

Jump to solution

Hi Cristina,

Thanks 

It's so strange (sorry for my bad english)

var firma = search.findNode('workspace://SpacesStore/c573e408-a6d6-4ce0-a84a-a6c040d60e2e');
logger.log("***************************Firma : " + firma.name );

In Javascript Console

***************************Firma :  XXXXX_XXXX.png

I have other scripts where it´s code run ok.

Now I prefer use a query but it doesn´t work I tried a workaround using findNode but it's the same. In Consola JAvascript run ok but in script no.

B.R

 

Pedro