Has anyone worked with rendering PDFs? I am trying...
# suitescript
r
Has anyone worked with rendering PDFs? I am trying to render a PDF into another one. I'm using pdfset tags and I'm saving the file into the file cabinet, my issue is that no matter what I try, the URL is not processed correctly and I get an error. I'm also unable to modify the & characters and replace them with & Has anyone gone through this before?
s
what URL are you referring to?
r
I am hardcoding the accountdomain into a variable and concatenating it with the file's URL, which results into sth like this: https://[ACCOUNTID].app.netsuite.com/core/media/media.nl?id=272257&c=[ACCOUNTID]&h=bZPdjOEAZEaNAVWEVekxgrTQ3EpFjAt02EpT8gTt0ddgAhsa&_xt=.pdf I also tried using the full url directly but nothing seems to work
s
are you trying to put this in the PDF, or just to create a link to the PDF?
r
The goal is to render the existing file (which is a PDF containing Item Drawings) into a new PDF (for Work Orders). Right now I am trying to build the html from the script, since I didn't have any luck with the advanced pdf template. This is my code when generating the print:
var htmlTemplate =
'<?xml version="1.0"?>'+
'<!DOCTYPE pdf PUBLIC "-<//big.faceless.org//report>" "report-1.1.dtd">'+
'<pdfset>' +
'<pdf>' +
'<head>' +
'<style>' +
'body { font-family: Arial, sans-serif; margin: 0; padding: 0; }' +
'table { width: 100%; border-collapse: collapse; }' +
'th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; }' +
'h1, h2 { text-align: center; }' +
'.header { width: 100%; text-align: right; padding-right: 10px; }' +
'.footer { width: 100%; text-align: right; padding-right: 10px; }' +
'</style>' +
'</head>' +
'<body>' +
'<div class="header">' +
'<h1>Work Order #: ' + workOrderRecord.getValue({ fieldId: 'tranid' }) + '</h1>' +
'<p>Date: ' + workOrderRecord.getValue({ fieldId: 'trandate' }) + '</p>' +
'</div>' +
'<hr/>' +
'<table>' +
'<tr><th>Item</th><th>Quantity</th></tr>' +
generateItemRows(workOrderRecord) +
'</table>' +
'<br/>' +
'<div class="footer"><p>Drawing attached below</p></div>' +
'</body>' +
'</pdf>' +
'<pdf src="' + savedFileUrl + '"></pdf>' +
'</pdfset>';
s
encodeURI(savedFileUrl)
r
Above method worked! thanks @suitedev you rock!
❤️ 1