The glu.pdf module
The glu.pdf module provides low-level access to PDF generation using the baseline-pdf library. It allows direct control over PDF objects, streams, fonts, and images.
For most use cases, the glu.frontend module is recommended. The glu.pdf module is useful when you need fine-grained control over the PDF output.
Module functions
| Name |
Parameters |
Returns |
Description |
pdf.new() |
filename (string) |
PDFWriter |
Create a new PDF writer |
PDFWriter
Attributes
| Name |
R/W |
Type |
Description |
default_page_width |
R/W |
number |
Default width for new pages (points) |
default_page_height |
R/W |
number |
Default height for new pages (points) |
default_offset_x |
R/W |
number |
Default horizontal offset |
default_offset_y |
R/W |
number |
Default vertical offset |
size |
R |
number |
Size of the PDF document in bytes |
Methods
| Name |
Parameters |
Returns |
Description |
new_object() |
- |
Object |
Create a new PDF object |
add_page() |
stream |
Page |
Add a page with the given stream |
load_face() |
filename, [index] |
Face |
Load a font face |
load_image() |
filename, [page], [box] |
Image |
Load an image file |
finish() |
- |
- |
Finalize and write the PDF |
Example:
Object
PDF objects represent the building blocks of a PDF file.
Attributes
| Name |
R/W |
Type |
Description |
object_number |
R |
number |
The PDF object number |
force_stream |
R/W |
boolean |
Always write as stream object |
dict |
R/W |
table |
Dictionary entries |
array |
R/W |
table |
Array data |
Methods
| Name |
Parameters |
Returns |
Description |
write() |
string |
- |
Write data to the object stream |
save() |
- |
- |
Save the object to the PDF |
set_compression() |
level |
- |
Set compression level (0-9) |
Example:
Page
Attributes
| Name |
R/W |
Type |
Description |
width |
R/W |
number |
Page width in points |
height |
R/W |
number |
Page height in points |
offset_x |
R/W |
number |
Horizontal offset |
offset_y |
R/W |
number |
Vertical offset |
object_number |
R/W |
number |
PDF object number |
faces |
R/W |
table |
List of Face objects used |
images |
R/W |
table |
List of Image objects used |
dict |
R/W |
table |
Additional dictionary entries |
Face
Font face objects for PDF text rendering.
Attributes
| Name |
R/W |
Type |
Description |
internal_name |
R |
string |
PDF internal font name |
postscript_name |
R |
string |
PostScript name of the font |
units_per_em |
R |
number |
Font units per em |
filename |
R |
string |
Path to the font file |
face_id |
R |
number |
Internal face ID |
Methods
| Name |
Parameters |
Returns |
Description |
codepoint() |
rune |
number |
Get codepoint for a character |
codepoints() |
runes (table) |
table |
Get codepoints for characters |
register_codepoint() |
codepoint |
- |
Register codepoint for subsetting |
register_codepoints() |
codepoints (table) |
- |
Register multiple codepoints |
Example:
Image
Attributes
| Name |
R/W |
Type |
Description |
internal_name |
R |
string |
PDF internal image name |
page_number |
R |
number |
Page number (for PDF images) |
Methods
| Name |
Parameters |
Returns |
Description |
close() |
- |
- |
Close and free memory |
get_pdf_box_dimensions() |
page, box |
table |
Get box dimensions |