Expand description
§PDF-CLI Library
A comprehensive Rust library for reading, writing, and manipulating PDF documents. This library provides functionality for:
- PDF Generation: Create PDFs from markdown or raw text content
- PDF Parsing: Extract text and structure from existing PDFs
- PDF Manipulation: Merge, split, rotate, and reorder pages
- Image Support: Embed JPEG, PNG, and BMP images in PDFs
- Annotations: Add text, link, and highlight annotations
- Forms: Create interactive PDF forms with text fields, checkboxes, radio buttons, and dropdowns
- Watermarks: Add text or image watermarks to PDFs
- Metadata: Manage document metadata including custom fields
- Security: Add password protection and permissions to PDFs
§Quick Start
use pdfrs::pdf_generator;
use pdfrs::elements;
// Parse markdown content
let markdown = "# Hello World\n\nThis is a test document.";
let elements = elements::parse_markdown(markdown);
// Generate PDF
let layout = pdf_generator::PageLayout::portrait();
pdf_generator::create_pdf_from_elements_with_layout(
"output.pdf",
&elements,
"Helvetica",
12.0,
layout,
).expect("Failed to create PDF");§Modules
pdf: PDF document parsing and text extractionpdf_generator: PDF generation from elements and content streamspdf_ops: High-level PDF operations (merge, split, watermark, etc.)elements: Markdown parsing and element representationmarkdown: Markdown to PDF conversion utilitiesimage: Image loading, parsing, and PDF embeddingcompression: Data compression utilitiessecurity: PDF security, encryption, and permission managementbuilder: Fluent builder API for ergonomic PDF creationstreaming: Memory-efficient streaming PDF generation for large documentsparallel: High-performance parallel PDF operations using Rayonoptimization: PDF optimization profiles for different use cases (web, print, archive, ebook)
§Examples
§Creating a PDF from Markdown
use pdfrs::markdown;
markdown::markdown_to_pdf_full(
"input.md",
"output.pdf",
"Helvetica",
12.0,
pdfrs::pdf_generator::PageOrientation::Portrait,
).expect("Failed to convert");§Merging PDFs
use pdfrs::pdf_ops;
pdf_ops::merge_pdfs(
&["file1.pdf", "file2.pdf"],
"merged.pdf",
).expect("Failed to merge");§Adding a Watermark
use pdfrs::pdf_ops;
pdf_ops::watermark_pdf(
"input.pdf",
"output.pdf",
"CONFIDENTIAL",
48.0,
0.3,
).expect("Failed to add watermark");§Parallel PDF Operations
use pdfrs::parallel;
// Merge multiple PDFs in parallel (loads inputs concurrently)
parallel::merge_pdfs_parallel(
&["file1.pdf", "file2.pdf", "file3.pdf"],
"merged.pdf",
).expect("Failed to merge");
// Extract text from multiple PDFs in parallel
let results = parallel::extract_text_parallel(&["doc1.pdf", "doc2.pdf"])
.expect("Failed to extract text");
for (path, text) in results {
println!("{}: {} characters", path, text.len());
}§PDF Optimization Profiles
use pdfrs::optimization::{OptimizationProfile, OptimizedPdfGenerator};
// Create a web-optimized PDF (smallest file size)
let _pdf_gen = OptimizedPdfGenerator::new(OptimizationProfile::web());
// Or create a print-optimized PDF (highest quality)
let _pdf_gen = OptimizedPdfGenerator::new(OptimizationProfile::print());
// Or create a custom optimization profile
use pdfrs::optimization::{OptimizationSettings, CompressionLevel};
let settings = OptimizationSettings::new()
.with_compression(CompressionLevel::High)
.with_image_dpi(200);
let _pdf_gen = OptimizedPdfGenerator::new(OptimizationProfile::custom(settings));Modules§
- builder
- compression
- elements
- image
- markdown
- optimization
- PDF optimization profiles for different use cases
- parallel
- pdf_
generator - pdf_ops
- PDF high-level operations module
- security
- PDF security and encryption support
- streaming
- table_
renderer - Table rendering module for PDF generation