Recursive AI

Command-line reference

All onepdf-html docs

onepdf-html converts in both directions. Install it as a .NET tool:

dotnet tool install -g RecursiveAI.OnePdf.Html.Tool

The 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.

Text
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).

OptionPropertyNotes
-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|fixedModeReflowing text (default) or fixed-layout pages.
--pages <ranges>PageRangesOne-based, such as 1-3,7,10-.
--password <text>Password
--per-pageLayout = PagePerFileOne HTML file per page in a directory, plus index.html.
--assets inline|filesAssetsImages and fonts inside the HTML (default) or as files beside it: <output>_files/ for one file, assets/ in the per-page directory.
--dpi <n>RasterDpi36 to 600, default 144.
--zoom <x>Zoom0.1 to 10, default 1.
--lazyLazyPages
--fonts web|cssFontsWeb fonts built from the PDF's glyphs (default) or CSS font families by name.
--ocr auto|always|neverTextSourceauto (default) recognises text only where a page has none usable; never uses the PDF's own text everywhere.
--ocr-lang <tags>OcrTextSourceOptions.LanguagesComma-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>MaxDegreeOfParallelismPages converted at once.
-v, --verbosePrints every diagnostic to standard error.
-q, --quietNo 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).

OptionPropertyNotes
-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>PageSizeA4, A3, A5, B5, Letter, Legal, Tabloid, or <W>x<H> with an optional unit (210x297mm, 8.5x11in).
--landscape, --portraitOrientation
--margin <len>MarginsOne length for every side. Units are mm, cm, in, pt or px; a bare number is px.
--margins <t,r,b,l>MarginsFour lengths: top, right, bottom, left.
--header, --header-left, --header-right, --footer, --footer-left, --footer-right <text>Header, FooterA 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-numbersFooterA footer reading "Page N of M".
--header-style, --footer-style <css>HtmlHeaderFooter.StyleCSS declarations for the text.
--header-html, --footer-html <file>HtmlHeaderFooter.HtmlAn HTML template across the page area; its images load like the document's.
--links web|internal|all|noneLinksDefault web.
--no-outlineOutline = null
--no-tagsTagged = false
--profile ua1|a2a|a2a-ua1ProfilePDF/UA-1, PDF/A-2a, or both.
--title, --author, --subject, --keywords, --languagemetadata
--date <ISO 8601>CreationDateWritten only when given.
--no-compressCompress = false
--root <dir>Where relative files may be read; default the input's folder.
--networkNetwork.EnabledAllow http/https resources. A URL input always fetches.
--allow-privateNetwork.AllowPrivateAddressesAllow loopback and private addresses.
--timeout <seconds>Network.RequestTimeout
--max-resource-mb <n>Limits.MaxResourceBytes
--max-resources <n>Limits.MaxResources
-j <n>, --parallel <n>MaxDegreeOfParallelismParallel conversions for several inputs.
-v, -qPrint 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

CodeMeaning
0Done. Diagnostics, if any, are counted in the summary line (-v lists them).
1The conversion failed: an unreadable or damaged input, a limit, a file or network error, a profile violation.
2Usage: an unknown option, a missing value or input, an unreadable template. Nothing was converted.
3The PDF is encrypted and the password is missing or wrong (--password).
130Cancelled (Ctrl+C). Files the conversion had started are removed.

The summary and diagnostics go to standard error, so -o - can be piped.