How can I merge three different pdf as one?

sashraf93
Mega Contributor

Hi,

 

I would like to know if we can merge three different pdf files which are attached on an task record to a one single pdf containing the data from all three pdf's?

6 REPLIES 6

Ahana 01
Tera Expert

Yes, it is possible to merge multiple PDF files attached to a task record into a single PDF in ServiceNow. However, this is not a built-in feature of ServiceNow and would require custom scripting or a third-party integration. Here are the general steps:

1. Retrieve the attachments: Use GlideRecord to query the sys_attachment table and get the attachments associated with the task record.

2. Convert the attachments to a format that can be manipulated: ServiceNow stores attachments as binary data, so you would need to convert this data into a format that can be manipulated, such as a byte array or a stream.

3. Merge the PDFs: This is the most complex step and would likely require a third-party library or API. There are many libraries available for manipulating PDFs, such as PDFBox or iText. You would need to write a script that uses one of these libraries to merge the PDFs.

4. Attach the merged PDF to the task record: Once the PDFs have been merged, you can convert the merged PDF back into binary data and attach it to the task record using the Attachment API.

Here is a sample code:

javascript
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', taskSysId);
gr.addQuery('table_name', 'task');
gr.query();

while(gr.next()) {
var sa = new GlideSysAttachment();
var bytes = sa.getBytes(gr);
// Use a third-party library to merge the PDFs
}

// Use the Attachment API to attach the merged PDF to the task record
var attachment = new GlideSysAttachment();
attachment.write(taskGr, 'merged.pdf', 'application/pdf', mergedBytes);


Please note that this is a high-level overview and the actual implementation may vary depending on the specific requirements and the third-party library used.


nowKB.com
For a good and optimistic result, and solving ServiceNow-related issues please visit this website.https://nowkb.com/home

Gpope
Tera Contributor

Hey @sashraf93 ! Have you ever solve this ? 

Thanks! 

morenjenly
Mega Contributor

With my advice, you can combine multiple PDFs into one by applying your online skills. There are a lot of solutions accessible, but I want to give you an excellent choice so that you can finish your work easily and quickly. The Pcinfotools PDF Split and Merge Tool are the most latest and professional software. This software can easily and quickly combine multiple PDF files into a single PDF document. This software splits and combines PDF files while preserving attachments and all source file attachments will stay in the output PDF file. It also offers the capacity to add files or folders to merge several PDF files into one. All versions of the Microsoft Windows OS, among others, are supported by this software. All of the attachments that include multiple PDF files are placed in a different folder. This utility fully saves and secures your PDF file information by maintaining the design and structure of your files exactly as they were in the original PDF files. This tool never loses your PDF file properties.

morenjenly
Mega Contributor

With my advice, you can combine multiple PDFs into one by applying your online skills. There are a lot of solutions accessible, but I want to give you an excellent choice so that you can finish your work easily and quickly. The Pcinfotools PDF Split and Merge Tool are the most latest and professional software. This software can easily and quickly combine multiple PDF files into a single PDF document. This software splits and combines PDF files while preserving attachments and all source file attachments will stay in the output PDF file. It also offers the capacity to add files or folders to merge several PDF files into one. All versions of the Microsoft Windows OS, among others, are supported by this software. All of the attachments that include multiple PDF files are placed in a different folder. This utility fully saves and secures your PDF file information by maintaining the design and structure of your files exactly as they were in the original PDF files. This tool never loses your PDF file properties.