đ Page Configuration
Configure your PDF pages with various sizes, orientations, and margins.
Page Sizes
PDF Generator supports multiple standard page sizes:
| Size | Dimensions (mm) | Usage |
|---|---|---|
PageSize.A3 |
297 Ã 420 | Large documents, posters |
PageSize.A4 |
210 Ã 297 | Standard documents (default) |
PageSize.A5 |
148 Ã 210 | Booklets, flyers |
PageSize.A6 |
105 Ã 148 | Postcards, small notes |
PageSize.LETTER |
216 Ã 279 | US standard |
PageSize.LEGAL |
216 Ã 356 | Legal documents (US) |
pdf {
// Standard page size
pageSize(PageSize.A4)
// Custom page size in millimeters
pageSizeMm(200f, 300f)
// Custom page size in inches
pageSizeInches(8.5f, 11f)
// Page orientation
orientation(PageOrientation.PORTRAIT) // or LANDSCAPE
// Page margins
margins(PageMargins.NORMAL) // Preset
margins(72f, 72f, 72f, 72f) // Custom (top, bottom, left, right)
marginsMm(25f, 25f, 20f, 20f) // In millimeters
// Background color
backgroundColor(0xFFF5F5F5.toInt())
}
Margin Presets
| Preset | Values (points) |
|---|---|
PageMargins.NONE |
0 on all sides |
PageMargins.NARROW |
36 (0.5 inch) |
PageMargins.NORMAL |
72 (1 inch) |
PageMargins.WIDE |
108 (1.5 inches) |
đ Text Content
Add various text elements with full styling control.
pdf {
// Title - large, bold text
title("Document Title", size = 24f, align = TextAlign.CENTER)
// Heading - medium, bold text
heading("Section Heading", size = 18f)
// Subheading - smaller heading
subheading("Subsection", size = 14f)
// Regular text with full customization
text(
content = "This is a paragraph of text.",
size = 12f,
color = 0xFF333333.toInt(),
typeface = Typeface.DEFAULT,
align = TextAlign.LEFT // LEFT, CENTER, RIGHT
)
// Bold text
text("Important text", typeface = Typeface.DEFAULT_BOLD)
// Italic text
text("Emphasized text", typeface = Typeface.create(Typeface.DEFAULT, Typeface.ITALIC))
}
Text Alignment
TextAlign.LEFT- Left-aligned (default)TextAlign.CENTER- CenteredTextAlign.RIGHT- Right-aligned
đ Tables
Create tables with headers, styled cells, and automatic page splitting.
pdf {
// Simple table
table {
header("Name", "Email", "Role")
row("John Doe", "john@example.com", "Developer")
row("Jane Smith", "jane@example.com", "Designer")
row("Bob Wilson", "bob@example.com", "Manager")
}
// Table with styled cells
table {
headerCells(
TableCell("Product", backgroundColor = 0xFF1E40AF.toInt(), textColor = 0xFFFFFFFF.toInt()),
TableCell("Price", backgroundColor = 0xFF1E40AF.toInt(), textColor = 0xFFFFFFFF.toInt()),
TableCell("Qty", backgroundColor = 0xFF1E40AF.toInt(), textColor = 0xFFFFFFFF.toInt())
)
row(listOf(
TableCell("Widget A"),
TableCell("$29.99", alignment = TextAlign.RIGHT),
TableCell("10", alignment = TextAlign.CENTER)
))
}
}
Large tables automatically split across pages, with headers repeating on each page for better readability.
đ Lists
Add bullet lists and numbered lists that automatically continue across pages.
pdf {
// Bullet list
bulletList(
"First item",
"Second item",
"Third item with longer text that will wrap properly",
"Fourth item"
)
// Numbered list
numberedList(
"Step one: Prepare materials",
"Step two: Follow instructions",
"Step three: Complete the process",
"Step four: Review results"
)
}
đŧī¸ Images
Add images with flexible sizing and alignment options.
pdf {
// Add image from bitmap
val bitmap = BitmapFactory.decodeResource(resources, R.drawable.logo)
// Full width image
image(bitmap)
// Custom size
image(bitmap, width = 200f, height = 100f)
// Maintain aspect ratio with max width
image(bitmap, width = 300f) // Height calculated automatically
// Centered image
image(bitmap, width = 200f, align = TextAlign.CENTER)
// Right-aligned image
image(bitmap, width = 150f, align = TextAlign.RIGHT)
}
đą QR Codes
Generate various types of QR codes directly in your PDF.
pdf {
// Basic QR code
qrCode("https://example.com", size = 150f)
// URL QR code
qrCodeUrl("https://github.com/Alims-Repo/Pdf-Generator")
// Email QR code
qrCodeEmail(
email = "contact@example.com",
subject = "Hello",
body = "I'd like to inquire about..."
)
// Phone QR code
qrCodePhone("+1234567890")
// SMS QR code
qrCodeSms(
phone = "+1234567890",
message = "Hello from PDF Generator!"
)
// WiFi QR code
qrCodeWifi(
ssid = "MyNetwork",
password = "secretpassword"
)
// vCard QR code (Contact)
qrCodeVCard(
firstName = "John",
lastName = "Doe",
phone = "+1234567890",
email = "john.doe@example.com",
organization = "ACME Corp"
)
// Location QR code
qrCodeLocation(
latitude = 40.7128,
longitude = -74.0060
)
}
QR Code Types
| Method | Description |
|---|---|
qrCode() |
Generic QR code with any data |
qrCodeUrl() |
Opens a URL when scanned |
qrCodeEmail() |
Opens email composer |
qrCodePhone() |
Initiates phone call |
qrCodeSms() |
Opens SMS with pre-filled message |
qrCodeWifi() |
Connects to WiFi network |
qrCodeVCard() |
Adds contact to address book |
qrCodeLocation() |
Opens location in maps |
âī¸ Checkboxes
Perfect for forms, checklists, and surveys.
pdf {
heading("Checklist")
// Single checkbox
checkbox("I agree to the terms", isChecked = false)
checkbox("Subscribe to newsletter", isChecked = true)
// Checkbox list from strings
checkboxList(
"Task 1: Complete documentation",
"Task 2: Write tests",
"Task 3: Deploy to production"
)
// Checkbox list with pre-checked items
checkboxList(listOf(
CheckboxItem("Completed task", isChecked = true),
CheckboxItem("Pending task", isChecked = false),
CheckboxItem("Another completed task", isChecked = true)
))
}
đĻ Box Elements
Highlight content with styled boxes for different purposes.
pdf {
// Info box (blue)
infoBox(
TextElement("âšī¸ Information", textSize = 14f, typeface = Typeface.DEFAULT_BOLD),
TextElement("This is an informational message.")
)
// Warning box (yellow/orange)
warningBox(
TextElement("â ī¸ Warning", textSize = 14f, typeface = Typeface.DEFAULT_BOLD),
TextElement("Please review carefully before proceeding.")
)
// Error box (red)
errorBox(
TextElement("â Error", textSize = 14f, typeface = Typeface.DEFAULT_BOLD),
TextElement("An error occurred during processing.")
)
// Success box (green)
successBox(
TextElement("â
Success", textSize = 14f, typeface = Typeface.DEFAULT_BOLD),
TextElement("Operation completed successfully!")
)
// Custom box
box(
elements = listOf(
TextElement("Custom Box", textSize = 16f),
TextElement("With custom styling")
),
padding = 16f,
backgroundColor = 0xFFE0E7FF.toInt()
)
}
đ Headers & Footers
Add customizable headers and footers with automatic page numbering.
pdf {
// Header with page numbers
header(
left = "Company Name",
center = "Document Title",
right = null,
showPageNumber = true,
pageNumberFormat = "Page {page} of {total}"
)
// Footer
footer(
left = "Confidential",
center = null,
right = "Š 2026 Company",
showPageNumber = true
)
// Content...
title("Report")
text("Document content goes here...")
}
Page Number Formats
Use placeholders in your format string:
{page}- Current page number{total}- Total number of pages
đ§ Watermarks
Add text watermarks with rotation and transparency.
pdf {
// Custom text watermark
textWatermark(
text = "CONFIDENTIAL",
textSize = 48f,
textColor = 0x33000000, // Semi-transparent black
rotation = -45f
)
// Preset watermarks
draftWatermark() // "DRAFT" watermark
confidentialWatermark() // "CONFIDENTIAL" watermark
// Advanced watermark
watermark(Watermark(
text = "SAMPLE",
textSize = 60f,
textColor = 0x20FF0000, // Semi-transparent red
rotation = -30f,
position = WatermarkPosition.CENTER
))
// Content...
title("Document")
}
đ Layout & Spacing
Control spacing and visual separation in your document.
pdf {
title("Section 1")
text("Content...")
// Add vertical space
spacer(30f) // 30 points of space
// Solid divider line
divider(thickness = 1f, color = 0xFF000000.toInt())
spacer(30f)
title("Section 2")
text("More content...")
// Dashed divider line
dashedDivider(thickness = 1f, color = 0xFF666666.toInt())
spacer(20f)
// Force a page break
pageBreak()
title("Section 3 (New Page)")
}
Layout Elements
| Element | Description |
|---|---|
spacer(height) |
Add vertical space in points |
divider() |
Solid horizontal line |
dashedDivider() |
Dashed horizontal line |
pageBreak() |
Force content to next page |