Crate carbonpdf

Crate carbonpdf 

Source
Expand description

§CarbonPDF

Production-ready HTML to PDF conversion using Headless Chrome.

CarbonPDF provides a safe, ergonomic API for converting HTML content to PDF documents using Headless Chrome via the Chrome DevTools Protocol. It’s designed for backend services, CI/CD pipelines, and any application requiring high-quality PDF generation.

§Why Headless Chrome?

  • Accurate rendering: Chrome’s rendering engine ensures PDFs match web output exactly
  • Modern web standards: Full support for CSS3, JavaScript, web fonts, and flexbox/grid
  • Battle-tested: Leverages the same engine used by billions of users daily

§Architecture

CarbonPDF uses a layered architecture:

  • Public API: Ergonomic builder pattern for common use cases
  • Renderer trait: Abstraction allowing multiple backend implementations
  • Chrome backend: Production-ready Chrome DevTools Protocol integration

§Quick Start

use carbonpdf::{PdfBuilder, PageSize, Result};

#[tokio::main]
async fn main() -> Result<()> {
    // Convert HTML string to PDF
    let pdf = PdfBuilder::new()
        .html("<h1>Hello, PDF!</h1>")
        .page_size(PageSize::A4)
        .margin_all(1.0)
        .build()
        .await?;

    std::fs::write("output.pdf", pdf)?;
    Ok(())
}

§Feature Flags

  • chrome (default): Enable Chrome backend via chromiumoxide
  • cli: Build the carbonpdf CLI tool

Re-exports§

pub use builder::PdfBuilder;
pub use config::PdfConfig;
pub use config::PageSize;
pub use config::Orientation;
pub use config::Margins;
pub use error::Error;
pub use error::Result;
pub use input::InputSource;
pub use renderer::PdfRenderer;
pub use renderer::chrome::ChromeRenderer;

Modules§

builder
Fluent builder API for PDF generation.
config
PDF configuration types.
error
Error types for CarbonPDF operations.
input
Input source types for HTML content.
renderer
PDF rendering abstraction and implementations.
utils
Utility functions for working with PDFs.

Constants§

VERSION
Library version