wilton/PDFDocument
Generate PDF documents.
More...
Functions | |
Undefined | addPage (Object options, Function|Undefined callback) |
Append page to the document. | |
Undefined | destroy (Function|Undefined callback) |
Release memory allocated for this document. | |
Undefined | drawImage (Object options, Function|Undefined callback) |
Draw image. | |
Undefined | drawLine (Object options, Function|Undefined callback) |
Draw straight line. | |
Undefined | drawRectangle (Object options, Function|Undefined callback) |
Draw rectangle. | |
String | loadFont (String ttfPath, Function|Undefined callback) |
Load TrueType font from the specified TTF file. | |
Object | PDFDocument (Function|Undefined callback) |
Create PDFDocument instance. | |
Undefined | saveToFile (String path, Function|Undefined callback) |
Write this document contents into PDF file. | |
Undefined | writeText (Object options, Function|Undefined callback) |
Write text to document. | |
Undefined | writeTextInsideRectangle (Object options, Function|Undefined callback) |
Write text to document inside rectangle. |
This module allows to generate PDF documents.
Text, colors, lines and rectangles are supported.
TrueType font is required for PDF generation, it is read from a specified TTF file.
After use, PDF document instance may be destroyed manually using destroy()
or it will be destroyed during the shutdown.
libharu is used for PDF generation, refer to its doc for the information about the coordinate system.
Usage example:
Undefined PDFDocument::addPage | ( | Object | options, |
Function|Undefined | callback | ||
) |
Appends new page to the document and moves internal "write cursor" to this page. All subsequent content-related operation will be done to this page (until additional page will be appended).
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
String|Undefined
Paper format, supported values: A3
, A4
, A5
, B4
, B5
; either both format
and orientation
, or both width
and height
must be specified.String|Undefined
Paper orientation, supported values: PORTRAIT
, LANDSCAPE
Number|Undefined
Page width.Number|Undefined
Page height. Undefined PDFDocument::destroy | ( | Function|Undefined | callback | ) |
Releases memory allocated for this document.
callback | Function|Undefined callback to receive result or error |
Undefined
Undefined PDFDocument::drawImage | ( | Object | options, |
Function|Undefined | callback | ||
) |
Draws the specified image scaling it to the specified width
and higth
at the current (last added) page of the document.
Either imageHex
or imagePath
must be specified.
See libharu
documentation for the information about the coordinate system.
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
String|Undefined
image data in hexadecimalStringUndefined
path to image fileString
file format of the specified image data, supported formats: PNG
, JPEG
Number
x
coordinate of the lower-left corner of the rectangleNumber
y
coordinate of the lower-left corner of the rectangleNumber
Width of the rectangle in pt
Number
Height of the rectangle in pt
Undefined PDFDocument::drawLine | ( | Object | options, |
Function|Undefined | callback | ||
) |
Draws the straigth line with the specified lineWidth
and color
at the current (last added) page of the document.
See libharu
documentation for the information about the coordinate system.
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
Number
x
coordinate of the beginning of the lineNumber
y
coordinate of the beginning of the lineNumber
x
coordinate of the end of the lineNumber
y
coordinate of the end of the lineNumber|Undefined
Line width in pt
, default value: 1
Object|Undefined
Line color in RGB format, default value: black
Number
Red element as float
, must be in [0, 1]
Number
Green element as float
, must be in [0, 1]
Number
Blue element as float
, must be in [0, 1]
Undefined PDFDocument::drawRectangle | ( | Object | options, |
Function|Undefined | callback | ||
) |
Draws the rectangle with the specified lineWidth
and color
at the current (last added) page of the document.
See libharu
documentation for the information about the coordinate system.
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
Number
x
coordinate of the lower-left corner of the rectangleNumber
y
coordinate of the lower-left corner of the rectangleNumber
Width of the rectangle in pt
Number
Height of the rectangle in pt
Number|Undefined
Line (rectangle border) width in pt
, default value: 1
Object|Undefined
Line (rectangle border) color in RGB format, default value: black
Number
Red element as float
, must be in [0, 1]
Number
Green element as float
, must be in [0, 1]
Number
Blue element as float
, must be in [0, 1]
String PDFDocument::loadFont | ( | String | ttfPath, |
Function|Undefined | callback | ||
) |
Loads TrueType font from the specified TTF file. Loaded font will be added to the current document.
Multiple fonts can be loaded for the single document and used later for the text operations.
Returns the name of the loaded font.
ttfPath | String path to TTF file |
callback | Function|Undefined callback to receive result or error |
String
loaded font name Object PDFDocument::PDFDocument | ( | Function|Undefined | callback | ) |
Creates PDFDocument
instance, at least one page must be added to created document before writing content to it.
callback | Function|Undefined callback to receive result or error |
Object
PDFDocument
instance Undefined PDFDocument::saveToFile | ( | String | path, |
Function|Undefined | callback | ||
) |
Writes this document contents into PDF file on the specified path.
path | String File system path for the PDF file to write |
callback | Function|Undefined callback to receive result or error |
Undefined
Undefined PDFDocument::writeText | ( | Object | options, |
Function|Undefined | callback | ||
) |
Writes specified text to the current (last added) page of the document at the specified coordinates.
Text is processed using UTF-8
encoding.
See libharu
documentation for the information about the coordinate system.
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
String
Text contents to writeString
Name of the font to use for the specified text, font must already loaded for this document, name should be obtained from loadFont()
Number
Font size (in pt
) to use for the specified textNumber
x
coordinate of the texts beginningNumber
y
coordinate of the texts beginningObject|Undefined
Text color in RGB format, default value: black
Number
Red element as float
, must be in [0, 1]
Number
Green element as float
, must be in [0, 1]
Number
Blue element as float
, must be in [0, 1]
Undefined PDFDocument::writeTextInsideRectangle | ( | Object | options, |
Function|Undefined | callback | ||
) |
Writes specified text to the current (last added) page of the document placing it inside the specified rectangle. Text lines that do not fit inside the rectangle won't be dislayed.
Text is processed using UTF-8
encoding.
See libharu
documentation for the information about the coordinate system.
options | Object configuration object, see possible options below |
callback | Function|Undefined callback to receive result or error |
Undefined
Options
String
Text contents to writeString
Name of the font to use for the specified text, font must already loaded for this document, name should be obtained from loadFont()
Number
Font size (in pt
) to use for the specified textNumber
left
coordinate of the rectangleNumber
top
coordinate of the rectangleNumber
right
coordinate of the rectangleNumber
bottom
coordinate of the rectangleString
Text alignment inside the rectangle, supported values: LEFT
, RIGHT
, CENTER
, JUSTIFY
Object|Undefined
Text color in RGB format, default value: black
Number
Red element as float
, must be in [0, 1]
Number
Green element as float
, must be in [0, 1]
Number
Blue element as float
, must be in [0, 1]