PDF to HTML Command line Examples

Use these command-line examples for common PDF to HTML tasks. See the CLI guide for installation, input and output handling, and diagnostics.

You can run the examples below without account setup. The CLI uses demo credentials unless you have configured your own API credentials. Update the input URLs and filenames as needed.

Commands use POSIX-shell syntax, as in Bash or Zsh, and save results in the current directory.

Basic examples

These commands save the result with --output. See Handle the Result for output choices and failure handling.

Convert a file

Upload an existing logo.pdf file.

pdf2html --output logo.html \
    logo.pdf

Convert a URL

pdf2html --output invoice.html \
    https://your-server.com/invoice.pdf

Read bytes from stdin

Read logo.pdf through stdin. Use the same - input for bytes piped from another program.

pdf2html --output logo.html \
    - < logo.pdf

Customize the HTML output

These examples upload report.pdf, a document with text, images, and vector graphics.

Convert selected pages

Convert pages 1 and 3 of report.pdf into excerpt.html.

pdf2html --print-page-range=1,3 \
    --output excerpt.html \
    report.pdf

Export HTML with separate assets

Save the HTML, stylesheets, fonts, and images in report.zip. Extract the archive and serve its HTML with the accompanying files, preserving their relative paths.

pdf2html --css-mode=separate \
    --font-mode=separate \
    --force-zip \
    --image-mode=separate \
    --output report.zip \
    report.pdf

Customize the document preview

Scale pages to 75% and change the background, page spacing, and corners in preview.html. Use !important to override the generated background and margin rules.

pdf2html '--custom-css=#page-container { background: #eaf0f6 !important; } .page { margin: 24px auto !important; border-radius: 8px; }' \
    --scale-factor=75 \
    --output preview.html \
    report.pdf

Avoid naming conflicts

Prefix generated IDs, CSS classes, and font names with report_ in namespaced.html. This helps avoid naming conflicts when integrating the converted content into another page; adjust the surrounding layout separately.

pdf2html --html-namespace=report_ \
    --output namespaced.html \
    report.pdf

Reduce image resolution

Render page graphics at 72 DPI instead of the default 144 DPI and save smaller.html. Lower resolution can reduce file size at the cost of image detail; text remains HTML text.

pdf2html --dpi=72 \
    --output smaller.html \
    report.pdf

Preserve vector graphics with SVG

Use SVG for page graphics in vector.html, preserving vector shapes when zooming. Raster images in the PDF remain raster images within the SVG.

pdf2html --image-format=svg \
    --output vector.html \
    report.pdf