Generate & Manipulate PDFs via Open Source C++ API
Top Open Source C++ PDF Processing Library for Creating, Editing, Manipulating & Parsing PDF Files in.
What is PDF-Writer?
For developers seeking a powerful open source PDF creation solution, PDF-Writer is a dedicated C++ PDF API built for performance. This library is engineered around an efficient "one-off" generation method, enabling it to create PDF files rapidly with minimal memory footprint. This design makes it exceptionally well-suited for generating everything from compact documents to larger PDF reports, ensuring stable performance regardless of the final file size.
Beyond its core strength in generation, the library provides robust capabilities to parse PDF files and manipulate their contents extensively. It includes a comprehensive feature set for processing, such as embedding images like JPG, PNG, and TIFF, supporting Unicode text and advanced fonts, and performing critical document operations. Developers can leverage these tools to modify existing PDFs, extract data, and execute tasks such as split pdf pages or merge documents, offering extensive control over PDF content and structure.
Getting Started with PDF-Writer
The recommended method for building the library, and sample application is to use CMake. you can get it from CMake web site. The library is dependent on Zlib, LibTiff, LibJpeg, FreeType, and LibPng. This means that you should compile them too, before using the PDF library in a linked context.
You can also install it manually; download the latest release files directly from GitHub repository.
PDF Generation & Modification via C++
Software developers can use PDF-Writer API to generate a new PDF file inside their own C++ applications. The library also facilitates developers to modify it according to their own needs. You can easily embed JPG, PNG, and TIFF images, Defining reusable objects, embed existing PDFs pages as well as text with ease. You can use existing PDFs pages by either append them as pages to the PDF or use them as parts to include in the graphics of a newly created page. By using the following steps, you can generate PDF easily.
Generate PDF in C++
- Create an instance of the PDFWriter objec
- Open a PDF file for writing
- Now go ahead and add content to the PDF.
- Save PDF document
How to Perform PDF Generation in C++ Apps?
// Create an instance of the PDFWriter objec
PDFWriter pdfWriter;
// Open a PDF file for writing
pdfWriter.StartPDF("c:\\myFile.pdf",ePDFVersion13);
// ...add content to PDF file...
pdfWriter.EndPDF();
Adding New Pages to PDF Document
With PDF-Writer library it is possible to add new pages and set their dimensions inside a PDF document. It is very easy and requires just a few lines of C++ code to add new pages to a PDF file. The library also gives developers the power to modify an existing page or delete a page. It is also possible to add content to an already created PDF page.
Embedding Images in PDF Documents
The PDF-Writer library provides support for embedding TIFF, PNG, and JPG Images as well as PDF pages. There are high-level methods that are general for any image type. Apart from that there some lower-level methods for advanced usages of the images. It has provided support for JPG Images through the native DCT decoder, PNG through decoding with LibPng and TIFF Images is through encoding/decoding with the help of LibTiff.
How to Perform Image Embedding in PDF via C++?
pdfWriter.StartPDF("HighLevelImages.PDF",ePDFVersion13);
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0,0,595,842));
PageContentContext* cxt = pdfWriter.StartPageContentContext(page);
cxt->DrawImage(10,10,"soundcloud_logo.jpg"));
pdfWriter.EndPageContentContext(cxt);
pdfWriter.WritePageAndRelease(page);
pdfWriter.EndPDF();
Joining Various PDF Documents
Using Open Source PDF combiner API, users can quickly combine multiple PDF documents without any external dependencies using just a couple of lines of code. The PDF-Writer gives software developers the power to generate a brand new PDF document from the existing PDF files. It helps users to store and review the PDF document more easily.
How to Merge PDF Pages Content via C++ API?
PDFPage* page = new PDFPage();
page->SetMediaBox(PDFRectangle(0,0,595,842));
PDFPageRange singlePageRange;
singlePageRange.mType = PDFPageRange::eRangeTypeSpecific;
singlePageRange.mSpecificRanges.push_back(ULongAndULong(0,0));
pdfWriter.MergePDFPagesToPage(page,"C:\\Other2PagePDF.PDF",singlePageRange);
pdfWriter.WritePageAndRelease(page);