Documentation
¶
Overview ¶
Package gopdfkit is a small facade over GoPDFKit's PDF generation API.
GoPDFKit generates PDFs directly from Go code. The root package exposes the default constructor and public aliases. Import github.com/cssbruno/gopdfkit/document for the full API.
Quick Start ¶
pdf := gopdfkit.New()
pdf.AddPage()
pdf.SetFont("Helvetica", "B", 16)
pdf.Cell(40, 10, "Hello, world")
err := pdf.OutputFileAndClose("hello.pdf")
Use document.NewWithOptions when generation defaults should be configured at construction time:
pdf := document.NewWithOptions(document.Options{
OrientationStr: "P",
UnitStr: "mm",
SizeStr: "A4",
Optimize: true,
})
Optimize selects best zlib compression for generated page and template streams. It is not a full PDF optimizer for images, fonts, object streams, or arbitrary existing PDFs.
Current Capabilities ¶
The document package supports page generation, text, cells, multicells, tables, headers, footers, drawing primitives, clipping, transforms, transparency, gradients, spot colors, layers, templates, imported PDF pages, images, SVG, WebP, controlled HTML fragments, thumbnails, attachments, metadata, XMP metadata, JavaScript actions, password protection, PDF signing, and signature verification through CMS SignedData. The inspect package provides lightweight PDF structure, stream, page, and literal text inspection helpers.
Imported-page examples cover merge, split, reorder, rotate, 4-up layout, template overlay, and watermark overlay by creating a new PDF from imported pages.
Current Limits ¶
GoPDFKit does not implement full browser HTML/CSS layout, JavaScript page rendering, DOCX conversion, interactive AcroForm field creation, filling or flattening existing interactive forms, FDF merging, unlocking/decrypting existing password-protected PDFs, OCR, arbitrary PDF content rewriting, or general-purpose semantic text extraction from every possible PDF encoding.
Imported page support is intentionally narrow: classic xref-table PDFs, unencrypted documents, and pages whose content streams are unfiltered or FlateDecode-compressed. PDFs that use xref streams or object streams are reported as unsupported.
Packages ¶
The main packages are:
- gopdfkit: root facade with the default constructor and public aliases.
- document: main PDF generation API.
- font: font parsing and JSON font definition generation.
- importpdf: small wrappers around imported-page APIs.
- inspect: lightweight PDF structure, stream, page, and text inspection.
- sign: CMS-first PDF signing and signature verification.
- sign/pkcs7: legacy PKCS #7 terminology wrappers around CMS APIs.
Examples ¶
Runnable examples live under examples/ and write PDFs under assets/generated/pdf/examples. Focused examples include reports, table reports, invoices, styled paragraphs, HTML/CSS styling, manual pagination, document-model pagination, images, compression, watermarks, merge/split/ reorder/rotate page workflows, 4-up pages, template overlays, static form documents, password protection, templates, thumbnails, UTF-8 fonts, and signing.
HTML Support ¶
HTMLNew renders a controlled subset of HTML fragments into PDF drawing operations. It is useful for rich text, generated sections, reports, letters, and static forms. Supported CSS maps to PDF operations for text, colors, spacing, borders, border radius, backgrounds, simple box shadows, line height, page breaks, and table layout. It is not a browser engine.
Use document.RenderHTMLTemplate for simple {{key}} substitution before rendering HTML. Plain values are escaped, HTMLTemplateRaw inserts trusted HTML, and HTMLTemplateImage inserts an img tag that can be sized and spaced with supported HTML/CSS.
See doc/pdf-html-subset.md for the full renderer contract.
Errors ¶
Most Document methods record errors on the document instead of returning errors directly. Once an error is set, later methods usually return without changing the PDF. Check Ok, Err, or Error after generation, especially before trusting output.
Background ¶
GoPDFKit is derived from the original FPDF PHP library and keeps many FPDF-style method names for compatibility and familiarity. Internally, this Go version uses buffers, io.Writer/io.WriteCloser output, and JSON font definition files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
Document is the high-level PDF document API exposed by the document package.
func NewWithOptions ¶
NewWithOptions returns a new PDF document using explicit construction options.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
compliance-check
command
Command compliance-check performs local structural checks for generated compliance fixtures.
|
Command compliance-check performs local structural checks for generated compliance fixtures. |
|
compliance-fixtures
command
Command compliance-fixtures generates candidate PDFs for external standards validators.
|
Command compliance-fixtures generates candidate PDFs for external standards validators. |
|
fontmaker
command
Command fontmaker generates JSON font definition files for GoPDFKit.
|
Command fontmaker generates JSON font definition files for GoPDFKit. |
|
list
command
Command list prints Markdown links for generated reference PDFs.
|
Command list prints Markdown links for generated reference PDFs. |
|
Package document contains the high-level PDF document implementation.
|
Package document contains the high-level PDF document implementation. |
|
examples
|
|
|
add-images-to-pages
command
|
|
|
compress-optimize-pdf
command
|
|
|
drawing
command
|
|
|
form-creation
command
|
|
|
four-up-pages
command
|
|
|
headers-footers
command
|
|
|
hello-world
command
|
|
|
html-css-styles
command
|
|
|
html-fragment
command
|
|
|
html-images
command
|
|
|
html-tables
command
|
|
|
html-template
command
|
|
|
image-from-memory
command
|
|
|
import-page
command
|
|
|
internal/assets
Package assets resolves repository fixture files for examples.
|
Package assets resolves repository fixture files for examples. |
|
internal/outpath
Package outpath resolves generated PDF output paths for examples.
|
Package outpath resolves generated PDF output paths for examples. |
|
internal/samplepdf
Package samplepdf builds small in-memory PDFs used by page-processing examples.
|
Package samplepdf builds small in-memory PDFs used by page-processing examples. |
|
invoice
command
|
|
|
merge-pdf-pages
command
|
|
|
pagination-document
command
|
|
|
pagination-table
command
|
|
|
protect-pdf
command
|
|
|
protection-attachments
command
|
|
|
rendering-gallery
command
|
|
|
report
command
|
|
|
rotate-pages
command
|
|
|
sign-pdf
command
|
|
|
split-reorder-pages
command
|
|
|
structured-report
command
|
|
|
styled-paragraphs
command
|
|
|
table-report
command
|
|
|
template-overlay
command
|
|
|
templates
command
|
|
|
thumbnail
command
|
|
|
utf8-font
command
|
|
|
watermark-pdf
command
|
|
|
Package font provides font parsing, metrics, and font definition generation APIs.
|
Package font provides font parsing, metrics, and font definition generation APIs. |
|
Package importpdf provides helpers for importing pages from existing PDFs.
|
Package importpdf provides helpers for importing pages from existing PDFs. |
|
Package inspect provides lightweight PDF inspection helpers.
|
Package inspect provides lightweight PDF inspection helpers. |
|
internal
|
|
|
testpdf
Package testpdf provides internal deterministic PDF test helpers.
|
Package testpdf provides internal deterministic PDF test helpers. |
|
testsupport/example
Package example provides internal helpers for deterministic example PDF generation.
|
Package example provides internal helpers for deterministic example PDF generation. |
|
This file signs and verifies PDF CMS signatures.
|
This file signs and verifies PDF CMS signatures. |
|
pkcs7
Package pkcs7 keeps legacy PKCS #7 terminology separate from the CMS-first signing API in package sign.
|
Package pkcs7 keeps legacy PKCS #7 terminology separate from the CMS-first signing API in package sign. |
