Generate PDF via Open Source C++ API
Open Source C++ Library for Creating, Editing, Manipulating & Parsing PDF Files.
What is PDF-Writer?
PDF-Writer is an Open Source C++ library that fully supports creating, editing, manipulating & parsing PDF Files as well as streams. The library was developed with the principal “one-off” method of generating PDF files. That’s why it is working fast and uses low memory regardless of how large the file grows. Therefore it is best to create small PDF files or generate larger PDF documents.
Adding content to a PDF is always very important and helping developers in generating custom PDFs. The library has included support for several important features for processing PDF files such as creation of PDF pages, PDF operators for drawing content, JPG or PNG and TIFF images embedding, modifying PDF, merge or split PDFs, rendering PDF files, data extraction from PDF, Unicode text support, TrueType and OpenType fonts support and many more.
At A Glance
An overview of PDF-Writer features.
- Generate PDF
- PDF modification
- PDF merging
- PDF rendering
- Add PDF pages
- Unicode text
- Embed images
- Primitives drawing
- PDF annotations
- Data extraction
- Font embedding
- State Saving
- Encrypt PDF
- Parsing PDF
- FDF form
- Unicode support
PDF-Writer supports PDF file format as well as industry-standard formats for export.
PDF-Writer only requires C++ runtime.
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
PDF Generation in C++
// 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.
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.
Merging PDF Pages Content via C++
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);