Skip to content

C++ API

Milosz edited this page Oct 9, 2026 · 3 revisions

C++ API

The public native exporter API is intentionally small and lives in include/rayomd/tiny_pdf.h.

#include "rayomd/tiny_pdf.h"

#include <string>

std::string pdfBytes;
TinyPdf::PdfOptions options;
options.style = TinyPdf::PdfStyle::Modern;
options.margin = TinyPdf::PdfMargin::Normal();
options.sourcePath = "input.md";
options.enableUrlImages = false;
options.embedSource = false;  // opt in only for exact source recovery
options.pageNumbers = false;  // "N / M" at the foot of every page (since 3.1)

TinyPdf::BuildResult result = TinyPdf::BuildPdf(markdownText, options, pdfBytes);
if (!result) {
    return static_cast<int>(result.error);
}
if (result.missingCharacters != 0) {
    // No available font could show these characters; they were drawn as their base
    // letter or '?'. The PDF is still complete.
}

Set sourcePath for file-based conversions so relative local images resolve next to the input file. By default, image targets must remain inside that source directory after canonicalization. Enable unsafe local paths or URL fetching only for trusted documents.

Since 3.1, a missing system font no longer fails the build: the document is drawn in the PDF standard fonts and missingCharacters counts what they could not show.

The header in the source tag you build against is authoritative for that release.

Clone this wiki locally