Module pdfgen

Lua bindings to PDFgen

This documentation is partial, and doesn't cover all functionality yet.

Info:

Functions

new () Initializes the library
create (width, height, table) Create a new PDF object, with the given page width/height
set_font (font) Sets the font to use for text objects.
get_font_text_width (font_name, text, size) Calculate the width of a given string in the current font
add_text (page, text, size, xoff, yoff, colour) Add a text string to the document
add_rectangle (page, x, y, width, height, border_width, colour) Add an outline rectangle to the document
add_filled_rectangle (page, x, y, width, height, border_width, colour_fill, colour_border) Add a filled rectangle to the document
add_line (page, x1, y1, x2, y2, width, colour) Add a line to the document
add_image_file (page, x, y, display_width, display_height, image_filename) Add an image file as an image to the document.
add_bookmark (page, parent, name) Add a bookmark to the document
add_link (page, x, y, width, height, target_page, target_x, target_y) Add a link annotation to the document
get_page (page_number) Retrieve a page by its number.
page_set_size (page, width, height) Adjust the width/height of a specific page
add_text_wrap (page, text, size, xoff, yoff, angle, colour, wrap_width, align) Add a text string to the document, making it wrap if it is too long
add_text_rotate (page, text, size, xoff, yoff, angle, colour) Add a text string to the document at a rotated angle
save (filename) Save the given pdf document to the supplied filename.
height () Retrieves a PDF document height
width () Retrieves a PDF document width
page_height (page) Retrieves page height
page_width (page) Retrieves page width
add_barcode (page, code, x, y, width, height, string, colour) Add a barcode to the document
get_err (errval) Retrieve the error message if any operation fails
mm_to_point (mm) Convert a value in milli-meters into a number of points.
inch_to_point (inch) Convert a value in inches into a number of points.
rgb () Convert three 8-bit RGB values into a single packed 32-bit colour.
argb () Convert four 8-bit ARGB values into a single packed 32-bit colour.
clear_err () Acknowledge an outstanding pdf error
destroy () Destroy the pdf object, and all of its associated memory


Functions

new ()
Initializes the library

Returns:

    object the object pdfgen
create (width, height, table)
Create a new PDF object, with the given page width/height

Parameters:

  • width Width of the page
  • height Height of the page
  • table info Optional information to be put into the PDF header
set_font (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 pdfsetfont is called again.

Parameters:

  • font New font to use. This must be one of the standard PDF fonts: Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Symbol or ZapfDingbats

Returns:

    boolean false on failure, true on success
get_font_text_width (font_name, text, size)
Calculate the width of a given string in the current font

Parameters:

  • font_name Name of the font to get the width of. This must be one of the standard PDF fonts: Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Symbol or ZapfDingbats
  • text Text to determine width of
  • size Size of the text, in points

Returns:

    mixed false on failure, text_width calculated width in
add_text (page, text, size, xoff, yoff, colour)
Add a text string to the document

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • text String to display
  • size Point size of the font
  • xoff X location to put it in
  • yoff Y location to put it in
  • colour Colour to draw the text

Returns:

    boolean true on success, false on failure
add_rectangle (page, x, y, width, height, border_width, colour)
Add an outline rectangle to the document

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • x X offset to start rectangle at
  • y Y offset to start rectangle at
  • width Width of rectangle
  • height Height of rectangle
  • border_width Width of rectangle border
  • colour Colour to draw the rectangle

Returns:

    boolean true success, false on failure
add_filled_rectangle (page, x, y, width, height, border_width, colour_fill, colour_border)
Add a filled rectangle to the document

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • x X offset to start rectangle at
  • y Y offset to start rectangle at
  • width Width of rectangle
  • height Height of rectangle
  • border_width Width of rectangle border
  • colour_fill Colour to fill the rectangle
  • colour_border Colour to draw the rectangle

Returns:

    boolean true success, false on failure
add_line (page, x1, y1, x2, y2, width, colour)
Add a line to the document

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • x1 X offset of start of line
  • y1 Y offset of start of line
  • x2 X offset of end of line
  • y2 Y offset of end of line
  • width Width of the line
  • colour Colour to draw the line

Returns:

    boolean true success, false on failure
add_image_file (page, x, y, display_width, display_height, image_filename)
Add an image file as an image to the document. Passing 0 for either the display width or height will include the image but not render it visible. Passing a negative number either the display height or width will have the image be resized while keeping the original aspect ratio. Supports image formats: JPEG, PNG, PPM, PGM & BMP

Parameters:

  • page Page to add image to (NULL => most recently added page)
  • x X offset to put image at
  • y Y offset to put image at
  • display_width Displayed width of image
  • display_height Displayed height of image
  • image_filename Filename of image file to display

Returns:

    bbolean false on failure, true on success
add_bookmark (page, parent, name)
Add a bookmark to the document

Parameters:

  • page Page to jump to for bookmark (or NULL for the most recently added page)
  • parent ID of a previously created bookmark that is the parent of this one. -1 if this should be a top-level bookmark.
  • name String to associate with the bookmark

Returns:

    false on failure, new bookmark id on success
add_link (page, x, y, width, height, target_page, target_x, target_y)
Add a link annotation to the document

Parameters:

  • page Page that holds the clickable rectangle (or NULL for the most recently added page)
  • x X coordinate of bottom LHS corner of clickable rectangle
  • y Y coordinate of bottom LHS corner of clickable rectangle
  • width width of clickable rectangle
  • height height of clickable rectangle
  • target_page Page to jump to for link
  • target_x X coordinate to position at the left of the view
  • target_y Y coordinate to position at the top of the view

Returns:

    boolean false on failure, new bookmark id on success
get_page (page_number)
Retrieve a page by its number.

Parameters:

  • page_number Page number to retrieve, starting from 1.

Returns:

    Page object if the given page is found, NULL otherwise
page_set_size (page, width, height)
Adjust the width/height of a specific page

Parameters:

  • page object returned from @ref pdfappendpage
  • width Width of the page in points
  • height Height of the page in points

Returns:

    boolean false on failure, true on success
add_text_wrap (page, text, size, xoff, yoff, angle, colour, wrap_width, align)
Add a text string to the document, making it wrap if it is too long

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • text String to display
  • size Point size of the font
  • xoff X location to put it in
  • yoff Y location to put it in
  • angle Rotation angle of text (in radians)
  • colour Colour to draw the text
  • wrap_width Width at which to wrap the text
  • align Text alignment (see PDFALIGNxxx)

Returns:

    mixed false on failure, the final height on success
add_text_rotate (page, text, size, xoff, yoff, angle, colour)
Add a text string to the document at a rotated angle

Parameters:

  • page Page to add object to (NULL => most recently added page)
  • text String to display
  • size Point size of the font
  • xoff X location to put it in
  • yoff Y location to put it in
  • angle Rotation angle of text (in radians)
  • colour Colour to draw the text

Returns:

    boolean true on success, false on failure
save (filename)
Save the given pdf document to the supplied filename.

Parameters:

  • filename Name of the file to store the PDF into (NULL for stdout)

Returns:

    boolean false on failure, true on success
height ()
Retrieves a PDF document height

Returns:

    number height of PDF document (in points)
width ()
Retrieves a PDF document width

Returns:

    number width of PDF document (in points)
page_height (page)
Retrieves page height

Parameters:

  • page Page object to get height of

Returns:

    number height of page (in points)
page_width (page)
Retrieves page width

Parameters:

  • page Page object to get width of

Returns:

    number width of page (in points)
add_barcode (page, code, x, y, width, height, string, colour)
Add a barcode to the document

Parameters:

  • page Page to add barcode to (NULL => most recently added page)
  • code Type of barcode to add (PDFBARCODExxx)
  • x X offset to put barcode at
  • y Y offset to put barcode at
  • width Width of barcode
  • height Height of barcode
  • string Barcode contents
  • colour Colour to draw barcode

Returns:

    false on failure, true on success
get_err (errval)
Retrieve the error message if any operation fails

Parameters:

  • errval optional pointer to an integer to be set to the error code

Returns:

    mixed NULL if no error message, string description of error otherwise
mm_to_point (mm)
Convert a value in milli-meters into a number of points.

Parameters:

  • mm millimeter value to convert to points

Returns:

    number
inch_to_point (inch)
Convert a value in inches into a number of points.

Parameters:

  • inch inches value to convert to points

Returns:

    number
rgb ()
Convert three 8-bit RGB values into a single packed 32-bit colour. These 32-bit colours are used by various functions in PDFGen
argb ()
Convert four 8-bit ARGB values into a single packed 32-bit colour. These 32-bit colours are used by various functions in PDFGen. Alpha values range from 0 (opaque) to 0xff (transparent)
clear_err ()
Acknowledge an outstanding pdf error
destroy ()
Destroy the pdf object, and all of its associated memory
generated by LDoc 1.5.0 Last updated 2023-11-02 17:11:05