JavaScript PDF Creator is a client library to generate PDFs in pure JavaScript. JavaScript PDF Creator is a leading HTML5 client solution for generating PDFs, used for event tickets, reports, certificates.

[Live Demo] https://veryutils.com/demo/jspdf/
[Documentation] https://veryutils.com/demo/jspdf/docs/

With JavaScript PDF Creator Library, you can create PDF files easily from your web page. In order to use this JavaScript library, you need to include js file, create an object and call its methods precisely defining what and how to render, for example:

[head]
[script src="https://veryutils.com/demo/jspdf/dist/jspdf.min.js"][/script]
[/head]

Then you're ready to start making your document:

//JavaScript
//Default export is a4 paper, portrait, using millimeters for units
var doc = new jsPDF()
doc.text('Hello world!', 10, 10)
doc.save('a4.pdf')

If you want to change the paper size, orientation, or units, you can do:

//JavaScript
//Landscape export, 2×4 inches
var doc = new jsPDF({orientation: 'landscape', unit: 'in', format: [4, 2]})
doc.text('Hello world!', 1, 1)
doc.save('two-by-four.pdf')

The JavaScript PDF Creator library APIs

Creating a document

First let us discuss how to create a new document. It's as simple as executing this code.

var doc = new jsPDF(orientation, unit, format, compress);

The constructor can take several parameters.
• orientation - The default value for orientation is "portrait". We can set it to "landscape" if we want a different page orientation.
• unit - We can tell jsPDF in which units we want to work. Use one of the following: "pt" (points), "mm" (default), "cm", "in".
• format - It's default page format. It can be "a3", "a4" (default), "a5", "letter", "legal".

We can add new page using the following code.

doc.addPage(width, height);

As parameters we pass the page, width and height in the units defined in the document constructor. Adding pages moves us to this page, so any operation will be executed on that page. If we want to go to another page we can use the setPage function.

doc.setPage(pageNumber);

You can also get actual page numbers by using this code.

doc.internal.getNumberOfPages();

The first example in the sample application demonstrates the usage of the functions described above. You can run the application to check it out and investigate the application's code that is attached to the article.

Working with text

First, the most important thing is displaying text, we do it using the doc.text function which takes 3 parameters. The first two are X and Y positions of the text in units defined in the document constructor. Notice that the Y position, is the position of the text baseline, so printing something with the Y position set to 0 will actually print it over the top edge of the document. The third argument is the text to be displayed.

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

The second thing is the font name used to draw the text. We can choose one of the following: courier, helvetica, time. We change the font family and font style by running the doc.setFont function.

doc.setFont("courier", "italic");

By executing the doc.getFontList function we can find out what fonts are available and what font styles we can set for given font.

doc.getFontList();

/*
{
"helvetica": ["normal", "bold", "italic", "bolditalic"],
"Helvetica": ["", "Bold", "Oblique", "BoldOblique"],
"courier": ["normal", "bold", "italic", "bolditalic"],
"Courier": ["", "Bold", "Oblique", "BoldOblique"],
"times": ["normal", "bold", "italic", "bolditalic"],
"Times": ["Roman", "Bold", "Italic", "BoldItalic"]
}
*/

We can also change font styles individually thanks to the doc.setFontStyle or the doc.setFontType function, which is the alias to the first one.

doc.setFontType("bolditalic");

// is the same as calling
doc.setFontStyle("bolditalic");

Next thing is the font size. It's as simple as calling the doc.setFontSize function.

doc.setFontSize(40);

The last thing is the text color. We change text color using the doc.setTextColor function and passing three parameters which are RGB (Red, Green, Blue) color values.

doc.setTextColor(255, 0, 0);

The sample document showing different ways of displaying text is located under Example 2 in the sample application attached to the article.

Working with images

The only function for images is the doc.addImage. It takes image as a first parameter, image format/type as a second and X, Y positions of the image as a third and fourth arguments. We can also optionally pass new image size as a fifth and sixth argument.

var img = new Image();
img.addEventListener('load', function() {
var doc = new jsPDF();
doc.addImage(img, 'png', 10, 50);
});
img.src = 'images/tizen.png';

In the example above, we passed an Image HTML DOM element as a first argument of the addImage function, however it can also be a base64 encoded image string. For now, the only supported image formats are jpeg/jpg and png.

Working with graphics

First, we have to set the drawn shapes fill and stroke colors. We do it using the doc.setFillColor and the doc.setDrawColor accordingly, passing RGB color values as parameters.

doc.setFillColor(100, 100, 240);
doc.setDrawColor(100, 100, 0);

We can also set the stroke width. The stroke width unit is the same as defined in the document constructor.

doc.setLineWidth(1);

Every shape drawing function takes the center point coordinates (triangle is the only exception) as two first parameters. They also take the last parameter drawing style. It can be "S", "F", "DF", "FD" string and the meanings are: "stroke", "fill", "stroke and fill", "fill and stroke". The last two of course differ in the order of the drawing operations.

We can draw an ellipse, by passing two radiuses...

// Empty ellipse
doc.ellipse(50, 50, 10, 5);

// Filled ellipse
doc.ellipse(100, 50, 10, 5, 'F');

// Filled circle with borders
... or a circle, by passing only one radius...
doc.circle(150, 50, 5, 'FD');

... or a rectangle, by passing its width and height...
// Empty square
doc.rect(50, 100, 10, 10);

// Filled square
doc.rect(100, 100, 10, 10, 'F');

// Filled square with borders
doc.rect(150, 100, 10, 10, 'FD');

... a rounded rectangle, by passing its width, height and border radiuses...
// Filled sqaure with rounded corners
doc.roundedRect(50, 150, 10, 10, 3, 3, 'FD');

... and a triangle, by passing each corners coordinates.
// Filled triangle with borders
doc.triangle(50, 200, 60, 200, 55, 210, 'FD');

We can also draw lines passing through the coordinates of two points.

// Line
doc.line(50, 250, 100, 250);

If you have any question for this JavaScript PDF Creator Library, please feel free to let us know, we are glad to assist you asap.

Write a review

Note: HTML is not translated!
    Bad           Good
Captcha

JavaScript PDF Creator Library

  • Product Code: MOD190715073315
  • Availability: In Stock
  • Viewed: 22157
  • Sold By: BestScripts
  • Seller Rating:
  • Seller Reviews: (0)
  • $79.95
  • $49.95-38%

  • Ex Tax: $49.95

Available Options


Related Products

PDF to Image Converter Command Line

PDF to Image Converter Command Line

PDF to Image Converter Command Line is a Windows console utility that create image files (png, jpg..

$59.95 Ex Tax: $59.95

Save
25%

HTMLPrint to Any Converter Command Line

HTMLPrint to Any Converter Command Line

HTMLPrint to Any Converter Command Line is a versatile tool that streamlines the process of printing..

$299.00 $399.00 Ex Tax: $299.00

Save
15%

Encrypt PDF Command Line

Encrypt PDF Command Line

EncryptPDF Command Line is a powerful tool that enables users to encrypt their PDF files by setting ..

$49.95 $59.00 Ex Tax: $49.95

Save
20%

Interactive SVG Map

Interactive SVG Map

Interactive SVG Map is a powerful JavaScript tool that transforms any SVG file into an interactive a..

$39.95 $49.95 Ex Tax: $39.95

PDF Validator Command Line

PDF Validator Command Line

PDF Validator Command Line is a Command Line software which can be used to verify conformance and ..

$99.95 Ex Tax: $99.95

Save
25%

PHP Ajax Mailer With Multiple Attachments

PHP Ajax Mailer With Multiple Attachments

PHP Ajax Mailer With Multiple Attachments Hey there, hope you are doing well, if you are looking ..

$14.95 $19.95 Ex Tax: $14.95

Save
17%

HTML5 Signature Pad to Image

HTML5 Signature Pad to Image

HTML5 Signature Pad to Image is a JavaScript library for drawing smooth signatures. It's HTML5 can..

$24.95 $29.95 Ex Tax: $24.95

PHP FTP Client - PHP Script

PHP FTP Client - PHP Script

PHPFTP ( PHP HTTP FTP ) is a simple and fast Web FTP application. You can upload, download and adm..

$29.95 Ex Tax: $29.95

PS to PDF Converter SDK

PS to PDF Converter SDK

PostScript (PS) to PDF Converter SDK is Library SDK for developers to convert from PostScript (PS) ..

$395.00 Ex Tax: $395.00

PDF Stamper SDK

PDF Stamper SDK

Welcome to the PDF Stamper SDK. This SDK allows you to stamp barcodes, hyperlinks, images, lines a..

$199.00 Ex Tax: $199.00

Save
20%

HTML5 Excel (Best JavaScript Data Grids and Spreadsheets)

HTML5 Excel (Best JavaScript Data Grids and Spreadsheets)

HTML5 Excel is an Online Excel Application which written in JavaScript completely. HTML5 Excel is ..

$79.95 $99.95 Ex Tax: $79.95

Online Javascript HTML5 Gauntlet Game

Online Javascript HTML5 Gauntlet Game

Online Javascript HTML5 Gauntlet Game Javascript Gauntlet Game Features: Play as Warrior, V..

$9.95 Ex Tax: $9.95

TIFF Toolkit -- Compress, Merge, Split, Extract, Compare and Maintain TIFF files

TIFF Toolkit -- Compress, Merge, Split, Extract, Compare and Maintain TIFF files

TIFF Toolkit is a powerful application tool which can compress TIFF image files to small size ones..

$19.95 Ex Tax: $19.95

PDF Page Counter for All Sub-folders by PHP Script

PDF Page Counter for All Sub-folders by PHP Script

PDF Page Counter can be used to count the number of pages of all PDFs in current directory and all..

$59.95 Ex Tax: $59.95

Tags: client pdf, generate pdf, html5 pdf, javascript pdf, js pdf, jspdf, make pdf, pdf generation, pdf generator, pdf library, pdf maker, pdf render, pdf sdk, pdf server, pdf writer, render pdf, web page pdf, web pdf, write pdf