Add text to pdf attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 10:09 PM
Attachment in kb table is embedded in article body.
Requirement is that when it is published approval dates should be added to 1st page of PDF attachment.
I tried with jsPDF, but is creating page ,not adding text on that attachment.
I'm already using PdfMergeSignRequestor to embedd signature image on 1st page of PDF attachment.
But I want approval dates below signature.
Any Suggestion???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 01:58 AM
How about using document templates (works outside of HR too)? You can upload a fillable PDF and specifically map dates and signatures to the right places in your PDF file. You can then have a script triggered to generate the PDF after article publish. The only problem is, you would need to actually have a PDF template created for each separate document, which will be used for the document generation, i.e. it will not use the attachment from the KB article. Perhaps you can work around that though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 02:42 AM
Can i get Document Templates without HRSD module free of cost?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2023 08:18 AM
As far as I understand you can, it's a free store plugin: https://store.servicenow.com/sn_appstore_store.do#!/store/application/6a9ea833b763330088d9bc78ee11a8...
If you are unsure, the standard response applies: "check with your account manager" 😉

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 02:15 AM
Hi,
To add approval dates to the first page of a PDF attachment embedded in a ServiceNow knowledge base article, you can use a combination of JavaScript and a PDF generation library such as jsPDF. Here are some steps you can follow:
Identify the location in the article body where the approval dates should be added. This could be a specific location on the first page or a section that is reserved for approvals.
Create a JavaScript function that extracts the PDF attachment from the article and converts it into a jsPDF object.
Use jsPDF to add a new page to the PDF document.
Add the signature image to the first page of the PDF document using PdfMergeSignRequestor or a similar library.
Add the approval dates to the desired location on the first page of the PDF document using jsPDF text functions.
Save the updated PDF document back to the knowledge base article as a new attachment or overwrite the existing attachment.
Here is an example code snippet that demonstrates how to add text to a jsPDF document:
// Create a new jsPDF object
var doc = new jsPDF();
// Add a new page to the document
doc.addPage();
// Add a text box to the first page of the document
doc.text('Approval Date: 2023-04-17', 20, 20);
// Save the document as a new attachment
var pdfBytes = doc.output('arraybuffer');
var attachment = new GlideRecord('sys_attachment');
attachment.initialize();
attachment.setDisplayValue('file_name', 'Updated PDF Attachment.pdf');
attachment.setValue('table_name', 'kb_knowledge');
attachment.setValue('table_sys_id', kb_knowledge_sys_id);
attachment.setValue('content_type', 'application/pdf');
attachment.setValue('size', pdfBytes.length);
attachment.setValue('u_uploaded_by', gs.getUserID());
attachment.setValue('u_data', pdfBytes);
attachment.insert();
Note that this is just an example and will need to be modified to fit your specific use case. You may also need to modify the code to handle multiple attachments or to extract the correct attachment from the article based on its name or metadata.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar