Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pass your in-memory HTML string as the third argument to wkhtmltopdf_add_object, then call wkhtmltopdf_convert to generate the PDF. The string must be UTF-8. You can write the result to a configured output path or retrieve PDF bytes with wkhtmltopdf_get_output.

How the C API accepts an HTML string

The PDF bindings in pdf.h let an application provide HTML directly as data; you do not have to save the markup to a temporary file first. Create an object settings structure and pass the HTML bytes as the third argument to wkhtmltopdf_add_object. When that argument is non-null and non-empty, the API uses it instead of the content identified by the object’s page setting.

Adding an object only registers input. It does not create a PDF. The conversion happens when you call wkhtmltopdf_convert. The converter can contain one or more objects, which are included in their addition order.

Conversion lifecycle

  1. Initialize the library. Call wkhtmltopdf_init before calling other library functions.
  2. Create global settings. Use wkhtmltopdf_create_global_settings. Set document-wide options with wkhtmltopdf_set_global_setting, including out if you want the library to write directly to a file.
  3. Create the converter and object settings. Create a converter from the global settings, then create object settings and set options that apply to the HTML object.
  4. Register the HTML. Call wkhtmltopdf_add_object(converter, object_settings, html_utf8). The third argument is the in-memory HTML string encoded as UTF-8.
  5. Convert. Call wkhtmltopdf_convert and check its return value. Install the API’s callback handlers if your application needs progress, warning, error, or completion reporting.
  6. Collect the result. Use the configured output destination, or leave it empty and retrieve the generated data with wkhtmltopdf_get_output after conversion.
  7. Clean up. Destroy the converter and settings according to the ownership rules in the header for the exact version you build against. Call wkhtmltopdf_deinit when the process no longer needs the library.

The project describes pdf.h as its recommended C interface to the PDF functionality. The exact declarations and ownership rules should come from the pdf.h shipped with your installed library, not a header from a different package or fork.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
  • Convert your PDF files into Word, Excel & Co. the easy way
  • Convert scanned documents thanks to our new 2022 OCR technology
  • Adjustable conversion settings
  • No subscription! Lifetime license!
  • Compatible with Windows 11, 10, 8.1, 7 - Internet connection required

Minimal C integration pattern

The following shows the essential call order. Use the declarations and cleanup functions from the pdf.h that accompanies your build; distribution packages can differ, and the API reference should be treated as authoritative for those details. The HTML is deliberately a UTF-8 string literal, so no file is involved in supplying the document.

#include <stdio.h>
#include <stddef.h>
#include "pdf.h"

int main(void) {
    const char html[] =
        "<!doctype html>"
        "<html><head><meta charset="utf-8">"
        "<title>Example</title></head>"
        "<body><h1>Hello from memory</h1>"
        "<p>This HTML is passed directly to the PDF API.</p>"
        "</body></html>";

    /* Initialize before any other libwkhtmltox call. */
    if (!wkhtmltopdf_init(0)) {
        fputs("wkhtmltopdf initialization failedn", stderr);
        return 1;
    }

    wkhtmltopdf_global_settings *global =
        wkhtmltopdf_create_global_settings();
    if (!global) {
        fputs("Could not create global settingsn", stderr);
        wkhtmltopdf_deinit();
        return 1;
    }

    /* Set the output path; verify setting names and return handling in pdf.h. */
    wkhtmltopdf_set_global_setting(global, "out", "output.pdf");

    wkhtmltopdf_converter *converter =
        wkhtmltopdf_create_converter(global);
    if (!converter) {
        fputs("Could not create convertern", stderr);
        /* Destroy settings using the ownership rules in your pdf.h. */
        wkhtmltopdf_deinit();
        return 1;
    }

    wkhtmltopdf_object_settings *object =
        wkhtmltopdf_create_object_settings();
    if (!object) {
        fputs("Could not create object settingsn", stderr);
        /* Destroy converter/settings using the ownership rules in your pdf.h. */
        wkhtmltopdf_deinit();
        return 1;
    }

    wkhtmltopdf_add_object(converter, object, html);

    if (!wkhtmltopdf_convert(converter)) {
        fputs("PDF conversion failedn", stderr);
        /* Destroy converter and settings using the ownership rules in pdf.h. */
        wkhtmltopdf_deinit();
        return 1;
    }

    /* Destroy converter and settings using the ownership rules in pdf.h. */
    wkhtmltopdf_deinit();
    return 0;
}

This is an integration pattern rather than a universal drop-in source file: the supplied API material establishes the conversion calls and order but does not spell out every type declaration, destroy-function name, or ownership detail for every binary package. Resolve those from the matching header before compiling. Check return values for settings operations where the installed API exposes them, and add cleanup on every error path using that package’s documented ownership rules.

Writing directly to a PDF file

Set the global out setting to a destination path before creating and converting the document. This is suitable when the caller needs a filesystem artifact. Ensure the application can write to that location and handle conversion failure before treating the file as complete.

Retrieving PDF bytes in memory

Leave the output destination empty and retrieve the generated data with wkhtmltopdf_get_output after a successful conversion. This fits applications that need to send the PDF to another component or store it without choosing a local output file. Consult the documentation for the exact build to determine the returned buffer’s lifetime and ownership; copy it before it becomes invalid if your application needs to retain it.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.

UTF-8, resources, and rendering behavior

The API’s HTML data argument is UTF-8. If the source string uses another encoding, convert it before calling wkhtmltopdf_add_object; declaring a charset in the markup does not change the encoding of bytes already passed to the library.

HTML may reference images, stylesheets, fonts, scripts, or other resources. Those resources need paths or URLs that the renderer can access in the runtime environment. Whether relative paths resolve as intended, whether remote resources load, and whether a particular CSS or JavaScript feature renders correctly depend on the installed build and object settings. Test the content and resource paths that matter to your application using the precise library package deployed in production.

Because conversion may load external resources, treat both the HTML and its referenced URLs as security inputs when accepting untrusted content. Apply restrictions appropriate to your service and environment. The API overview does not prescribe a universal safe policy for untrusted HTML or network access.

Choosing the input and output path

Choice Use it when Implementation consideration
In-memory HTML via data The document is already available as a UTF-8 string. Non-empty data takes precedence over the object’s page setting.
Object page setting The content should be identified by a page URL or path instead of supplied HTML data. Resource access and page navigation depend on the runtime environment and settings.
Configured output destination The application needs a PDF file at a known path. Set global out before conversion and handle filesystem errors.
wkhtmltopdf_get_output The application needs PDF bytes rather than a file written directly by the library. Confirm buffer lifetime and ownership against the exact API version.

The API documentation supports both output routes; it does not establish that one is faster or more reliable in every application. Choose based on whether your caller needs a file or bytes and how you will manage storage, buffer lifetime, and error reporting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.

Version and deployment checks

wkhtmltopdf uses the Qt WebKit rendering engine. Its repository was archived on January 2, 2023, so the project’s API documentation does not establish identical behavior across every package, later fork, operating system build, or Qt configuration. Before deploying, identify the version and Qt build of the library actually linked by your application, check how that package was produced, and test representative HTML, styles, scripts, and external resources.

  • Build against the pdf.h that corresponds to the linked library.
  • Confirm that the target environment has access to required local files and remote resources.
  • Exercise both successful conversion and failure paths; use callbacks and conversion-status functions for diagnostics where appropriate.
  • Verify the generated file or retrieved bytes before passing them downstream.

Troubleshooting common failures

Initialization fails

Call wkhtmltopdf_init before every other library function and check its return value. Confirm that the runtime can load the intended library and that the binary and its dependencies match the environment.

The PDF is empty or does not contain the supplied markup

Check that the third argument to wkhtmltopdf_add_object is non-null and points to a non-empty, valid UTF-8 string. Empty data does not replace the object’s page setting. Also verify that you call wkhtmltopdf_convert; adding the object alone is not conversion.

Characters are corrupted

Encode the bytes as UTF-8 before passing them as data. Validate the actual byte sequence rather than relying only on an HTML charset declaration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.

Images, fonts, or styles are missing

Check whether each referenced resource resolves from the converter’s runtime context, whether the process has the necessary filesystem or network access, and whether the relevant object settings permit the required behavior. Validate against the exact deployed build.

Conversion reports failure

Check the return value from wkhtmltopdf_convert. Register error and warning callbacks, along with progress or completion callbacks if useful, and record their output. Distinguish a failed conversion from a successful one before reading output bytes or serving a file.

Output bytes disappear or cannot be used later

For the in-memory path, consult the matching API documentation for the returned buffer’s ownership and lifetime. Copy the data while it is valid if it must outlive the converter or the documented validity period.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your input is a public webpage rather than an HTML string already in memory, ScreenshotNeo offers a one-request screenshot or PDF API. It does not take the place of wkhtmltopdf_add_object for converting an arbitrary in-memory string. The example below captures a URL; see the ScreenshotNeo API documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
  • ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
  • MAXIMUM FUNCIONALITY – create interactive forms, compare PDFs, bates numbering, find and replace text or colors, convert documents, OCR engine, comment, highlight, fill out and print forms, document protection and others
  • EASY TO INSTALL AND USE – well-structured user-interface, in-program instructions, free tech support whenever you need it
  • GREAT VALUE FOR MONEY - why spend a fortune if you can have maximum functionality at a reasonable price - this also fits the requirements of companies very well
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and responses indicate the page verdict and billing status. Its MCP server provides screenshot, page-info, and PDF-capture tools for AI agents. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Frequently Asked Questions

Can one converter produce a PDF containing multiple HTML documents?

Yes. The API documentation allows one or more objects to be added to a converter; their inclusion order follows the order in which they are added.

Does the wkhtmltox C API guarantee support for current browser features?

No. It uses Qt WebKit, and the archived project documentation does not establish modern-browser compatibility. Test the specific features and build you plan to deploy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
Convert your PDF files into Word, Excel & Co. the easy way; Convert scanned documents thanks to our new 2022 OCR technology
$29.99
Bestseller No. 2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.
Bestseller No. 3
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 4
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99
Bestseller No. 5
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
$29.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.