hipdf
A high-level PDF manipulation library built on lopdf, focusing on ease of use and powerful abstractions for common PDF operations following the ISO 32000-2 standard.
Features
- Optional Content Groups (OCG): Easy creation and management of PDF layers
- Layer Management: High-level API for organizing content into toggleable layers
- Hatching Patterns: Support for various fill patterns including crosshatching, dots, and custom patterns
- PDF Embedding: Embed other PDF documents with various layout strategies
- Block System: Reusable PDF content components with transformations and efficient rendering
- Image Embedding: Support for PNG and JPEG images
- Font Management: Easy embedding and management of fonts
- Type Safety: Strongly typed interfaces with compile-time guarantees
Showcase
You can see the results of our test suit in this folder.
Quick Start
Creating PDF Layers
use ;
use ;
// Create a new PDF with layers
let mut doc = with_version;
let mut ocg_manager = with_config;
// Add layers
ocg_manager.add_layer;
ocg_manager.add_layer;
ocg_manager.add_layer;
// Initialize layers in document
ocg_manager.initialize;
// Build content for specific layers
let mut builder = new;
builder.begin_layer
.add_operation
.add_operation
.end_layer;
Adding Hatching Patterns
use ;
// Create a hatching manager
let mut manager = new;
// Add a diagonal pattern
let pattern_id = manager.add_pattern;
// Create a shape with the pattern
let mut builder = new;
builder.rectangle;
Embedding PDFs
use ;
// Create an embedder
let mut embedder = new;
// Load a PDF
embedder.load_pdf?;
let options = EmbedOptions ;
// Embed into target document
embedder.embed_pdf?;
Creating Reusable Blocks
use ;
use Operation;
// Create a block manager
let mut manager = new;
// Create a reusable block
let mut block = new;
manager.register;
// Create instances with different transformations
let instances = vec!;
// Render all instances
let operations = manager.render_instances;
Modules
- [
ocg] - Optional Content Groups (layers) functionality - [
hatching] - Hatching and pattern support for PDF documents - [
embed_pdf] - PDF embedding and composition support - [
blocks] - Reusable PDF content components with transformations - [
images] - Image embedding and manipulation - [
fonts] - Font management and embedding
Usage Examples
Image Embedding with Quality Preservation
use ;
use Document;
// Create an image manager for efficient embedding
let mut image_manager = new;
// Load images with perfect quality preservation
let image = from_file?;
let img_id = image_manager.embed_image?;
// Add to page resources
let img_name = image_manager.add_to_resources;
// Draw the image on the page
let operations = draw_image;
Layer Management
use ;
// Create layer manager
let mut manager = new;
// Add layers with different visibility settings
manager.add_layer;
manager.add_layer;
manager.add_layer;
// Initialize in PDF document
manager.initialize;
Custom Hatching Patterns
use ;
// Create custom pattern
let mut pattern_builder = new;
pattern_builder
.move_to
.line_to
.line_to;
// Register the pattern
let custom_pattern_id = manager.add_custom_pattern;
Advanced PDF Embedding
use ;
// Create layout builder
let mut layout_builder = new;
// Add multiple PDFs with different layouts
layout_builder
.add_pdf
.add_pdf;
// Generate the final document
let final_doc = layout_builder.build?;
Block System
use ;
// Create block manager and register reusable content
let mut manager = new;
let star_block = new.with_bbox;
manager.register;
// Create multiple instances with different positions and transformations
let instances = vec!;
// Render instances efficiently using Form XObjects
manager.create_xobjects;
let operations = manager.render_instances_as_xobjects;
Requirements
- Rust 1.70+
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
API Documentation
For complete API documentation, visit docs.rs/hipdf.