Welcome folks today in this blog post we will be adding meta properties to the pdf document using jspdf
library in browser using javascript. All the full source code of the application is shown below.
Get Started
In order to get started yo need to make a index.html
file and copy paste the following code
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script> </html> |
As you can see we are including the jspdf cdn
Now we need to add the javascript
code to add the meta properties in the pdf document as shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
var doc = new jsPDF(); doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.'); // Optional - set properties on the document doc.setProperties({ title: 'Title', subject: 'This is the subject', author: 'Author Name', keywords: 'generated, javascript, web 2.0, ajax', creator: 'Creator Name' }); // Output as Data URI doc.save('Test.pdf'); |
As you can see we are initializing a new jspdf
document and then we are using the setProperties()
method to set the meta properties about the pdf
document. We are adding the properties & attributes such as title,subject,author,creator & keywords
about the pdf document.