onepdf-html converts in both directions. Install it as a .NET tool:
dotnet tool install -g RecursiveAI.OnePdf.Html.ToolThe tool installs as a native executable on linux-x64, linux-arm64, osx-arm64 and win-x64 (no .NET runtime is started, so a short document converts in tens of milliseconds) and as a framework-dependent package on every other platform. The output is byte-identical either way.
Which direction
The direction follows the input: a .pdf file becomes HTML; a .html, .htm or .xhtml file, a URL (http:// or https://) or standard input (-, anything that does not start with %PDF) becomes a PDF. To say it explicitly, put to-html or to-pdf first:
onepdf-html report.pdf onepdf-html to-html report.pdf --mode fixed onepdf-html to-pdf page.html -o page.pdf
--help and -h print the text below, --version prints the version. With no arguments the tool prints the help and exits with code 2.
Help text
This block is the tool's own --help output; a test fails if it differs, so it cannot drift.
onepdf-html: convert between PDF and HTML. onepdf-html [to-html] <input.pdf|-> [-o <output>] [options] Converts a PDF to HTML. Without -o the output is <input>.html beside the input (with --per-page, the directory <input>_pages). '-o -' writes one document to standard output. -m, --mode semantic|fixed reflowing text (default) or fixed-layout pages --pages 1-3,7,10- pages to convert, one-based (default: all) --password <text> password of an encrypted PDF --per-page one HTML file per page in a directory, plus index.html --assets inline|files images inside the HTML (default) or as files beside it --dpi <n> resolution of the fixed-layout page picture (default 144) --zoom <x> scale of fixed-layout pages (default 1) --lazy draw fixed-layout pages only when they scroll into view --fonts web|css fixed layout: web fonts built from the PDF's glyphs (default) or CSS font families by name --ocr auto|always|never recognise text from the page picture: only where a page has no usable text (default), on every page, or never --ocr-lang <tags> the document's languages, e.g. en,de or ja (default: the recogniser decides per line) -j, --parallel <n> pages converted at once (default: up to 4) -v, --verbose list every diagnostic; -q, --quiet: no summary onepdf-html to-pdf <input.html|URL|-> [-o <output.pdf|dir|->] [options] Converts HTML (a file, an http(s) URL or standard input) to a tagged PDF. Several input files need -o <directory>. Page: --page-size A4|A3|A5|B5|Letter|Legal|Tabloid|<W>x<H>[mm|cm|in|pt|px] --landscape --portrait --margin <len> --margins <top,right,bottom,left> (lengths take mm, cm, in, pt or px; default px) Running: --header <text> --header-left <text> --header-right <text> --footer <text> --footer-left <text> --footer-right <text> --page-numbers (footer "Page N of M") --header-style <css> --footer-style <css> --header-html <file> --footer-html <file> (an HTML template across the page area; images load like the document's) In a text, <span class="pageNumber"></span>, <span class="totalPages"></span> and <span class="title"></span> are replaced. Output: --links web|internal|all|none (default web) --no-outline --no-tags --profile ua1|a2a|a2a-ua1 --title <t> --author <a> --subject <s> --keywords <k> --language <bcp47> --date <ISO 8601> --no-compress Resources: --root <dir> (where relative files may be read; default the input's folder) --network (allow http/https resources) --allow-private (allow loopback and private addresses) --timeout <seconds> --max-resource-mb <n> --max-resources <n> Other: -j <n> parallel conversions for several inputs -v list diagnostics -q quiet The direction follows the input: .pdf files become HTML; .html, .htm, URLs and standard input become PDF. Exit codes: 0 done, 1 failed, 2 usage, 3 password needed, 130 cancelled.
PDF to HTML (to-html)
Every option maps to a property of PdfHtmlOptions (guide).
| Option | Property | Notes |
|---|---|---|
-o, --output <path> | Without it, <input>.html beside the input; with --per-page, the directory <input>_pages. -o - writes one document to standard output. | |
-m, --mode semantic|fixed | Mode | Reflowing text (default) or fixed-layout pages. |
--pages <ranges> | PageRanges | One-based, such as 1-3,7,10-. |
--password <text> | Password | |
--per-page | Layout = PagePerFile | One HTML file per page in a directory, plus index.html. |
--assets inline|files | Assets | Images and fonts inside the HTML (default) or as files beside it: <output>_files/ for one file, assets/ in the per-page directory. |
--dpi <n> | RasterDpi | 36 to 600, default 144. |
--zoom <x> | Zoom | 0.1 to 10, default 1. |
--lazy | LazyPages | |
--fonts web|css | Fonts | Web fonts built from the PDF's glyphs (default) or CSS font families by name. |
--ocr auto|always|never | TextSource | auto (default) recognises text only where a page has none usable; never uses the PDF's own text everywhere. |
--ocr-lang <tags> | OcrTextSourceOptions.Languages | Comma-separated BCP 47 tags, such as en,de or ja. The tool includes the Latin, Greek, Cyrillic, CJK, Arabic, Hebrew and Indic models. |
-j, --parallel <n> | MaxDegreeOfParallelism | Pages converted at once. |
-v, --verbose | Prints every diagnostic to standard error. | |
-q, --quiet | No summary line. |
The options for headers and footers, form fields, page boundaries, annotations, limits and font mapping have no flag; use the library for those.
Standard input (-) needs -o <output>.
onepdf-html report.pdf # report.html, reflowing onepdf-html report.pdf --mode fixed --lazy -o book.html onepdf-html report.pdf --per-page --assets files --pages 1-5 onepdf-html scan.pdf --ocr always --ocr-lang en,de onepdf-html locked.pdf --password secret -o - # to standard output cat report.pdf | onepdf-html - -o report.html
HTML to PDF (to-pdf)
Every option maps to a property of HtmlToPdfOptions (guide).
| Option | Property | Notes |
|---|---|---|
-o, --output <path> | A file, or a directory when there are several inputs. Without it, <input>.pdf beside the input, or <host>.pdf in the current folder for a URL. -o - writes the PDF to standard output. | |
--page-size <size> | PageSize | A4, A3, A5, B5, Letter, Legal, Tabloid, or <W>x<H> with an optional unit (210x297mm, 8.5x11in). |
--landscape, --portrait | Orientation | |
--margin <len> | Margins | One length for every side. Units are mm, cm, in, pt or px; a bare number is px. |
--margins <t,r,b,l> | Margins | Four lengths: top, right, bottom, left. |
--header, --header-left, --header-right, --footer, --footer-left, --footer-right <text> | Header, Footer | A template for the centre, left or right of the margin. In a text, <span class="pageNumber"></span>, <span class="totalPages"></span> and <span class="title"></span> are replaced. |
--page-numbers | Footer | A footer reading "Page N of M". |
--header-style, --footer-style <css> | HtmlHeaderFooter.Style | CSS declarations for the text. |
--header-html, --footer-html <file> | HtmlHeaderFooter.Html | An HTML template across the page area; its images load like the document's. |
--links web|internal|all|none | Links | Default web. |
--no-outline | Outline = null | |
--no-tags | Tagged = false | |
--profile ua1|a2a|a2a-ua1 | Profile | PDF/UA-1, PDF/A-2a, or both. |
--title, --author, --subject, --keywords, --language | metadata | |
--date <ISO 8601> | CreationDate | Written only when given. |
--no-compress | Compress = false | |
--root <dir> | Where relative files may be read; default the input's folder. | |
--network | Network.Enabled | Allow http/https resources. A URL input always fetches. |
--allow-private | Network.AllowPrivateAddresses | Allow loopback and private addresses. |
--timeout <seconds> | Network.RequestTimeout | |
--max-resource-mb <n> | Limits.MaxResourceBytes | |
--max-resources <n> | Limits.MaxResources | |
-j <n>, --parallel <n> | MaxDegreeOfParallelism | Parallel conversions for several inputs. |
-v, -q | Print every diagnostic; no summary line. |
Several input files need -o <directory>. Standard input needs -o <output.pdf>.
onepdf-html page.html # page.pdf onepdf-html https://example.org/ -o page.pdf --page-size A4 --landscape --page-numbers --profile ua1 onepdf-html a.html b.html -o out/ -j 4 onepdf-html page.html --margins 25mm,15mm,25mm,15mm --header-left "Quarterly report" --page-numbers onepdf-html page.html --title Report --language en --profile a2a-ua1 cat page.html | onepdf-html - -o page.pdf
Exit codes
| Code | Meaning |
|---|---|
| 0 | Done. Diagnostics, if any, are counted in the summary line (-v lists them). |
| 1 | The conversion failed: an unreadable or damaged input, a limit, a file or network error, a profile violation. |
| 2 | Usage: an unknown option, a missing value or input, an unreadable template. Nothing was converted. |
| 3 | The PDF is encrypted and the password is missing or wrong (--password). |
| 130 | Cancelled (Ctrl+C). Files the conversion had started are removed. |
The summary and diagnostics go to standard error, so -o - can be piped.