Gets supported conversions for provided document extension
Examples
Basic conversion from file path:
// Convert DOCX to PDFusing(varconverter=newConverter("sample.docx")){varoptions=newPdfConvertOptions();converter.Convert("output.pdf",options);}
Conversion with custom options:
// Convert DOCX to PDF with watermark and specific page rangeusing(varconverter=newConverter("sample.docx")){varoptions=newPdfConvertOptions{PageNumber=1,PagesCount=3,Watermark=newWatermarkTextOptions("CONFIDENTIAL"){Color=System.Drawing.Color.Red,Width=300,Height=100}};converter.Convert("output.pdf",options);}
Conversion from stream:
// Convert document from stream to streamusing(varsourceStream=File.OpenRead("sample.docx"))using(varconverter=newConverter(()=>sourceStream))using(varoutputStream=File.Create("output.pdf")){varoptions=newPdfConvertOptions();converter.Convert((SaveContextcontext)=>outputStream,options);}
Conversion with load options (password-protected document):
// Load password-protected document and convert to PDFvarloadOptions=newWordProcessingLoadOptions{Password="secret_password"};using(varconverter=newConverter("protected.docx",(LoadContextcontext)=>loadOptions)){varconvertOptions=newPdfConvertOptions();converter.Convert("output.pdf",convertOptions);}
Page-by-page conversion:
// Convert document pages to separate image filesusing(varconverter=newConverter("sample.pdf")){varoptions=newImageConvertOptions{Format=ImageFileType.Png};converter.Convert((SavePageContextcontext)=>File.Create($"page-{context.Page}.png"),options);}
// Aggregate all event handlers in a ConversionEvents bag and pass it to the Converter.varevents=newConversionEvents{OnDocumentConverted=ctx=>Console.WriteLine($"Done: {ctx.SourceFileName}"),OnDocumentFailed=(ctx,ex)=>Console.Error.WriteLine($"Conversion of {ctx.SourceFileName} failed: {ex.Message}"),OnPageFailed=(ctx,ex)=>Console.Error.WriteLine($"Page {ctx.Page} of {ctx.SourceFileName} failed: {ex.Message}"),};using(varconverter=newConverter("sample.docx",()=>newConverterSettings(),()=>events)){converter.Convert("output.pdf",newPdfConvertOptions());}
The flat OnConversionFailed, OnConversionByPageFailed, and OnCompressionCompleted properties on ConverterSettings still work but are obsolete; new code should pass a ConversionEvents instance via the events constructor parameter.
Get document information:
// Retrieve document metadata before conversionusing(varconverter=newConverter("sample.docx")){varinfo=converter.GetDocumentInfo();Console.WriteLine($"Document has {info.PagesCount} pages");Console.WriteLine($"Format: {info.Format}");Console.WriteLine($"Size: {info.Size} bytes");}