PDF::Document
Represents a PDF document.
A PDF document consists of a collection of objects that describe the structure and content of the document. The main components are:
- Catalog: The root of the document's object hierarchy
- Pages tree: A tree structure containing all pages
- Resources: Fonts, images, and other shared resources
Basic Usage
pdf = PDF::Document.new
pdf.page do |page|
page.font "Helvetica", size: 12
page.text "Hello, World!", at: {72, 720}
end
pdf.save("output.pdf")
Constants
PAGE_SIZES = {
letter: {612, 792},
a4: {595, 842},
legal: {612, 1008},
tabloid: {792, 1224},
a3: {842, 1191},
a5: {420, 595},
executive: {522, 756},
}
Default page size constants (in points, 72 points = 1 inch)
Constructors
new
SourceInstance methods
author
Sourcecreator
Sourcefinalize!
Finalizes all pages and objects for writing. Called by the writer before serialization.
keywords
SourceLoads a TrueType font from a file path.
The font will be automatically subsetted to include only the glyphs used in the document.
my_font = pdf.load_font("./fonts/OpenSans-Regular.ttf")
pdf.page do |page|
page.font my_font, size: 12
page.text "Hello!", at: {72, 720}
end
Loads a TrueType font from bytes.
Creates a new page and yields it for content.
pdf.page do |page|
page.text "Hello!", at: {72, 720}
end
Creates a new page with a named size.
pdf.page(size: :a4) do |page|
page.text "A4 page", at: {72, 800}
end
producer
Sourceregister_object(value : Objects::Base) : Objects::Indirect
Registers an indirect object and returns it.
subject
Source