Sunday, February 3, 2019

Create a PDF File with Watermark

Here is how to add a watermark on a PDF document using nlapiXMLToPDF: (Please view this in Edit mode. The code does not render correctly if viewed in View mode/ Preview HTML)

function helloWorld()
{
var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">";
xml += "<pdf>\n";
xml += "<head>";
xml += "<macrolist>";
xml += "<macro id=\"watermark\">";
xml += "<p rotate=\"-45\" font-size=\"30pt\" color=\"#C0C0C0\">";
xml += "Confidential";
xml += "</p>";
xml += "</macro>";
xml += "</macrolist>";
xml += "</head>";
xml += "<body font-size=\"18\" background-macro=\"watermark\">\nHello World!\n</body>\n";
xml += "</pdf>";


var file = nlapiXMLToPDF( xml );
response.setContentType('PDF','helloworld.pdf');
response.write( file.getValue() ); 
}


Notice that I have used  "macro". According to BFO's user guide, macro is used as a block of XML which can be repeated multiple times throughout the document.

 

No comments:

Post a Comment