How to use jspdf library

Aman Trivedi1
Tera Contributor

I have a UI page Which I need to call using UI Action button to download as PDF, but by using jspdf library.

So I am confused in how to import Jspdf in my PDI.

 

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Aman Trivedi1 ,

 

You can follow these steps:

  1. Download the jspdf library from the official website: https://github.com/MrRio/jsPDF

  2. Extract the downloaded zip file and copy the "dist" folder into your instance's "scripts" folder. You can find this folder in the "File System" section of your instance.

  3. Create a UI Action button and add the following code to it:

 

var doc = new jsPDF();

doc.text('Hello world!', 10, 10);

doc.save('hello.pdf');

 

 

This code creates a new PDF document using the jspdf library, adds the text "Hello world!" to it, and saves it as "hello.pdf".

 

   4. Save the UI Action and test it by clicking the button. A PDF file should be downloaded with the text "Hello world!".

Note: You may need to include the jspdf library in your HTML file if it is not already included. To do this, add the following code to your HTML file:

 

<script type="text/javascript" src="/scripts/jspdf.min.js"></script>

 

 

Make sure to adjust the path to the jspdf library based on where you saved it in your instance.

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

 

where to find the "dist" folder in my ServiceNow instance.

Good Day, I cant seem to find how to add the dist folder to the instance.

could you explain in more detail please?