How to Create Text Columns in PDF file using JavaScript

This sample source code will help you to use BytescoutPDF.js (Bytescout PDF Generator for JavaScript) for creating text columns in generated PDF file.

// 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();
 
    // set document properties: Title, subject, keywords, author name and creator name
    pdf.propertiesSet("Sample document title", "Sample subject", "keyword1, keyword 2, keyword3", "Document Author Name", "Document Creator Name");
 
    // add new page
    pdf.pageAdd();
 
	pdf.textSetBoxPadding(3);
 
    // set text box for first column
    pdf.textSetBox(50, 50, 200, 200);
    // draw a rectangle around it
    pdf.graphicsDrawRectangle(50, 50, 200, 200);
    // add text:
    pdf.textAddToBox('First column', true);
    pdf.textAddToBox('First column', true);
    pdf.textAddToBox('First column', true);
 
    // set text box for second column
    pdf.textSetBox(250, 50, 200, 200);
    // draw a rectangle around it
    pdf.graphicsDrawRectangle(250, 50, 200, 200);
    // add text:
    pdf.textAddToBox('Second column', true);
    pdf.textAddToBox('Second column', true);
    pdf.textAddToBox('Second column', true);
 
    // return BytescoutPDF object instance
    return pdf;
}

Generated PDF file with text columns (click to view full size):

Click to view full size