Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Convert PDF to OFD ​

Overview ​

ComPDF Conversion SDK supports converting PDF documents to OFD documents. Similar to searchable PDF, OFD conversion also supports OCR, page background preservation, and transparent text layers.

Conversion Options ​

This format uses only the following options of ConvertOptions; the other options have no effect:

OptionDefaultMeaning
enable_ocrfalseThe text layer comes from OCR on the pages chosen by ocr_option; when off, it comes from the text of the PDF. Image input without OCR has no text layer. Ignored if the license does not include OCR.
ocr_optionOCROption::e_AllWhich content OCR handles: OCROption::e_All every page; OCROption::e_ScanPage only image (scanned) pages; OCROption::e_InvalidCharacter re-recognizes unreadable characters of the text layer on the other pages; OCROption::e_InvalidCharacterAndScanPage both. Only takes effect when enable_ocr is on.
languages / language_countlanguage_count = 0OCR recognition languages; when no language is given, English is used. Only takes effect when enable_ocr is on.
enable_document_orientation_classificationfalseTurns the page image upright before OCR; the page size follows the rotation. Only takes effect when enable_ocr is on.
enable_document_dewarpfalseFlattens curved or warped page photos before OCR. Only takes effect when enable_ocr is on.
page_rangesEmptyPages to convert, e.g. "1-3,5,7-9"; empty converts every page. For multi-frame image input it selects the frames.
enable_ai_layouttrueOnly changes how the invisible text of pages not recognized by OCR is grouped, and the header and footer detection; the visible page image is not affected.
formula_to_imagetrueWhen on, the text of formulas found by AI layout analysis is removed from the invisible text layer (it can no longer be copied or searched); turn it off to keep it. The page image is unchanged. Only for pages not recognized by OCR, with enable_ai_layout on.
output_document_per_pagefalseWrites one file per page instead of one document. The files are named after the input file plus the page number and are written to the folder of the output path; the file name in the output path is not used.
enable_auto_page_sizefalseImage input only: sizes the page from the image resolution, matched to the nearest standard paper size; when off, one image pixel becomes one point.
custom_page_width / custom_page_height0Image input only: exact page width and height in points (1 pt = 1/72 inch); both must be greater than 0. The image is fitted inside with white padding. Takes precedence over enable_auto_page_size.

Example:

cpp
ConvertOptions opt;
opt.enable_ocr = true;
opt.enable_document_orientation_classification = true;
opt.output_document_per_page = true;
CPDFConversion::StartPDFToOfd("input.pdf", "password", "path/output.ofd", opt);

Notice ​

  • If you need to generate searchable OFD output, you can enable transparent_text.
  • When enable_ocr is enabled, it is recommended to specify the OCR language through languages.

Sample ​

c++
LibraryManager::SetDocumentAIModel("path/documentai.model");

ConvertOptions opt;
opt.enable_ocr = true;
opt.languages = {OCRLanguage::e_English};
opt.contain_page_background_image = true;
opt.transparent_text = true;
CPDFConversion::StartPDFToOfd("scan.pdf", "password", "path/output.ofd", opt);