Add print button to document viewer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 04:20 PM
Hello Everyone,
Have you ever implemented a print button to document viewer? If yes, can you let me know the steps which you've performed.
Thanks
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2025 09:37 PM
Hi @Arun Kumar D ,
I have found some solutions from other questions raised in community.
You can refer to solution provided by @Ravi Gaurav
To add a print button to a document viewer in ServiceNow instead of a download option, you can follow these general steps. The exact implementation may vary based on your specific ServiceNow instance and the way your document viewer is set up. Here’s a basic outline of how you can achieve this:
Steps to Add a Print Button in ServiceNow Document Viewer
Identify the Document Viewer: Determine where the document viewer is located in your ServiceNow instance. This could be a UI page, a widget, or a specific form.
Modify the UI Page or Widget:
- If you are using a UI page, navigate to System UI > UI Pages and find the relevant page.
- If you are using a widget, go to Service Portal > Widgets and locate the widget that contains the document viewer.
Add a Print Button:
- In the HTML section of the UI page or widget, add a button element for printing. For example:
- <button id="printButton" onclick="printDocument()">Print Document</button>
Implement the Print Functionality:
- You will need to create a JavaScript function that handles the print action. This function can be added in the script section of the UI page or widget. Here’s a simple example:
- function printDocument() {
// Assuming the document viewer is in an iframe or a specific div
var printContent = document.getElementById('documentViewerId'); // Replace with your document viewer's ID
var WinPrint = window.open('', '', 'width=900,height=650');
WinPrint.document.write('<html><head><title>Print Document</title>');
WinPrint.document.write('</head><body >');
WinPrint.document.write(printContent.innerHTML); // Get the content to print
WinPrint.document.write('</body></html>');
WinPrint.document.close();
WinPrint.print();
}
Please mark the answer helpful and correct if it resolves the issue. Happy scripting 🙂
-Shantanu