|
My Project
|
PoDoFo is a free portable C++ library to work with the PDF file format.
PoDoFo provides classes to parse a PDF file and modify its content, allowing to write it back to disk easily. Besides PDF parsing and manipulation PoDoFo also provides facilities to create your own PDF files from scratch.
PoDoFo has a modern and user-friendly C++17 API that features:
PoDoFo does not support rendering PDF content yet. Text writing is also limited as it currently does not perform proper text shaping/kerning.
To build PoDoFo lib you'll need a c++17 compiler, CMake 3.16 and the following libraries (tentative minimum versions indicated):
For the most popular toolchains, PoDoFo requires the following minimum versions:
It is regularly tested with the following IDE/toolchains versions:
GCC 8.1 support broke, but it could be reinstanced.
PoDoFo library is licensed under the LGPL 2.0 or later terms. PoDoFo tools are licensed under the GPL 2.0 or later terms.
PoDoFo is known to compile through a multitude of package managers (including APT, brew, vcpkg, Conan), and has public continuous integration working in Ubuntu Linux, MacOS and Windows, bootstrapping the CMake project, building and testing the library. It's highly recommended to build PoDoFo using such package managers.
There's also a playground area in the repository where you can have access to pre-build dependencies for some popular architectures/operating systems: the playground is the recommended setting to develop the library and reproduce bugs, while it's not recommended for the deployment of your application using PoDoFo. Have a look to the Readme there.
Warning: PoDoFo is known to be working in cross-compilation toolchains (eg. Android/iOS development), but support may not provided in such scenarios. If you decide to manually build dependencies you are assumed to know how to identity possible library clashes/mismatches and how to deal with compilation/linking problems that can arise in your system.
From the source root run:
Install brew, then from the source root run:
Install conan, then from source root run:
Follow the vcpkg quickstart guide to setup the package manager repository first. In Windows, it may be also useful to set the environment variable VCPKG_DEFAULT_TRIPLET to x64-windows to default installing 64 bit dependencies and define a VCPKG_INSTALLATION_ROOT variable with the location of the repository as created in the quickstart.
Then from source root run:
Starting with version 1.0, PoDoFo has a quite advanced CMake integration and can be consumed as a CMake package. As soon as it's correctly integrated in your favorite package manager (APT, vcpkg, Conan, ...), you will be able to locate PoDoFo and compile your application with the following CMakeLists.txt:
If you want to use a static build of PoDoFo and you are including the PoDoFo cmake project it's very simple. Do something like the following in your CMake project:
If you are linking against a precompiled static build of PoDoFo this is a scenario where the support is limited, as you are really supposed to be able to identify and fix linking errors. The general steps are:
The API documentation can be found at https://podofo.github.io/podofo/documentation/ .
Refer to the main article in the Wiki. At this page you can find an incomplete guide on migrating 0.9.8 code to 0.10.x, and from 0.10.x to 1.0.
All std::strings or std::string_view in the library are intended to hold UTF-8 encoded string content. PdfString and PdfName constructors accept UTF-8 encoded strings by default (PdfName accept only characters in the PdfDocEncoding char set, though). charbuff abd bufferview instead represent a generic octet buffer.
Warning: Tools are currently unsupported, untested and unmaintained.
PoDoFo tools are still available in the source tree but their compilation is disabled by default because they are unsted/unmaintained, and will not receive support until their status is cleared. It's not recommended to include them in software distributions. If you want to build them make sure to bootstrap the CMake project with -DPODOFO_BUILD_UNSUPPORTED_TOOLS=TRUE. Tools are conveniently enabled in the playground at least to ensure library changes won't break their compilation.
There's a TODO list, or look at the issue tracker.
**Q: PoDoFo compilation requires a CMake version higher than what is present in my system, can you lower the requirement?**
A: No, CMake 2.23 introduced a functionality that makes it very easy to create CMake packages that is too conventient to ignore. In Windows it's easy to upgrade the CMake version to latest, while in MacOs it's the same thanks to the official KitWare installer or brew. In a linux system it's also quite easy to install an upgraded parallel CMake installation. Just run the following script:
**Q: How do I sign a document?**
A: PoDoFo HEAD now supplies a high level signing procedure which is very powerful and that allows to sign a document without having to supply a CMS structure manually. By default, it supports signing a document with the modern PAdES-B compliance profiles, but there's also a support for the legacy PKCS7 signatures. Providing you have both ASN.1 encoded X509 certificate and RSA private key, you can sign a document with the following code:
There's also a support for external signing services and/or signing the document in memory buffers. See the various signing examples in the unit tests.
**Q: Can I still use an event based procedure to sign the document?**
A: Yes, the old low level procedure hasn't changed and it's still available. To describe the procedure briefly, one has to fully Implement a PdfSigner, retrieve or create a PdfSignature field, create an output device (see next question) and use PoDoFo::SignDocument(doc, device, signer, signature). When signing, the sequence of calls of PdfSignature works in this way: method PdfSigner::Reset() is called first, then the PdfSigner::ComputeSignature(buffer, dryrun) is called with an empty buffer and the dryrun argument set to true. In this call one can just resize the buffer overestimating the required size for the signature, or just compute a fake signature that must be saved on the buffer. Then a sequence of PdfSigner::AppendData(buffer) are called, receiving all the document data to be signed. A final PdfSigner::ComputeSignature(buffer, dryrun) is called, with the dryrun parameter set to false. The buffer on this call is cleared (capacity is not altered) or not accordingly to the value of PdfSigner::SkipBufferClear().
**Q: PdfMemDocument::SaveUpdate() or PoDoFo::SignDocument() write only a partial file: why there's no mechanism to seamlessly handle the incremental update as it was in PoDoFo 0.9.x? What should be done to correctly update/sign the document?**
A: The previous mechanism in PoDoFo 0.9.x required enablement of document for incremental updates, which is a decision step which I believe should be unnecessary. Also:
An alternative strategy that makes clearer the fact that the incremental update must be performed on the same file from where the document was loaded, or that underlying buffer will grow its mememory consumption following subsequent operations in case of buffer loaded documents, is available. It follows a couple of examples showing the correct operations to update a document, loaded from file or buffer:
Signing documents can be done with same technique, read the other questions for more examples.
**Q: Can I sign a document a second time?**
A: Yes, this is tested, but to make sure this will work you'll to re-parse the document a second time, as re-using the already loaded document is still untested (this may change later). For example you can do as it follows:
PoDoFo may or may not work for your needs and comes with absolutely no warranty. Serious bugs, including security flaws, may be fixed at arbitrary timeframes, or not fixed at all. Priority of implementing new features and bug fixing are decided according to the interests and personal preferences of the maintainers. If you need PoDoFo to integrate a feature or bug fix that is critical to your workflow, the most welcome and fastest approach is to contribute high-quality patches.
Please subscribe to the project mailing list which is still followed by several of the original developers of PoDoFo. A gitter community has also been created to ease some more informal chatter. If you find a bug and know how to fix it, or you want to add a small feature, you're welcome to send a pull request, providing it follows the coding style of the project. As a minimum requisite, any contribution should be:
Other reasons for the rejection, or hold, of a pull request may be:
If you need to implement a bigger feature or refactor, ask first if it was already planned. The feature may be up for grabs, meaning that it's open for external contributions. Please write in the relevant issue that you started to work on that, to receive some feedback/coordination. If it's not, it means that the refactor/feature is planned to be implemented later by the maintainer(s). If the feature is not listed in the issues, add it and/or create a discussion to receive some feedback and discuss some basic design choices.
Warning: Please don't use personal email addresses for technical support inquries, but create github issues instead.
PoDoFo is currently developed and maintained by Francesco Pretto, together with Dominik Seichter and others. See the file AUTHORS.md for more details.