๐งพ Invoice
Create a professional invoice with company details, line items, and payment QR code.
Invoice Example
Complete invoice with header, items table, totals, and payment QR code
fun generateInvoice(context: Context, invoice: Invoice): Result<File> {
val outputFile = File(context.cacheDir, "invoice_${invoice.number}.pdf")
return pdf {
pageSize(PageSize.A4)
margins(PageMargins.NORMAL)
// Header
header(
left = "INVOICE",
right = invoice.date,
showPageNumber = false
)
footer(
center = "Thank you for your business!",
showPageNumber = true
)
// Company Logo & Info
title("ACME Corporation", align = TextAlign.CENTER)
text("123 Business Street, City, Country", size = 10f, align = TextAlign.CENTER)
text("Phone: +1 234 567 890 | Email: billing@acme.com", size = 10f, align = TextAlign.CENTER)
spacer(30f)
divider()
spacer(20f)
// Invoice Details
text("Invoice #: ${invoice.number}", size = 14f, typeface = Typeface.DEFAULT_BOLD)
text("Date: ${invoice.date}")
text("Due Date: ${invoice.dueDate}")
spacer(20f)
// Bill To
heading("Bill To:")
text(invoice.customerName)
text(invoice.customerAddress)
text(invoice.customerEmail)
spacer(30f)
// Items Table
table {
header("Description", "Qty", "Unit Price", "Amount")
invoice.items.forEach { item ->
row(
item.description,
item.quantity.toString(),
"$${item.unitPrice}",
"$${item.quantity * item.unitPrice}"
)
}
}
spacer(20f)
// Totals
text("Subtotal: $${invoice.subtotal}", align = TextAlign.RIGHT)
text("Tax (10%): $${invoice.tax}", align = TextAlign.RIGHT)
divider()
text("Total: $${invoice.total}", size = 18f, typeface = Typeface.DEFAULT_BOLD, align = TextAlign.RIGHT)
spacer(40f)
// Payment QR Code
text("Scan to Pay:", align = TextAlign.CENTER)
qrCode("https://pay.acme.com/invoice/${invoice.number}", size = 120f)
spacer(20f)
// Payment Info Box
infoBox(
TextElement("Payment Information", typeface = Typeface.DEFAULT_BOLD),
TextElement("Bank: First National Bank"),
TextElement("Account: 1234567890"),
TextElement("Reference: ${invoice.number}")
)
}.saveToFile(outputFile)
}
// Usage
data class Invoice(
val number: String,
val date: String,
val dueDate: String,
val customerName: String,
val customerAddress: String,
val customerEmail: String,
val items: List<InvoiceItem>,
val subtotal: Double,
val tax: Double,
val total: Double
)
data class InvoiceItem(
val description: String,
val quantity: Int,
val unitPrice: Double
)
๐ Report
Generate a business report with sections, charts data, and summaries.
Monthly Report Example
Structured report with multiple sections and data tables
fun generateMonthlyReport(context: Context): Result<File> {
val outputFile = File(context.cacheDir, "monthly_report.pdf")
return pdf {
pageSize(PageSize.A4)
margins(PageMargins.NORMAL)
// Watermark
confidentialWatermark()
// Header/Footer
header(
left = "Monthly Sales Report",
right = "January 2026"
)
footer(showPageNumber = true)
// Title Page
spacer(100f)
title("Monthly Sales Report", size = 32f, align = TextAlign.CENTER)
spacer(20f)
text("January 2026", size = 18f, align = TextAlign.CENTER)
spacer(40f)
text("Prepared by: Sales Department", align = TextAlign.CENTER)
text("Date: January 31, 2026", align = TextAlign.CENTER)
pageBreak()
// Executive Summary
title("Executive Summary")
spacer(16f)
successBox(
TextElement("Key Highlights", typeface = Typeface.DEFAULT_BOLD),
TextElement("โข Total Revenue: $1,234,567 (+15% vs last month)"),
TextElement("โข New Customers: 234 (+20% vs last month)"),
TextElement("โข Customer Retention: 95%")
)
spacer(20f)
text("""
This month showed exceptional growth across all key metrics.
Our new marketing campaigns drove significant customer acquisition,
while our retention programs maintained high loyalty rates.
""".trimIndent())
spacer(30f)
// Sales by Region
heading("Sales by Region")
spacer(16f)
table {
header("Region", "Revenue", "Growth", "% of Total")
row("North America", "$450,000", "+12%", "36%")
row("Europe", "$380,000", "+18%", "31%")
row("Asia Pacific", "$280,000", "+22%", "23%")
row("Other", "$124,567", "+8%", "10%")
}
spacer(30f)
// Top Products
heading("Top Performing Products")
spacer(16f)
numberedList(
"Product A - $320,000 (26% of revenue)",
"Product B - $280,000 (23% of revenue)",
"Product C - $195,000 (16% of revenue)",
"Product D - $150,000 (12% of revenue)",
"Other Products - $289,567 (23% of revenue)"
)
pageBreak()
// Customer Metrics
title("Customer Metrics")
spacer(16f)
table {
header("Metric", "This Month", "Last Month", "Change")
row("New Customers", "234", "195", "+20%")
row("Churned Customers", "12", "15", "-20%")
row("Net New", "222", "180", "+23%")
row("Total Active", "4,567", "4,345", "+5%")
}
spacer(30f)
// Recommendations
heading("Recommendations")
spacer(16f)
warningBox(
TextElement("Action Items", typeface = Typeface.DEFAULT_BOLD),
TextElement("1. Increase marketing budget for APAC region"),
TextElement("2. Launch customer loyalty program Q2"),
TextElement("3. Expand Product A distribution channels")
)
spacer(30f)
// Signature
divider()
spacer(20f)
text("Approved by:", size = 10f)
spacer(30f)
text("_______________________")
text("Sales Director", size = 10f)
}.saveToFile(outputFile)
}
๐งพ Receipt
Create a compact receipt suitable for printing or digital delivery.
Receipt Example
Compact receipt with items, totals, and transaction QR code
fun generateReceipt(context: Context, order: Order): Result<File> {
val outputFile = File(context.cacheDir, "receipt_${order.id}.pdf")
return pdf {
// Narrow page for receipt
pageSizeMm(80f, 200f)
margins(10f, 10f, 10f, 10f)
// Store Header
title("COFFEE SHOP", size = 18f, align = TextAlign.CENTER)
text("123 Main Street", size = 9f, align = TextAlign.CENTER)
text("Tel: 555-0123", size = 9f, align = TextAlign.CENTER)
spacer(10f)
dashedDivider()
spacer(10f)
// Order Info
text("Order #${order.id}", size = 10f)
text("Date: ${order.date}", size = 9f)
text("Server: ${order.server}", size = 9f)
spacer(10f)
dashedDivider()
spacer(10f)
// Items
order.items.forEach { item ->
text("${item.quantity}x ${item.name}", size = 10f)
text(" $${item.price}", size = 9f, align = TextAlign.RIGHT)
}
spacer(10f)
dashedDivider()
spacer(10f)
// Totals
text("Subtotal: $${order.subtotal}", size = 10f, align = TextAlign.RIGHT)
text("Tax: $${order.tax}", size = 10f, align = TextAlign.RIGHT)
spacer(5f)
text("TOTAL: $${order.total}", size = 14f, typeface = Typeface.DEFAULT_BOLD, align = TextAlign.RIGHT)
spacer(10f)
text("Paid: ${order.paymentMethod}", size = 10f)
spacer(15f)
dashedDivider()
spacer(15f)
// QR Code for digital receipt
text("Scan for digital receipt:", size = 8f, align = TextAlign.CENTER)
qrCode("https://shop.com/receipt/${order.id}", size = 60f)
spacer(10f)
text("Thank you!", size = 12f, align = TextAlign.CENTER)
text("Visit again soon!", size = 9f, align = TextAlign.CENTER)
}.saveToFile(outputFile)
}
๐ Certificate
Create an elegant certificate of completion or achievement.
Certificate Example
Formal certificate with decorative elements
fun generateCertificate(
context: Context,
recipientName: String,
courseName: String,
completionDate: String,
certificateId: String
): Result<File> {
val outputFile = File(context.cacheDir, "certificate_$certificateId.pdf")
return pdf {
pageSize(PageSize.A4)
orientation(PageOrientation.LANDSCAPE)
margins(PageMargins.WIDE)
backgroundColor(0xFFFFFDF5.toInt())
spacer(40f)
// Header
text("CERTIFICATE", size = 14f, align = TextAlign.CENTER, color = 0xFF666666.toInt())
spacer(10f)
title("OF COMPLETION", size = 36f, align = TextAlign.CENTER)
spacer(30f)
text("This is to certify that", size = 14f, align = TextAlign.CENTER)
spacer(20f)
// Recipient Name
text(recipientName, size = 32f, align = TextAlign.CENTER, typeface = Typeface.create("serif", Typeface.BOLD_ITALIC))
spacer(10f)
divider(color = 0xFFCCCCCC.toInt())
spacer(20f)
text("has successfully completed the course", size = 14f, align = TextAlign.CENTER)
spacer(20f)
// Course Name
text(courseName, size = 24f, align = TextAlign.CENTER, typeface = Typeface.DEFAULT_BOLD)
spacer(30f)
text("Completed on $completionDate", size = 12f, align = TextAlign.CENTER)
spacer(50f)
// Signature Area
text("_______________________", align = TextAlign.CENTER)
text("Program Director", size = 10f, align = TextAlign.CENTER)
spacer(30f)
// Verification
text("Certificate ID: $certificateId", size = 9f, align = TextAlign.CENTER, color = 0xFF999999.toInt())
spacer(10f)
qrCode("https://verify.academy.com/cert/$certificateId", size = 80f)
text("Scan to verify", size = 8f, align = TextAlign.CENTER, color = 0xFF999999.toInt())
}.saveToFile(outputFile)
}
โ๏ธ Checklist Form
Create interactive checklist forms for inspections or tasks.
Inspection Checklist Example
Safety inspection form with checkboxes
fun generateInspectionChecklist(context: Context): Result<File> {
val outputFile = File(context.cacheDir, "inspection_checklist.pdf")
return pdf {
pageSize(PageSize.A4)
margins(PageMargins.NORMAL)
header(left = "Safety Inspection Checklist", showPageNumber = true)
title("Workplace Safety Inspection")
text("Date: ____________ Inspector: ____________")
text("Location: ____________ Department: ____________")
spacer(20f)
divider()
spacer(20f)
// Fire Safety Section
heading("๐ฅ Fire Safety")
spacer(10f)
checkboxList(
"Fire extinguishers are accessible and inspected",
"Emergency exits are clearly marked",
"Exit routes are clear and unobstructed",
"Fire alarm system tested and functional",
"Sprinkler system operational",
"Flammable materials properly stored"
)
spacer(20f)
// Electrical Safety
heading("โก Electrical Safety")
spacer(10f)
checkboxList(
"No exposed wiring or damaged cords",
"Electrical panels accessible",
"GFCI outlets in wet areas functional",
"No overloaded outlets or power strips",
"Equipment properly grounded"
)
spacer(20f)
// General Safety
heading("๐ก๏ธ General Safety")
spacer(10f)
checkboxList(
"First aid kit stocked and accessible",
"Safety signs visible and legible",
"Walkways clear of hazards",
"Proper lighting in all areas",
"PPE available and in good condition",
"Emergency contact information posted"
)
spacer(30f)
// Notes Section
heading("๐ Notes & Observations")
spacer(10f)
text("_".repeat(60))
spacer(15f)
text("_".repeat(60))
spacer(15f)
text("_".repeat(60))
spacer(15f)
text("_".repeat(60))
spacer(30f)
// Warning Box
warningBox(
TextElement("โ ๏ธ Important", typeface = Typeface.DEFAULT_BOLD),
TextElement("Any critical safety issues must be reported immediately to the Safety Officer.")
)
spacer(30f)
// Signature
divider()
spacer(20f)
text("Inspector Signature: ______________________ Date: ____________")
spacer(15f)
text("Supervisor Review: ______________________ Date: ____________")
}.saveToFile(outputFile)
}
๐ Contact Card
Generate a contact card with vCard QR code for easy sharing.
Contact Card Example
Digital business card with QR code
fun generateContactCard(
context: Context,
contact: ContactInfo
): Result<File> {
val outputFile = File(context.cacheDir, "contact_${contact.firstName}.pdf")
return pdf {
// Business card size
pageSizeMm(85f, 55f)
margins(5f, 5f, 5f, 5f)
// Name
text("${contact.firstName} ${contact.lastName}", size = 14f, typeface = Typeface.DEFAULT_BOLD)
text(contact.title, size = 10f, color = 0xFF666666.toInt())
spacer(8f)
text(contact.company, size = 11f)
spacer(8f)
// Contact Details
text("๐ง ${contact.email}", size = 8f)
text("๐ฑ ${contact.phone}", size = 8f)
contact.website?.let { text("๐ $it", size = 8f) }
spacer(10f)
// vCard QR Code
qrCodeVCard(
firstName = contact.firstName,
lastName = contact.lastName,
phone = contact.phone,
email = contact.email,
organization = contact.company,
size = 50f,
align = TextAlign.RIGHT
)
}.saveToFile(outputFile)
}
data class ContactInfo(
val firstName: String,
val lastName: String,
val title: String,
val company: String,
val email: String,
val phone: String,
val website: String? = null
)
๐ Multi-Page Document
Create documents with automatic pagination and page management.
Multi-Page Document Example
Document with table of contents and multiple sections
fun generateUserManual(context: Context): Result<File> {
val outputFile = File(context.cacheDir, "user_manual.pdf")
return pdf {
pageSize(PageSize.A4)
margins(PageMargins.NORMAL)
header(
left = "User Manual",
right = "Version 2.0"
)
footer(showPageNumber = true, pageNumberFormat = "Page {page} of {total}")
// Cover Page
spacer(150f)
title("Product User Manual", size = 36f, align = TextAlign.CENTER)
spacer(30f)
text("Version 2.0", size = 18f, align = TextAlign.CENTER)
text("Last Updated: January 2026", size = 14f, align = TextAlign.CENTER)
pageBreak()
// Table of Contents
title("Table of Contents")
spacer(20f)
text("1. Introduction .......................... 3")
text("2. Getting Started ...................... 4")
text("3. Features ............................. 6")
text("4. Troubleshooting ..................... 10")
text("5. FAQ ................................. 12")
pageBreak()
// Chapter 1
title("1. Introduction")
spacer(16f)
text("""
Welcome to the Product User Manual. This comprehensive guide will help you
understand all the features and capabilities of our product.
Our product is designed to simplify your daily tasks and improve productivity.
Whether you're a beginner or an advanced user, this manual will provide you
with all the information you need.
""".trimIndent())
spacer(20f)
infoBox(
TextElement("โน๏ธ Note", typeface = Typeface.DEFAULT_BOLD),
TextElement("Please read this manual carefully before using the product.")
)
spacer(20f)
heading("1.1 System Requirements")
spacer(10f)
bulletList(
"Android 7.0 (API 24) or higher",
"2GB RAM minimum",
"100MB free storage",
"Internet connection for sync features"
)
pageBreak()
// Chapter 2
title("2. Getting Started")
spacer(16f)
heading("2.1 Installation")
spacer(10f)
numberedList(
"Download the app from Google Play Store",
"Open the app and accept permissions",
"Create an account or sign in",
"Complete the setup wizard",
"Start using the app!"
)
spacer(20f)
heading("2.2 Initial Configuration")
spacer(10f)
table {
header("Setting", "Default", "Recommended")
row("Theme", "System", "Your preference")
row("Notifications", "Enabled", "Enabled")
row("Auto-sync", "Off", "On")
row("Language", "English", "Your language")
}
// Continue with more chapters...
pageBreak()
// Chapter 3
title("3. Features")
spacer(16f)
text("""
This chapter covers all the main features of the product.
Each feature is designed to enhance your experience and productivity.
""".trimIndent())
spacer(20f)
heading("3.1 Core Features")
spacer(10f)
bulletList(
"Feature A - Streamline your workflow",
"Feature B - Collaborate with team members",
"Feature C - Generate reports automatically",
"Feature D - Secure data encryption"
)
spacer(20f)
successBox(
TextElement("โ
Pro Tip", typeface = Typeface.DEFAULT_BOLD),
TextElement("Use keyboard shortcuts to speed up your work. Press Ctrl+? to see all available shortcuts.")
)
}.saveToFile(outputFile)
}