Skip to content

PaperForge v0.1.0 — Initial PDF Core and Graphics

Choose a tag to compare

@Manuel1471 Manuel1471 released this 26 Jul 19:18

PaperForge v0.1.0 — Initial PDF Core and Graphics

PaperForge v0.1.0 is the first public release of the project.

This version introduces the initial pure Elixir PDF generation engine, capable of building valid multi-page PDF documents directly without browsers, external binaries, or rendering services.

Highlights

  • Pure Elixir PDF generation
  • Multi-page document support
  • PDF object graph with indirect objects and references
  • PDF primitive serialization
  • Streams with automatic byte-length calculation
  • Traditional cross-reference table generation
  • PDF trailer and startxref generation
  • Built-in Helvetica text
  • Text positioning, font size, and color
  • Lines with configurable width and color
  • Rectangles with fill and stroke support
  • Circles rendered with cubic Bézier curves
  • RGB and grayscale colors
  • A3, A4, A5, Letter, Legal, and custom page sizes
  • Portrait and landscape orientations
  • Basic PDF metadata
  • Binary and file output APIs
  • Automated tests and GitHub Actions CI

Example

alias PaperForge.Color
alias PaperForge.Page

document =
  PaperForge.new()
  |> PaperForge.metadata(
    title: "PaperForge Example",
    author: "Manuel Garcia"
  )
  |> PaperForge.add_page(fn page ->
    page
    |> Page.text(
      "Hello from PaperForge",
      x: 72,
      y: 760,
      size: 28,
      color: Color.rgb255(35, 60, 120)
    )
    |> Page.rectangle(
      x: 72,
      y: 580,
      width: 220,
      height: 110,
      fill: true,
      stroke: true,
      fill_color: Color.rgb255(235, 240, 250),
      stroke_color: Color.rgb255(35, 60, 120)
    )
  end)

PaperForge.write!(document, "example.pdf")

Included in this release

PDF core

  • Serialization of PDF primitive values
  • Indirect object representation
  • Object references such as 3 0 R
  • Stream objects with automatic /Length
  • Document catalog generation
  • Page tree generation
  • Cross-reference table generation
  • Trailer and EOF generation
  • Binary PDF output

Pages

  • Multiple pages
  • A3
  • A4
  • A5
  • Letter
  • Legal
  • Custom page dimensions
  • Portrait orientation
  • Landscape orientation

Graphics

  • Text
  • Lines
  • Rectangles
  • Circles
  • Fill colors
  • Stroke colors
  • Configurable line width
  • RGB colors
  • RGB 0–255 helper
  • Grayscale colors

Metadata

  • Title
  • Author
  • Subject
  • Keywords
  • Creator
  • Producer

Current limitations

This is an early release and the public API may change before 1.0.0.

The following features are not yet included:

  • Text measurement and alignment
  • Automatic line wrapping
  • Embedded TrueType or OpenType fonts
  • Full Unicode support
  • Images
  • Stream compression
  • Paragraph layout
  • Automatic page breaks
  • Tables
  • HTML and CSS rendering
  • Existing PDF parsing or editing

Technical notes

PaperForge currently:

  • Uses traditional cross-reference tables
  • Uses generation 0 for newly created indirect objects
  • Uses the native PDF coordinate system
  • Uses the bottom-left corner as the page origin
  • Uses iodata internally to reduce unnecessary binary concatenation
  • Isolates drawing operations with the PDF q and Q graphics-state operators
  • Uses Helvetica with WinAnsiEncoding as the default font
  • Approximates circles using four cubic Bézier curves

Next steps

Planned improvements for future releases include:

  • Text measurement
  • Horizontal text alignment
  • Automatic line wrapping
  • Additional built-in PDF fonts
  • JPEG image support
  • Stream compression with FlateDecode
  • Top-left coordinate helpers
  • Page margins
  • Paragraph layout
  • Automatic page breaks

PaperForge is still experimental, but v0.1.0 establishes the foundational PDF object, graphics, serialization, and writing layers for future development.