Class

PDFGen

PDFGen(width, height)

Constructor

# new PDFGen(width, height)

render a PDF. **Note: PDFGen module must be loaded by calling LoadLibrary("pdfgen") before using!**
Parameters:
Name Type Description
width number page width.
height number page height.
See:
  • LoadLibrary()

Members

number

# height

page height
number

# width

page width

Methods

# AddBarcode(type, x, y, w, h, txt, col)

Add a barcode to the document
Parameters:
Name Type Description
type number PDF_BARCODE_128A or PDF_BARCODE_39
x number X offset to put barcode at
y number Y offset to put barcode at
w number Width of barcode
h number Height of barcode
txt string Barcode contents
col number ARGB Color or -1 for no color to draw barcode

# AddBookmark(parent, txt) → {number}

Parameters:
Name Type Description
parent number ID of a previously created bookmark that is the parent of this one. PDF_TOPLEVEL_BOOKMARK if this should be a top-level bookmark.
txt string String to associate with the bookmark
number

# AddCircle(x, y, r, width, col, fill_col)

Parameters:
Name Type Description
x number X offset of the center of the circle
y number Y offset of the center of the circle
r number Radius of the circle
width number Width of the circle outline stroke
col number ARGB Color or -1 for no color to draw the circle outline stroke
fill_col number ARGB Color or -1 for no color to fill the circle

# AddCubicBezier(x1, y1, x2, y2, xq1, yq1, xq2, yq2, width, col)

Add a cubic bezier curve to the document
Parameters:
Name Type Description
x1 number X offset of the initial point of the curve
y1 number Y offset of the initial point of the curve
x2 number X offset of the final point of the curve
y2 number Y offset of the final point of the curve
xq1 number X offset of the first control point of the curve
yq1 number Y offset of the first control point of the curve
xq2 number X offset of the second control of the curve
yq2 number Y offset of the second control of the curve
width number Width of the curve
col number ARGB Color or -1 for no color to draw the curve

# AddCustomPath(ops, width, col, fill_col)

Add a custom path to the document.

Each entry in the ops array must consist of an array with 7 values. Unused values have to be 0.
value 1: op Operation command. Possible operators are: m = move to, l = line to, c = cubic bezier curve with two control points, v = cubic bezier curve with one control point fixed at first point, y = cubic bezier curve with one control point fixed at second point, h = close path
value 2: X offset of the first point. Used with: m, l, c, v, y
value 3: Y offset of the first point. Used with: m, l, c, v, y
value 4: X offset of the second point. Used with: c, v, y
value 5: Y offset of the second point. Used with: c, v, y
value 6: X offset of the third point. Used with: c
value 7: Y offset of the third point. Used with: c

Parameters:
Name Type Description
ops Array.<Array.<number>> an array of 7 - value arrays with the ops of the path.
width number Width of polygon border
col number ARGB Color or -1 for no color to draw the polygon
fill_col number ARGB Color or -1 for no color to fill the path

# AddEllipse(x, y, xr, yr, width, col, fill_col)

Parameters:
Name Type Description
x number X offset of the center of the ellipse
y number Y offset of the center of the ellipse
xr number Radius of the ellipse in the X axis
yr number Radius of the ellipse in the Y axis
width number Width of the ellipse outline stroke
col number ARGB Color or -1 for no color to draw the ellipse outline stroke
fill_col number ARGB Color or -1 for no color to fill the ellipse

# AddFilledPolygon(points, width, col)

Add a filled polygon to the document
Parameters:
Name Type Description
points Array.<Array.<number>> an array of 2-number arrays with the points of the polygon (e.g. [[10,10], [20,20], [30,30]]).
width number Width of polygon border
col number ARGB Color or -1 for no color to draw the polygon

# AddFilledRectangle(x, y, w, h, width, fill, border)

Add a filled rectangle to the document
Parameters:
Name Type Description
x number X offset to start rectangle at
y number Y offset to start rectangle at
w number Width of rectangle
h number Height of rectangle
width number Width of rectangle border
fill number fill ARGB Color or -1 for no color to draw the rectangle
border number border ARGB Color or -1 for no color to draw the rectangle

# AddImageFile(x, y, w, h, fname)

Add an image file as an image to the document. Support image formats: JPEG, PNG, BMP & PPM
Parameters:
Name Type Description
x number X offset to put BMP at
y number Y offset to put BMP at
w number Displayed width of image
h number Displayed height of image
fname string Filename of image file to display

# AddLine(x1, y1, x2, y2, width, col)

Parameters:
Name Type Description
x1 number X offset of start of line
y1 number Y offset of start of line
x2 number X offset of end of line
y2 number Y offset of end of line
width number Width of the line
col number ARGB Color or -1 for no color to draw the line

# AddPolygon(points, width, col)

Add an outline polygon to the document
Parameters:
Name Type Description
points Array.<Array.<number>> an array of 2-number arrays with the points of the polygon (e.g. [[10,10], [20,20], [30,30]]).
width number Width of polygon border
col number ARGB Color or -1 for no color to draw the polygon

# AddQuadraticBezier(x1, y1, x2, y2, xq, yq, width, col)

Add a quadratic bezier curve to the document
Parameters:
Name Type Description
x1 number X offset of the initial point of the curve
y1 number Y offset of the initial point of the curve
x2 number X offset of the final point of the curve
y2 number Y offset of the final point of the curve
xq number X offset of the control point of the curve
yq number Y offset of the control point of the curve
width number Width of the curve
col number ARGB Color or -1 for no color to draw the curve

# AddRectangle(x, y, w, h, width, col)

Add an outline rectangle to the document
Parameters:
Name Type Description
x number X offset to start rectangle at
y number Y offset to start rectangle at
w number Width of rectangle
h number Height of rectangle
width number Width of rectangle border
col number ARGB Color or -1 for no color to draw the rectangle

# AddText(txt, size, x, y, col)

Add a text string to the document
Parameters:
Name Type Description
txt string String to display
size number Point size of the font
x number X location to put it in
y number Y location to put it in
col number ARGB Color or -1 for no color to draw the text

# AddTextWrap(txt, size, x, y, angle, col, wwidth, align) → {number}

Add a text string to the document, making it wrap if it is too long
Parameters:
Name Type Description
txt string String to display
size number Point size of the font
x number X location to put it in
y number Y location to put it in
angle number text rotation angle in radians
col number ARGB Color or -1 for no color to draw the text
wwidth number Width at which to wrap the text
align number Text alignment (see PDF_ALIGN_xxx)
the final height of the wrapped text here
number

# AppendPage()

Add a new page to the given pdf

# GetFontTextWidth(font, txt, size) → {number}

Calculate the width of a given string in the current font
Parameters:
Name Type Description
font string Name of the font to get the width of.
txt string Text to determine width of
size number Size of the text, in points
text width
number

# PageSetSize(w, h)

Adjust the width/height of current page
Parameters:
Name Type Description
w number Width of the page in points
h number Height of the page in points

# Save(filename)

Save the given pdf document to the given FILE output
Parameters:
Name Type Description
filename string Name of the file to store the PDF into

# SetFont(font)

Sets the font to use for text objects. Default value is Times-Roman if this function is not called. Note: The font selection should be done before text is output, and will remain until pdf_set_font is called again.
Parameters:
Name Type Description
font string New font to use. This must be one of the standard PDF fonts