Free C++ PDF API to Read, Write, Merge & Encrypt PDF Files.
Leading Open Source C++ PDF Generation Library for C and C++. It Provide a full Set of Features to Read, Create, Edit, Manipulate, and Secure PDF Documents in Cross-Platform Environments.
What is VersyPDF Library?
In the world of software development, the ability to generate and manipulate PDF documents is a common requirement. VersyPDF is a powerful, open-source C++/C library that provides a comprehensive set of tools for working with PDF files. Whether you're building a complex document management system or simply need to add PDF export functionality to your application, VersyPDF has you covered. The library provides very granular control over text, graphics, layout, fonts, color; suitable for applications that need precise output (e.g. publishing, automated document generation). The library provides a complete solution for working with PDF forms. You can fill in existing forms, read the values of form fields, and even create new form fields from scratch.
VersyPDF is an open source, industry-strength PDF library for C and C++, developed by Sybrex Systems. Its goal is to provide developers with a full set of tools to read, create, edit, manipulate, and secure PDF documents in cross-platform environments. It boasts a rich feature set that makes it a versatile solution for a wide range of PDF-related tasks. The library supports reading and writing PDF documents, content creation and manipulation, embedding images into PDF documents, font and text handling, better color and graphics support, create and edit bookmarks, PDF encryption support, PDF files optimization, and so on. With its comprehensive feature set and easy-to-use API, VersyPDF is an excellent choice for any developer who needs to incorporate PDF functionality into their applications.
Getting Started with VersyPDF
TThe recommend way to install VersyPDF is using CMake. Please use the following command for a smooth installation.
Install VersyPDF via GitHub
git clone https://github.com/sybrexsys/VersyPDF.git
You can also install it manually; download the latest release files directly from GitHub repository.
Reading & Writing PDF Documents via C++
The open source VersyPDF has included support for creating new PDF documents and reading existing PDFs inside C++ application. Software developers can load PDF documents from files or memory buffers, and write modified or new PDFs back to file or memory with ease. This means both input and output are flexible. The following example demonstrates how to create a simple PDF document with a single page of text using C++ commands.
How to Create PDF Documents & Add Page to It via C++ API?
#include "versypdf.h"
int main()
{
// Create a new PDF document
CPDFDocument doc;
doc.CreateNew();
// Add a new page
CPDFPage page = doc.AppendPage();
// Set the font and draw some text
page.BeginText();
page.SetFont("Helvetica", 12);
page.SetXY(100, 700);
page.ShowText("Hello, VersyPDF!");
page.EndText();
// Save the document to a file
doc.SaveToFile("hello.pdf");
return 0;
}
Add Images and Fonts to PDF via C++ API
The open source VersyPDF makes it easy for software developers to easily handle images and fonts inside PDF documents using C++ API. The library supports embedding common image formats, such as TIFF, JPEG, PNG, BMP and more. It is very useful for including raster content (e.g. photos, scans). The following example demonstrates, how software developers can embed a JPEG image into a PDF document inside C++ applications.
How to Embed a JPEG Image into a PDF Document inside C++ Apps?
#include "versypdf.h"
int main()
{
// Create a new PDF document
CPDFDocument doc;
doc.CreateNew();
// Add a new page
CPDFPage page = doc.AppendPage();
// Load an image from a file
CPDFImage image = doc.CreateImageFromFile("my_image.jpg");
// Draw the image on the page
page.DrawImage(image, 100, 500, 200, 150);
// Save the document to a file
doc.SaveToFile("image_example.pdf");
return 0;
}
Merge PDFs & Manipulate Pages in PDF via C++
The VersyPDF library has included several features for merging various PDF documents and manipulate pages inside PDF documents via C++ library. The library has included support for rotating pages, splitting, merging, appending and deleting unwanted pages with just a couple of lines of code. Moreover, it also supports inserting or appending new content into existing pages with ease. Here is a very useful example that shows how to merge two PDF files, add a Bookmark, and apply encryption inside C++ apps.
How to Merge Two PDFs, Add a Bookmark and Apply Encryption via C++?
#include "versypdf.h"
int main() {
// Load existing PDFs
VersyPDF::Document doc1, doc2;
doc1.LoadFromFile("document1.pdf");
doc2.LoadFromFile("document2.pdf");
// Merge
VersyPDF::Document merged = VersyPDF::Merge({ &doc1, &doc2 });
// Add a bookmark to first page
merged.AddBookmark("Start Here", /*pageIndex=*/0, /*destination=*/VersyPDF::Destination::FitPage);
// Apply encryption: 256-bit AES, require password to open
merged.SetSecurityHandler(VersyPDF::Security::AES256, /*ownerPwd=*/"ownerpass", /*userPwd=*/"userpass", /*permissions=*/VersyPDF::Permission::Print);
// Save
merged.Save("merged_encrypted.pdf");
return 0;
Working with PDF Forms via C++
The open source VersyPDF library provides a complete solution for working with PDF forms. The library has included various features for handling forms, such as creating new form fields from scratch, filling in an existing forms, read the values of form fields, and many more. Here is a very useful example that demonstrates how software developers can fill in a simple PDF form with a single text field via C++.
How to Fill in a Simple PDF Form with a Single Text Field via C++ Apps?
#include "versypdf.h"
int main()
{
// Load an existing PDF document with a form
CPDFDocument doc;
doc.LoadFromFile("form.pdf");
// Get the form field by name
CPDFFormField field = doc.GetFormField("my_text_field");
// Set the value of the form field
field.SetValue("This is the new value");
// Save the modified document
doc.SaveToFile("form_filled.pdf");
return 0;
}