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 Word to PDF ​

Overview ​

ComPDF Conversion SDK supports converting Word documents to PDF files. During conversion you can choose to generate PDF bookmarks, output only specific pages. This function is provided by Conversion::wordToPdf. Its options are set through ConvertOption, the same structure used for PDF conversion; only wordPdfBookmarkMode and pageRanges take effect for Word to PDF, and the other members are ignored.

Conversion::wordToPdf(string $in, string $out, ?ConvertOption $opt = null, ?ConvertCallback $cb = null): int

Conversion Options ​

Word to PDF uses only the following members of ConvertOption:

FieldTypeDefaultDescription
wordPdfBookmarkModeWordPdfBookmarkModeWordPdfBookmarkMode::NONEHow PDF bookmarks (the outline shown in a reader's navigation panel) are generated
pageRangesstringemptyPages to output, e.g. "1-3,5,7-9"; empty outputs every page

Values of WordPdfBookmarkMode:

ValueDescription
WordPdfBookmarkMode::NONEDo not generate bookmarks
WordPdfBookmarkMode::HEADINGSOne bookmark per heading (a paragraph with an outline level), nested by level
WordPdfBookmarkMode::WORD_BOOKMARKSOne bookmark per Word bookmark, named after it

Return Values and Diagnostics ​

  • Documents containing features that may affect fidelity return UNSUPPORTED_FEATURE (95). The PDF is usually still produced; check the output file.
  • If conversion itself fails, its actual error code takes precedence over 95.
  • This binding does not expose the native diagnostics buffer.

Sample ​

php
$options = new \Conversion\ConvertOption();
$options->wordPdfBookmarkMode = \Conversion\WordPdfBookmarkMode::HEADINGS;
$options->pageRanges = "1-3,5,7-9";
$result = \Conversion\Conversion::wordToPdf("input.docx", "output.pdf", $options);