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 converts Word documents (.docx) to PDF files, and can optionally generate PDF bookmarks and output only selected pages. The feature is provided by [CPDFConversion startWordToPDF:outputPath:options:] and shares WordOptions with PDF to Word; only wordPdfBookmarkMode and pageRanges take effect for Word to PDF, and the other properties are ignored. Word to PDF does not depend on any AI model.
CPDFConversion provides the following startWordToPDF methods:
// Default options.
+ (ErrorCode)startWordToPDF:(NSString *)filePath outputPath:(NSString *)outputPath;
// Bookmark and page range options.
+ (ErrorCode)startWordToPDF:(NSString *)filePath outputPath:(NSString *)outputPath
options:(WordOptions *)options;
// Progress and cancellation through blocks, or through a ConvertCallback object.
+ (ErrorCode)startWordToPDF:(NSString *)filePath outputPath:(NSString *)outputPath
options:(WordOptions *)options
progress:(COMProgressBlock)progress cancel:(COMCancelBlock)cancel;
+ (ErrorCode)startWordToPDF:(NSString *)filePath outputPath:(NSString *)outputPath
options:(WordOptions *)options callback:(id<ConvertCallback>)callback;
// Also returns the diagnostic information.
+ (ErrorCode)startWordToPDF:(NSString *)filePath outputPath:(NSString *)outputPath
options:(WordOptions *)options
progress:(COMProgressBlock)progress cancel:(COMCancelBlock)cancel
diagnostics:(NSString **)diagnostics;| Parameter | Meaning |
|---|---|
filePath | Path of the input Word document |
outputPath | Path of the output PDF |
options | Conversion options; Word to PDF uses only their wordPdfBookmarkMode and pageRanges, see below |
progress / cancel / callback | Optional, used to get the conversion progress and cancel the conversion |
diagnostics | Optional, receives the diagnostic information; pass nil if not needed |
Word to PDF uses only the following properties of WordOptions:
| Field | Default | Meaning |
|---|---|---|
wordPdfBookmarkMode | WordPdfBookmarkModeNone | How PDF bookmarks (the outline shown in a reader's navigation panel) are generated |
pageRanges | Empty | Pages to output, e.g. "1-3,5,7-9"; empty outputs every page |
Values of WordPdfBookmarkMode:
| Value | Meaning |
|---|---|
WordPdfBookmarkModeNone | No bookmarks |
WordPdfBookmarkModeHeadings | One bookmark per heading (a paragraph with an outline level), nested by level |
WordPdfBookmarkModeWordBookmarks | One bookmark per Word bookmark, with the same name as in the Word document |
ErrorCodeUnsupportedFeature (95) is returned. The PDF is usually still produced in this case, so do not assume that no output file exists just because 95 is returned.Pass the address of an NSString * as diagnostics to receive the diagnostic text, or nil if you do not need it. The SDK manages the 8192-byte buffer itself.
output=produced when the PDF was produced, or output=not_produced when no complete PDF was produced.ErrorCodeOutOfMemory is returned; the text is never truncated.// Default options.
ErrorCode code = [CPDFConversion startWordToPDF:@"input.docx" outputPath:@"path/output.pdf"];
// Generate bookmarks from headings, output pages 1-3, 5 and 7-9, and get diagnostics.
WordOptions *options = [[WordOptions alloc] init];
options.wordPdfBookmarkMode = WordPdfBookmarkModeHeadings;
options.pageRanges = @"1-3,5,7-9";
NSString *diagnostics = nil;
code = [CPDFConversion startWordToPDF:@"input.docx"
outputPath:@"path/output.pdf"
options:options
progress:nil
cancel:nil
diagnostics:&diagnostics];
if (code == ErrorCodeUnsupportedFeature) {
// The document contains features that may affect fidelity. The PDF is usually still produced;
// check output=produced / output=not_produced on the first line of the diagnostic text.
NSLog(@"%@", diagnostics);
} else if (code != ErrorCodeSuccess) {
// The conversion failed.
}