Retrieve attachments of type imge/jpeg and embedding them into pdf report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 09:06 AM
Hi,
Has anyone created a pdf document via script, which takes and uses the attached images to a particular record? To create a pdf using the PDFGenerationAPI, the content of the document must be an html passed as a string such as:
var pdfGen = new sn_pdfgeneratorutils.PDFGenerationAPI;
var myHtml = "<body><p>Hello World!</p></body>";
var result = pdfGen.convertToPDF( myHtml, "target_table", "target_record_sys_id", "documentName");
gs.info(JSON.stringify(result));
For the report I neeed to create a img tag which src point to the location of every image attached to the record. In this way, the pdf generator retrieves and embeds the images in the pdf. To make this dynamic, i use a while loop with the outcome obtained from a GlideRecod over the table "sys_attachment". However, for simplicity I'll use an if conditional and pretend that we are looking to retrieve a single attachement.
var grAttch = new GlideRecord('sys_attachment');
grAttch.addQuery('table_name','wm_task'); // -> The table of the record which attachments I want
grAttch.addQuery('table_sys_id','some_sys_id'); // -> of the specific record stored in wm_task
grAttch.query();
if(grAttch.next()){
if (grAttachment.content_type=="image/jpeg"){
var atsysid = grAttachment.getValue('sys_id');
myHtml = "<img src=\"https://snow_instance/nav_to.do?uri=sys_attachment.do?sys_id="+atsysid+"\">";
}
}
var result = pdfGen.convertToPDF( myHtml, "target_table", "target_record_sys_id", "documentName");
gs.info(JSON.stringify(result));
After running this, a pdf is generated and attached into the target record. however, no image is retrieved and embeded. I think this is because (if I understood correctly what i found in other posts), the actual data of all attachments are actually split into chunks of 4kb max, and stored into another table called 'sys_attachment_doc'. Any ideas of how can this be approached?
I appreciate the help before hand.
Regards,
Israeli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 05:04 AM
Hi @Israeli,
If you are getting data from an HTML Type Field, you can attach pictures from HTML Type fields into pdf generating without gliding the sys_attachment table.
You can use the following line of code:
Ex: htmlString.replaceAll('/sys_attachment.do', "sys_attachment.do");
Note: 'htmlString' is where you are storing all the data.
Regards
Kartheek.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2024 10:18 AM
Hi @Israeli
Have you figured it out how to do this? I have a similar situation. I'm trying to find out how to embed an image into a PDF ... tried a couple of things with no luck yet