Skip to content

devConcordia/pdf-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf-javascript

This project arose from the need to generate PDF files for production on a plotter. As it was developed to run in a web browser, some features still need to be implemented to work with Node.js.

References

Basic usage

In this example, a PDF file is generated with the message "Hello World!" in the bottom left corner of the page.

/// importing ...
import { PDF, PDFPage, PDFStream } from "../source/index.mjs"

/// create a document
let doc = PDF.Create();

/// create a page
let page = new PDFPage();

/// indicate a font type used by the page
    page.use( PDF.Fonts.COURIER );



let fontSize = 4;
let px = 20;
let py = 20;

/// init a 2d renderer
let content = new PDF.Path2D();

/// set a fill color
content.fillColor( new PDF.Color( 0xff0000 ) );

/// write "hello world"
content.fillText( 'Hello World!', px, py, fontSize, PDF.Fonts.COURIER );

/// add content to the page
page.append( new PDFStream( content ) );

/// add page to document
doc.attach( page );


/// display in an iframe
doc.preview( document.body, innerWidth, innerHeight );

/// open a popup
doc.open();

/// download
doc.download();

See examples

To view the examples in docs/, you need to start a local server. In the following example, we use Python to start a simple server. Then, open the localhost in a web browser.

git clone https://github.com/devConcordia/pdf-javascript.git

cd pdf-javascript

python -m http.server

About

A generator for PDF files using Javascript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published