How to Set Document Properties When Generating PDF file in JavaScript - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

How to Set Document Properties When Generating PDF file in JavaScript

  • Home
  • /
  • Articles
  • /
  • How to Set Document Properties When Generating PDF file in JavaScript

This sample demonstrates how to set properties of PDF document generated in JavaScript with BytescoutPDF.js (Bytescout PDF Generator for JavaScript).
You can set such document properties as title, subject, keywords, author and creator name.

// function that creates BytescoutPDF instance (defined in BytescoutPDF.js script which have to be included into the same page)
// then calls API methods and properties to create PDF document
// and returns created BytescoutPDF object instance
// this CreatePDF() function is called from Sample.html

function CreatePDF() {

    // create BytescoutPDF object instance
    var pdf = new BytescoutPDF();

    var documentTitle = "Sample document title";
    var documentSubject = "Sample subject";
    var documentkeywords = "keyword1, keyword 2, keyword3";
    var documentAuthor = "Document Author Name";
    var documentCreator = "Document Creator Name";

    // set document properties: Title, subject, keywords, author name and creator name
    pdf.propertiesSet(documentTitle, documentSubject, documentkeywords, documentAuthor, documentCreator);

    // add empty page
    pdf.pageAdd();
    
    pdf.textAdd(20, 20, 'Document properties are set.', 0);

    // return BytescoutPDF object instance
    return pdf;
}

Generated PDF file with document properties set (click to view full size):

Click to view full size

prev
next