Wednesday, January 30, 2019

Merge a PDF file from the File Cabinet using nlapiXMLtoPDF

 

Using 'pdfset' element, another file can be merged as another page using the 'src' attribute where the URL of the file can be indicated.
*** Note that the 'Available without login' must be checked on the file record for this to work.


Sample code snippet:
 ======================
 function xmltoPDF_pdfSet(request, response){

  var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n";
  xml += "<pdfset>";
  
  // PDF Page 1
  xml += "<pdf>";
  xml += "<body>";
  xml += " This is Page 1";
  xml += "</body>";
  xml += "</pdf>";
  
 ` // PDF Page 2
  xml += "<pdf>";
  xml += "<body>";
  xml += "This is Page 2";
  xml += "</body>";
  xml += "</pdf>";

  // PDF Page 3 (PDF from File cabinet)
  // --Get the URL of the PDF file
  // --Escape characters for XML 
  var pdf_fileURL = nlapiEscapeXML('/core/media/media.nl?id=5860&c=TSTDRV570139&h=b525d5f23455ee07cc24&_xt=.pdf'); 

  xml += "<pdf src='"+ pdf_fileURL +"'/>";
  xml += "</pdfset>";

  var filePDF = nlapiXMLToPDF(xml);
  response.setContentType('PDF', 'pdfset.pdf', 'inline');
  response.write(filePDF.getValue());

 }
 ======================

No comments:

Post a Comment