PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
ComPDF Conversion SDK supports converting Word documents to PDF files. You can choose to generate PDF bookmarks, or to output only specific pages.
string inputFilePath = "***";
string outputFileName = "***";
ErrorCode error = CPDFConversion.StartWordToPDF(inputFilePath, outputFileName);Word to PDF reuses WordOptions; only WordPdfBookmarkMode (how bookmarks are generated) and PageRanges (which pages are output) take effect, and the other settings are ignored:
| Option | Type | Default | Description |
|---|---|---|---|
WordPdfBookmarkMode | WordPdfBookmarkMode | e_None | How PDF bookmarks (the table of contents in a reader's navigation pane) are generated |
PageRanges | string | empty | The pages to output, for example "1-3,5,7-9"; empty outputs all pages |
Values of WordPdfBookmarkMode:
| Value | Description |
|---|---|
e_None | Do not generate bookmarks |
e_Headings | One bookmark per heading (a paragraph with an outline level), nested by level |
e_WordBookmarks | One bookmark per Word bookmark, named after the Word bookmark |
WordOptions options = new WordOptions();
options.WordPdfBookmarkMode = WordPdfBookmarkMode.e_Headings;
options.PageRanges = "1-3,5,7-9";
ErrorCode error = CPDFConversion.StartWordToPDF(inputFilePath, outputFileName, options);As with the other conversion interfaces, use ConvertCallback to get progress or to cancel the conversion:
OnProgress getProgress = (pageIndex, total) =>
{
// Add callback function code here.
};
ConvertCallback callback = new ConvertCallback();
callback.progress = Marshal.GetFunctionPointerForDelegate(getProgress);
ErrorCode error = CPDFConversion.StartWordToPDF(inputFilePath, outputFileName, options, callback);When the document contains features that may affect fidelity, the conversion returns ErrorCode.e_ErrUnsupportedFeature (95). The PDF is usually still generated in this case. Use the overload with the out string diagnostics parameter to get the diagnostic text:
string diagnostics;
ErrorCode error = CPDFConversion.StartWordToPDF(inputFilePath, outputFileName, options, out diagnostics);
if (error == ErrorCode.e_ErrUnsupportedFeature)
{
// The first line is either output=produced or output=not_produced.
Console.WriteLine(diagnostics);
}output=produced means a PDF was generated, and output=not_produced means no complete PDF was generated.ruby:unsupported ruby layout. The same feature is reported only once per conversion.ErrorCode.e_ErrOutOfMemory is returned; the diagnostics are never truncated.