C getting started

Generate PDF bytes
from C

Link one native library, keep ownership explicit, and use the same Rust renderer from any C-compatible runtime.

C11 · ABI generation 1 · Linux, macOS, Windows

Download the native library

Choose the archive for your platform from the matching GitHub release. It contains the public header, shared and static libraries, the ABI contract, and checksums.

cc main.c \
  -I ironpress-c-<VERSION>-linux-x86_64/include \
  -L ironpress-c-<VERSION>-linux-x86_64/lib \
  -lironpress_ffi -o render

Set your platform's shared-library search path when the library is not installed in a system location.

Create an HTML PDF

#include "ironpress.h"

#include <stdint.h>
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *source = "<h1>Hello from C</h1>";
    IronpressBytes html = {(const uint8_t *)source, strlen(source)};
    IronpressBuffer *pdf = NULL;
    IronpressError *error = NULL;

    if (ironpress_html_to_pdf(html, &pdf, &error) != IRONPRESS_STATUS_OK) {
        fwrite(ironpress_error_message_data(error), 1,
               ironpress_error_message_len(error), stderr);
        ironpress_error_free(&error);
        return 1;
    }

    FILE *file = fopen("output.pdf", "wb");
    if (file == NULL) {
        ironpress_buffer_free(&pdf);
        return 1;
    }
    fwrite(ironpress_buffer_data(pdf), 1, ironpress_buffer_len(pdf), file);
    fclose(file);
    ironpress_buffer_free(&pdf);
    return 0;
}
Ownership rule

Initialize every output handle to null. Free it through its matching function, which also clears the handle.

Render Markdown

Markdown uses the same owned buffer and error contract:

const char *source = "# Release notes\n\nEverything shipped.";
IronpressBytes markdown = {(const uint8_t *)source, strlen(source)};
IronpressStatus status = ironpress_markdown_to_pdf(
    markdown, &pdf, &error
);

Reuse a configured converter

Create one converter, configure it while idle, and reuse it for multiple documents.

IronpressConverter *converter = NULL;
ironpress_converter_new(&converter, &error);
ironpress_converter_set_page_size(
    converter, IRONPRESS_PAGE_SIZE_LETTER, &error
);
ironpress_converter_set_margin(converter, 36.0f, &error);
ironpress_converter_set_compress(converter, IRONPRESS_TRUE, &error);

ironpress_converter_convert_html(converter, html, &pdf, &error);
ironpress_buffer_free(&pdf);
ironpress_converter_free(&converter);

Provide fonts as bytes

The C ABI does not read document paths or access the network. Your application may read a TrueType font or optional CJK or emoji pack, then pass its bytes to the converter.

Input ranges are borrowed only for the duration of the call. The converter copies custom fonts and takes its own parsed font-pack value.

Handle failures and runtime limits

Every fallible function returns a stable status. An optional owned error adds a UTF-8 diagnostic. Rust panics are contained before they reach C.

  • HTML sanitization is enabled by default.
  • Converters must not be used or freed concurrently.
  • Local paths, direct file output, async, streaming, and remote HTTP are absent.
  • Check ironpress_abi_version() before depending on a new ABI generation.

Go further