Convert Figma logo to code with AI

galkahana logoPDF-Writer

High performance library for creating, modiyfing and parsing PDF files in C++

1,001
229
1,001
52

Top Related Projects

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

3,041

Mirror of Apache PDFBox

1,957

libharu - free PDF library

53,141

PDF Reader in JavaScript

Quick Overview

PDF-Writer is an open-source C++ library for creating and manipulating PDF files. It provides a comprehensive set of tools for generating PDF documents programmatically, including support for text, images, vector graphics, and various PDF features.

Pros

  • Lightweight and efficient, with minimal dependencies
  • Supports a wide range of PDF features and specifications
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Actively maintained with regular updates and bug fixes

Cons

  • Steeper learning curve compared to some higher-level PDF libraries
  • Documentation could be more comprehensive and user-friendly
  • Limited built-in support for advanced typography and text layout
  • Requires manual memory management in some cases

Code Examples

  1. Creating a simple PDF document with text:
PDFWriter pdfWriter;
pdfWriter.StartPDF("output.pdf", ePDFVersion13);

PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, 595, 842));

PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
PDFUsedFont* font = pdfWriter.GetFontForFile("arial.ttf");

contentContext->BT();
contentContext->k(0, 0, 0, 1);
contentContext->Tf(font, 14);
contentContext->Tm(1, 0, 0, 1, 20, 800);
contentContext->Tj("Hello, PDF-Writer!");
contentContext->ET();

pdfWriter.EndPageContentContext(contentContext);
pdfWriter.WritePageAndRelease(page);
pdfWriter.EndPDF();
  1. Adding an image to a PDF:
PDFWriter pdfWriter;
pdfWriter.StartPDF("output_with_image.pdf", ePDFVersion13);

PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, 595, 842));

PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);

PDFImageXObject* imageXObject = pdfWriter.CreateImageXObjectFromJPGFile("image.jpg");
contentContext->q();
contentContext->cm(200, 0, 0, 200, 50, 500);
contentContext->Do(page->GetResourcesDictionary().AddImageXObjectMapping(imageXObject));
contentContext->Q();

pdfWriter.EndPageContentContext(contentContext);
pdfWriter.WritePageAndRelease(page);
pdfWriter.EndPDF();
  1. Creating a simple vector graphic:
PDFWriter pdfWriter;
pdfWriter.StartPDF("output_with_graphic.pdf", ePDFVersion13);

PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0, 0, 595, 842));

PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);

contentContext->q();
contentContext->G(1);
contentContext->g(0.5);
contentContext->w(2);
contentContext->m(100, 500);
contentContext->l(200, 600);
contentContext->l(300, 500);
contentContext->h();
contentContext->B();
contentContext->Q();

pdfWriter.EndPageContentContext(contentContext);
pdfWriter.WritePageAndRelease(page);
pdfWriter.EndPDF();

Getting Started

  1. Clone the repository: git clone https://github.com/galkahana/PDF-Writer.git
  2. Build the library using CMake:
    mkdir build && cd build
    cmake ..
    make
    
  3. Include the necessary headers in your C++ project:
    #include "PDFWriter/PDFWriter.h"
    #include "PDFWriter/PDFPage.h"
    #include "PDFWriter/PageContentContext.h"
    
  4. Link against the built library when compiling your project.
  5. Use the code examples above as a starting point for creating your PDF documents.

Competitor Comparisons

iText for Java represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText can be a boon to nearly every workflow.

Pros of iText

  • More comprehensive feature set for PDF manipulation
  • Larger community and better documentation
  • Regular updates and active maintenance

Cons of iText

  • Commercial licensing required for many use cases
  • Steeper learning curve due to extensive API
  • Larger library size, potentially impacting application size

Code Comparison

PDF-Writer:

PDFWriter pdfWriter;
pdfWriter.StartPDF("output.pdf", ePDFVersion13);
PDFPage* page = pdfWriter.CreatePage();
page->WriteToStream(pdfWriter.GetWriteStream());
pdfWriter.EndPDF();

iText:

PdfWriter writer = new PdfWriter("output.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();

Key Differences

  • PDF-Writer is written in C++, while iText is primarily Java-based
  • iText offers more advanced features like digital signatures and form filling
  • PDF-Writer has a simpler API, making it easier for beginners to get started
  • iText has better support for PDF/A and other PDF standards
  • PDF-Writer is open-source and free for commercial use, unlike iText

Both libraries are capable of creating and manipulating PDF documents, but iText is generally more feature-rich and widely used in enterprise environments, while PDF-Writer may be more suitable for simpler use cases or projects with licensing constraints.

3,041

Mirror of Apache PDFBox

Pros of PDFBox

  • More comprehensive feature set, including PDF creation, manipulation, and extraction
  • Larger community and better documentation
  • Active development with frequent updates and bug fixes

Cons of PDFBox

  • Steeper learning curve due to its extensive API
  • Larger library size, which may impact application size and performance
  • More complex setup and configuration process

Code Comparison

PDFBox:

PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();

PDF-Writer:

PDFWriter pdfWriter;
PDFPage* page = pdfWriter.CreatePage();
PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
PDFUsedFont* font = pdfWriter.GetFontForFile("arial.ttf");
contentContext->BT();

Both libraries provide methods for creating PDF documents and adding content. PDFBox uses a more object-oriented approach with separate classes for different components, while PDF-Writer uses a more procedural style with a central PDFWriter object.

PDFBox offers a more Java-centric API, while PDF-Writer is designed for C++ developers. The choice between the two may depend on the programming language preference and specific project requirements.

1,957

libharu - free PDF library

Pros of libharu

  • Lightweight and efficient C library for PDF generation
  • Extensive documentation and examples available
  • Cross-platform support (Windows, macOS, Linux)

Cons of libharu

  • Less active development compared to PDF-Writer
  • Limited support for advanced PDF features
  • C-based API may be less intuitive for some developers

Code Comparison

PDF-Writer (C++):

PDFWriter pdfWriter;
PDFPage* page = pdfWriter.CreatePage(0, 0, 595, 842);
PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
contentContext->WriteText(10, 800, "Hello, World!");
pdfWriter.EndPageContentContext(contentContext);
pdfWriter.WriteToFile("output.pdf");

libharu (C):

HPDF_Doc pdf = HPDF_New(NULL, NULL);
HPDF_Page page = HPDF_AddPage(pdf);
HPDF_Page_BeginText(page);
HPDF_Page_SetFontAndSize(page, HPDF_GetFont(pdf, "Helvetica", NULL), 18);
HPDF_Page_TextOut(page, 10, 800, "Hello, World!");
HPDF_Page_EndText(page);
HPDF_SaveToFile(pdf, "output.pdf");
HPDF_Free(pdf);

Both libraries offer PDF generation capabilities, but PDF-Writer provides a more modern C++ interface with potentially easier-to-use abstractions. libharu, being a C library, may offer better performance in some cases but requires more manual memory management. The choice between the two depends on specific project requirements, language preferences, and desired features.

53,141

PDF Reader in JavaScript

Pros of pdf.js

  • Widely adopted and actively maintained by Mozilla
  • Renders PDFs directly in web browsers without plugins
  • Extensive documentation and community support

Cons of pdf.js

  • Focused on rendering PDFs, not creating or editing them
  • Larger file size and potentially slower performance for complex PDFs
  • Limited support for advanced PDF features

Code Comparison

PDF-Writer (C++):

PDFWriter pdfWriter;
PDFPage* page = pdfWriter.CreatePage(0, 0, 595, 842);
PageContentContext* contentContext = pdfWriter.StartPageContentContext(page);
contentContext->WriteText(10, 800, "Hello World");

pdf.js (JavaScript):

pdfjsLib.getDocument('path/to/document.pdf').promise.then(function(pdf) {
  pdf.getPage(1).then(function(page) {
    var scale = 1.5;
    var viewport = page.getViewport({ scale: scale });
    // Render page content
  });
});

PDF-Writer is designed for creating and manipulating PDFs programmatically, while pdf.js focuses on rendering existing PDFs in web browsers. The code examples illustrate this difference, with PDF-Writer showing content creation and pdf.js demonstrating page rendering.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PDF-Writer (PDFHummus)

A fast and free C++ library for creating, parsing and manipulating PDF files and streams.

📖 Documentation | 🌐 Project Site | 🟢 NodeJS Wrapper

Prerequisites

  • Compiler: Visual Studio (Windows), GCC/Clang (Linux/macOS)
  • CMake: Download here
  • OpenSSL: Required for PDF2.0 encryption (set PDFHUMMUS_NO_OPENSSL=TRUE to disable)

Project Structure

  • PDFWriter: Main library implementation
  • PDFWriterTesting: Test code for ctest
  • FreeType, LibAesgm, LibJpeg, LibPng, LibTiff, Zlib: Bundled dependencies

Quick Start

# Build
mkdir build && cd build
cmake ..
cmake --build . --config Release

# Test
ctest --test-dir . -C Release

# Install
cmake --install . --prefix ./install --config Release

CMake Options

OptionDefaultDescription
PDFHUMMUS_NO_DCTFALSEExclude DCT decoding support/Detach LibJpeg dependency
PDFHUMMUS_NO_TIFFFALSEExclude TIFF Images support/Detach LibTiff dependency
PDFHUMMUS_NO_PNGFALSEExclude PNG Images support/Detatch LibgPng dependency
PDFHUMMUS_NO_OPENSSLFALSEExclude PDF2.0 encryption/Detach OpenSSL dependency
USE_BUNDLEDTRUEUse bundled dependencies
USE_UNBUNDLED_FALLBACK_BUNDLEDFALSEFallback to bundled if system libs not found
BUILD_FUZZING_HARNESSFALSEEnable fuzz testing

Example: cmake .. -DUSE_BUNDLED=FALSE

Using in Your Project

Option 1: CMake FetchContent (Recommended)

include(FetchContent)
FetchContent_Declare(
  PDFHummus
  GIT_REPOSITORY https://github.com/galkahana/PDF-Writer.git
  GIT_TAG        v4.6.2
  FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(PDFHummus)
target_link_libraries(YourTarget PDFHummus::PDFWriter)

Option 2: find_package

find_package(PDFHummus REQUIRED)
target_link_libraries(YourTarget PDFHummus::PDFWriter)

Option 3: Copy Sources

Simply copy the source folders to your project and include them directly.

Development

Testing

# Run tests
ctest --test-dir build -C Release -j8

# Build and test 
cmake --build build --target pdfWriterCheck --config Release

Test output files: ./build/Testing/Output

VS Code Setup

Install these extensions:

  • C/C++ Extension Pack
  • CMake Tools
  • CMake Test Explorer

Packaging

cd build && cpack .

Development Guidelines

For detailed development guidelines, coding standards, and contribution patterns, see CLAUDE.md. This document contains:

  • Project coding standards and conventions
  • Build commands and configuration options
  • Error handling patterns and best practices
  • Testing guidelines and organizational structure

This documentation is also optimized for AI-assisted development with Claude Code.

Additional Build Instructions

iOS: See build guide

Manual builds: All PDFWriter sources are in the PDFWriter folder. Link against Zlib, LibTiff, LibJpeg, LibPng, FreeType, and OpenSSL.