ericbirdsall
10/03/2024, 2:37 PMerictgrubaugh
10/03/2024, 3:46 PMborncorp
10/03/2024, 4:00 PMborncorp
10/03/2024, 4:01 PMericbirdsall
10/03/2024, 4:02 PMborncorp
10/03/2024, 4:03 PMericbirdsall
10/03/2024, 4:04 PMhtml2pdf.js
(the client side library)
If I use that in a Suitelet, I can get the base64 encoded string of the PDF and then send that to the backend of the Suitelet and use file.create
to create the file.
But I was trying to figure out a fully backend solution
e.g. Create a Print button on an Invoice that just sends the Transaction ID (and maybe a template id) to a suitelet, the suitelet creates a HTML/CSS string, I use a library (or API) to convert the HTML string into a base 64 encoded string, create the file and render the PDF to the userericbirdsall
10/03/2024, 4:05 PMShawn Talbert
10/03/2024, 4:10 PMShawn Talbert
10/03/2024, 4:16 PMericbirdsall
10/03/2024, 4:20 PMShawn Talbert
10/03/2024, 4:29 PMborncorp
10/03/2024, 4:31 PMborncorp
10/03/2024, 4:39 PMborncorp
10/03/2024, 4:41 PMvar htmlTemplate=file.load({id: 5854 });
//var htmlTemplate = "<html><header><title>This is title</title></header><body>Hello world</body></html>";
var htmlString = htmlTemplate.getContents();
var urlTemplate = '<http://api.pdflayer.com/api/convert>'
+ '?access_key=' + PDF_LAYER_ACCESS_KEY
+ '&use_print_media=1'
var response = <http://http.post|http.post>({
url: urlTemplate,
body: 'document_html=' + encodeURIComponent(htmlString),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
var base64PDF = response.body;
var fileObj = file.create({
name: 'result.pdf',
fileType: file.Type.PDF,
contents: base64PDF,
description: 'This is a PDF saved from PDFLayer.com.',
folder: 695,
isOnline: true
});
var fileId = fileObj.save();
ericbirdsall
10/03/2024, 4:42 PMericbirdsall
10/03/2024, 4:43 PMFred Pope
10/03/2024, 9:39 PM