Converting Text to a PDF Attachment in ServiceNow: A Complete Guide
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2024 10:06 AM
ServiceNow offers a variety of features to help users manage and streamline business processes, including the ability to convert text data into PDF attachments. This functionality can be particularly useful when you want to preserve the content of a text file in a more secure and standardized format for sharing, storage, or documentation purposes. In this article, we'll explore how to use ServiceNow to convert text into PDF attachments, providing you with a clear understanding of the process and its benefits. Whether you're dealing with customer communications, internal reports, or any other type of textual information, this guide will show you how to leverage ServiceNow's capabilities to create PDF attachments from text. Let's get started!
var grAttachment = new GlideRecord("sys_attachment"); grAttachment.addQuery("table_sys_id", current.sys_id); grAttachment.addEncodedQuery("file_nameLIKEtxt"); grAttachment.query(); if (grAttachment.next()) { var gsa = GlideSysAttachmentInputStream(grAttachment.sys_id.toString()); var baos = new Packages.java.io.ByteArrayOutputStream(); gsa.writeTo(baos); baos.close(); var content = baos + ' '; //the break lines were missing so I added this for (var i = 0; i < content.length; i++) { var match = /\r|\n/.exec(content[i]); if (match) { content = content.replace(content[i], '<br>'); } } var html = '<p>' + content + '</p>'; var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI(); var hfInfo = new Object(); hfInfo["FooterText"] = "0001/2022 - v1 de 02-02-2022"; hfInfo["PageSize"] = "A4"; hfInfo["GeneratePageNumber"] = "true"; hfInfo["FooterTextAlignment"] = "BOTTOM_LEFT"; var result = pdf.convertToPDFWithHeaderFooter(html, "sc_req_item", current.sys_id, "s", hfInfo);
}