Need to print a portal page as a PDF and attach it to a record using a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 11:06 AM
I'm hoping someone out there has some ideas to help out with this one. We have a requirement to generate a PDF copy of a form only available on the portal, and attach it to a record when the record is created. I have tried using the ?PDF URL functionality, but that only outputs the back end form in a generic format.
The reason we need the form from the portal is due to the fact that the portal form is all html formatted to match the design the client requires their form to be in for distribution to their users (an official document layout). The official PDF document then needs to be emailed to the client with other generated attachments, and this is all done using notifications to include all attachments.
Any help would really be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2022 09:48 AM
Has anyone been able to accomplish this? i have a similar need!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2020 01:14 AM
You have two options for this and none of them are OOB options. Unfortunately the oob pdf generations is not very good.
For the past 6 months I have been working on a large application in ServicePortal that generates letters in PDF.
If you just need to take a div element from a widget and convert to pdf you can use jsPDF. I used this to begin with
https://github.com/MrRio/jsPDF
however this only works in the client. So to save the pdf as attachment you need to use the table api to post.
example:
iframe.attr('src', null); // if you want to display the PDF for viewing on the portal
var pdf = new jsPDF('p', 'pt', 'a4');
var html = '<h1>this is the html</h1>';
pdf.html(html, {
callback: function (pdf) {
var pdfOut = pdf.output('blob');
var config = {
'headers': {
'Content-type': 'application/pdf',
'Accept': 'application/json'
}
};
iframe.attr('src', pdf.output('datauristring')); // if you want to display the PDF for viewing on the portal
$http.post("/api/now/attachment/file?table_name=tablename&table_sys_id=sysid&file_name=filename", pdfOut, config);
}
});
Alternatively you can use an online REST based service.