Converting HTML to PDF is a common task for applications that generate reports, invoices, or other printable documents. Many solutions rely on embedding a full browser engine like WebKit or Chromium, which can add unnecessary complexity and size.
PlutoBook is a lightweight, native solution for rendering HTML into paged documents. It supports modern HTML and CSS features, handles pagination properly, and exports clean PDF files without bringing in a full browser behind the scenes.
What is PlutoBook?
PlutoBook is an open-source library for generating paged documents from HTML content. It is written in C++ with a clean C API, so you can use it easily in either C++ or C projects.
It is well-suited for generating reports, printable documents, or any scenario where you need reliable HTML-to-PDF conversion without bundling a full browser.
Quick Start: Render HTML to PDF
Below are minimal examples for both C++ and C to demonstrate how easy it is to generate a PDF.
C++ Example
#include <plutobook.hpp>
int main() {
plutobook::Book book(plutobook::PageSize::A4);
book.loadHtml("<b>Hello World</b>");
book.writeToPdf("hello.pdf");
return 0;
}
C Example
#include <plutobook.h>
int main() {
plutobook_t* book = plutobook_create(
PLUTOBOOK_PAGE_SIZE_A4,
PLUTOBOOK_PAGE_MARGINS_NORMAL,
PLUTOBOOK_MEDIA_TYPE_PRINT
);
plutobook_load_html(book, "<b>Hello World</b>", -1, "", "", "");
plutobook_write_to_pdf(book, "hello.pdf");
plutobook_destroy(book);
return 0;
}
Load HTML from a URL
PlutoBook can fetch remote pages or local files by URL. This is handy if you want to render a public web page or a local file on disk.
Keep in mind that PlutoBook does not execute JavaScript, so pages relying on client-side scripts may not look complete.
Loading over HTTP or HTTPS requires that PlutoBook is built with
libcurl.
C++ Example
#include <plutobook.hpp>
int main() {
plutobook::Book book(plutobook::PageSize::A4, plutobook::PageMargins::None);
book.loadUrl("https://en.wikipedia.org/wiki/Bjarne_Stroustrup");
book.writeToPdf("Bjarne_Stroustrup.pdf");
return 0;
}
Example output:
C Example
#include <plutobook.h>
int main()
{
plutobook_t* book = plutobook_create(
PLUTOBOOK_PAGE_SIZE_A4,
PLUTOBOOK_PAGE_MARGINS_NONE,
PLUTOBOOK_MEDIA_TYPE_PRINT
);
plutobook_load_url(book, "https://en.wikipedia.org/wiki/Dennis_Ritchie", "", "");
plutobook_write_to_pdf(book, "Dennis_Ritchie.pdf");
return 0;
}
Example output:
How to Build PlutoBook
PlutoBook uses Meson and Ninja as its build system. This makes configuration quick and reproducible.
Prerequisites
PlutoBook depends on the following libraries:
Required: cairo, freetype, harfbuzz, fontconfig, expat, icu
Optional: curl, turbojpeg, webp (these enable URL loading and more image formats)
Pro Tip
It is strongly recommended to install precompiled versions of these libraries using your system package manager. Otherwise, Meson will build them from source which can take extra time.
On Ubuntu or Debian, install all needed packages with:
sudo apt-get install -y libcairo2-dev libexpat1-dev libicu-dev \
libfreetype6-dev libfontconfig1-dev libharfbuzz-dev \
libcurl4-openssl-dev libturbojpeg0-dev libwebp-dev \
ninja-build meson
Build and Install
Clone the repository, configure the build, compile, and install:
git clone https://github.com/plutoprint/plutobook.git
cd plutobook
meson setup build
meson compile -C build
sudo meson install -C build
After this, the PlutoBook library and headers will be available for your own projects.
Why PlutoBook is Different
PlutoBook is not trying to be a full web browser. Its goal is to render simple, predictable HTML for paged output, and do it well. This makes it a good fit for projects that need predictable printing or PDF export without the overhead of a browser runtime.
Get Involved
PlutoBook is open source and actively developed. You can contribute by testing, reporting issues, or submitting pull requests on GitHub.
What do you think?
Have you tried PlutoBook? Do you use a different library for HTML to PDF in C or C++? I would love to hear your thoughts and tips in the comments below.


Top comments (0)