PDF Form to HTML

Getting Started

Use Case

Convert PDF Form to HTML to allow filling the Form directly in the browser without need of having PDF Readers installed.

Resources

Integration

The SDK provides two options for integrating into your project using a Command Line Utility or programatically.

Click here to create your free trial license key.

> Command Line

PDFix provides simple and fast automated PDF processing using a command line. PDFix Command Line Utility is the easiest way to integrate the SDK functionality into your solution available for Windows, MacOS and Linux. Learn more about the Command Line Utility.


$ cd /pdfix_mac/bin
$ ./pdfix_app support@pdfix.net 3bE31NaixzFE58ir -pdf2html /Users/admin/Documents/input.pdf output.html

Output:

This converts PDF to HTML , output is the HTML file created during conversion. Click to see available options.

PDF to HTML
Success
{ Code }

These code samples show how to convert the whole PDF document to HTML. Code integration into your project allows you to take full control of the PDF data processing:

#include <string>
#include <iostream>
#include "Pdfix.h"
#include "PdfToHtml.h"
const std::wstring& email, // authorization email
const std::wstring& license_key, // authorization license key
const std::wstring& open_path, // source PDF document
const std::wstring& save_path, // output HTML file
const std::wstring& config_path, // configuration file
PdfHtmlParams& html_params // conversion parameters
) {
// initialize Pdfix
if (!Pdfix_init(Pdfix_MODULE_NAME))
throw std::runtime_error("Pdfix initialization fail");
Pdfix* pdfix = GetPdfix();
if (!pdfix)
throw std::runtime_error("GetPdfix fail");
if (!pdfix->Authorize(email.c_str(), license_key.c_str()))
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
// initialize PdfToHtml
if (!PdfToHtml_init(PdfToHtml_MODULE_NAME))
throw std::runtime_error("PdfToHtml_init fail");
PdfToHtml* pdf_to_html = GetPdfToHtml();
if (!pdf_to_html)
throw std::runtime_error("GetPdfToHtml fail");
std::cout << "PDFix PDF to HTML " << pdf_to_html->GetVersionMajor() << "." <<
pdf_to_html->GetVersionMinor() << "." <<
pdf_to_html->GetVersionPatch() << std::endl;
if (!pdf_to_html->Initialize(pdfix))
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
PdfDoc* doc = pdfix->OpenDoc(open_path.c_str(), L"");
if (!doc)
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
PdfHtmlDoc* html_doc = pdf_to_html->OpenHtmlDoc(doc);
if (!html_doc)
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
//PdfDocTemplate* doc_tmpl = doc->GetDocTemplate();
//if (!doc_tmpl)
// throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
//doc_tmpl->PreflightDoc(nullptr, nullptr);
// customize conversion
if (!config_path.empty()) {
PdfDocTemplate* doc_tmpl = doc->GetDocTemplate();
if (!doc_tmpl)
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
// load from
PsFileStream* stm = pdfix->CreateFileStream(config_path.c_str(), kPsReadOnly);
if (stm) {
if (!doc_tmpl->LoadFromStream(stm, kDataFormatJson))
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
stm->Destroy();
}
}
/* set html_param
html_params.type = kPdfHtmlResponsive;
html_params.width = 1200;
html_params.flags |= kHtmlExportJavaScripts;
html_params.flags |= kHtmlExportFonts;
html_params.flags |= kHtmlRetainFontSize;
html_params.flags |= kHtmlRetainTextColor;
html_params.flags |= kHtmlNoExternalCSS | kHtmlNoExternalJS | kHtmlNoExternalIMG | kHtmlNoExternalFONT;
*/
if (!html_doc->Save(save_path.c_str(), &html_params, nullptr, nullptr))
throw std::runtime_error(std::to_string(GetPdfix()->GetErrorType()));
html_doc->Close();
doc->Close();
pdf_to_html->Destroy();
pdfix->Destroy();
}
using System;
using PDFixSDK.Pdfix;
using PDFixSDK.PdfToHtml;
namespace PDFix.App.Module
{
{
public static void Run(
String email, // authorization email
String licenseKey, // authorization license key
String openPath, // source PDF document
String savePath, // output PDF document
String configPath, // configuration file
PdfHtmlParams htmlParams // html conversion params
)
{
Pdfix pdfix = new Pdfix();
if (pdfix == null)
throw new Exception("Pdfix initialization fail");
if (!pdfix.Authorize(email, licenseKey))
throw new Exception(pdfix.GetError());
PdfToHtml pdfToHtml = new PdfToHtml();
if (pdfToHtml == null)
throw new Exception("PdfToHtml initialization fail");
if (!pdfToHtml.Initialize(pdfix))
throw new Exception(pdfix.GetError());
PdfDoc doc = pdfix.OpenDoc(openPath, "");
if (doc == null)
throw new Exception(pdfix.GetError());
// customize conversion
PsFileStream stm = pdfix.CreateFileStream(configPath, PsFileMode.kPsReadOnly);
if (stm != null)
{
PdfDocTemplate docTmpl = doc.GetDocTemplate();
if (docTmpl == null)
throw new Exception(pdfix.GetError());
if (!docTmpl.LoadFromStream(stm, PsDataFormat.kDataFormatJson))
throw new Exception(pdfix.GetError());
stm.Destroy();
}
// set html conversion params
//htmlParams.type = PdfHtmlType.kPdfHtmlResponsive;
//htmlParams.width = 1200;
//htmlParams.flags |= PdfToHtml.kHtmlExportJavaScripts;
//htmlParams.flags |= PdfToHtml.kHtmlExportFonts;
//htmlParams.flags |= PdfToHtml.kHtmlRetainFontSize;
//htmlParams.flags |= PdfToHtml.kHtmlRetainTextColor;
htmlParams.flags |= PdfToHtml.kHtmlNoExternalCSS | PdfToHtml.kHtmlNoExternalJS |
PdfToHtml.kHtmlNoExternalIMG | PdfToHtml.kHtmlNoExternalFONT;
PdfHtmlDoc htmlDoc = pdfToHtml.OpenHtmlDoc(doc);
if (htmlDoc == null)
throw new Exception(pdfix.GetError());
if (!htmlDoc.Save(savePath, htmlParams, null, IntPtr.Zero))
throw new Exception(pdfix.GetError());
htmlDoc.Close();
doc.Close();
pdfToHtml.Destroy();
pdfix.Destroy();
}
}
}
package net.pdfix.samples;
import net.pdfix.Utils;
import net.pdfix.pdfixlib.*;
import net.pdfix.pdftohtml.*;
public class ConvertToHtml {
public static void run(
String email, // authorization email
String licenseKey, // authorization license key
String openPath, // source PDF document
String savePath, // output HTML file
String configPath, // configuration file
PdfHtmlParams htmlParams
) throws Exception {
System.load(Utils.getAbsolutePath(Utils.getModuleName("pdfix")));
System.load(Utils.getAbsolutePath(Utils.getModuleName("pdf_to_html")));
Pdfix pdfix = new Pdfix();
if (pdfix == null)
throw new Exception("Pdfix initialization fail");
if (!pdfix.Authorize(email, licenseKey))
throw new Exception(pdfix.GetError());
PdfToHtml pdfToHtml = new PdfToHtml();
if (pdfToHtml == null)
throw new Exception("PdfToHtml initialization fail");
System.out.println( pdfToHtml.GetVersionMajor() + "." +
pdfToHtml.GetVersionMinor() + "." + pdfToHtml.GetVersionPatch());
if (!pdfToHtml.Initialize(pdfix))
throw new Exception(pdfix.GetError());
PdfDoc doc = pdfix.OpenDoc(openPath, "");
if (doc == null)
throw new Exception(pdfix.GetError());
// customize conversion
PsFileStream stm = pdfix.CreateFileStream(configPath, PsFileMode.kPsReadOnly);
if (stm != null) {
PdfDocTemplate docTmpl = doc.GetDocTemplate();
if (docTmpl == null)
throw new Exception(pdfix.GetError());
if (!docTmpl.LoadFromStream(stm, PsDataFormat.kDataFormatJson))
throw new Exception(pdfix.GetError());
stm.Destroy();
}
// set htmlParam
//htmlParams.type = PdfHtmlType.kPdfHtmlResponsive;
//htmlParams.width = 1200;
//htmlParams.flags |= PdfToHtml.kHtmlExportJavaScripts;
//htmlParams.flags |= PdfToHtml.kHtmlExportFonts;
//htmlParams.flags |= PdfToHtml.kHtmlRetainFontSize;
//htmlParams.flags |= PdfToHtml.kHtmlRetainTextColor;
//htmlParams.flags |= PdfToHtml.kHtmlNoExternalCSS | PdfToHtml.kHtmlNoExternalJS |
// PdfToHtml.kHtmlNoExternalIMG | PdfToHtml.kHtmlNoExternalFONT;
PdfHtmlDoc htmlDoc = pdfToHtml.OpenHtmlDoc(doc);
if (htmlDoc == null)
throw new Exception(pdfix.GetError());
if (!htmlDoc.Save(savePath, htmlParams))
throw new Exception(pdfix.GetError());
htmlDoc.Close();
doc.Close();
pdfToHtml.Destroy();
pdfix.Destroy();
}
}

Result

Using the PDFix CLI or the provided code snippet, we get the HTML output:

Processing the Form

Submit, Flatten or Sign the the Form directly in web browser and process the PDF on the backend.

Customizing the output

Customize the appearance and functionality by injecting your own JavaScript or CSS directly into HTML and enrich the experience of reading the PDF document. Contact us at support@pdfix.net if you need help with integration.

Windows, MacOS, Linux

Java, Python, C#, C++