Skip to content
ComPDF
DemoFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Convert PDF to HTML

Overview

ComPDF Conversion SDK provides the PDF to HTML function, which can convert PDF files to HTML files while maintaining the layout and format of the original document, allowing users to browse and view the document on Web.

Notice

When converting PDF to HTML format, ComPDF Conversion SDK provides the following four options to create HTML files:

OptionDescription
HtmlOption::SINGLE_PAGEConvert the entire PDF file into a single HTML file, where all PDF pages are connected in sequence according to page number, displayed on the same HTML page.
HtmlOption::SINGLE_PAGE_WITH_BOOKMARKConvert the PDF file into a single HTML file with an outline for navigation at the beginning of the HTML page. Still, all PDF pages are connected in sequence according to page number, displayed on the same HTML page.
HtmlOption::MULTI_PAGEConvert the PDF file into multiple HTML files. Each HTML file corresponds to a PDF page, and users can navigate to the next HTML file via a link at the bottom of the HTML page.
HtmlOption::MULTI_PAGE_WITH_BOOKMARKConvert the PDF file into multiple HTML files. Each HTML file corresponds to a PDF page, and users can navigate to the next HTML file via a link at the bottom of the HTML page. The links of all the HTML files are presented in an outline HTML file for navigation.

Sample

This sample demonstrates how to convert from a PDF to HTML file.

php
use ComPDFKit\Conversion\HtmlOption;
use ComPDFKit\Conversion\PageLayoutMode;

$option = new ConvertOption();
// Convert using default options.
Conversion::convert('Html', 'html.pdf', 'password', 'output.html', $option);

// Set the html page display method to HtmlOption::MULTI_PAGE_WITH_BOOKMARK.
$option->pageLayoutMode = PageLayoutMode::BOX;
$option->htmlOption = HtmlOption::MULTI_PAGE_WITH_BOOKMARK;
Conversion::convert('Html', 'html.pdf', 'password', 'output_multi.html', $option);