File Specific Converters and Conversion Options
DynamicPDF Converter offers multiple converters and conversion options depending upon the file type.
Converter Child Classes
The following are child classes of the Converter
parent class.
- ExcelConverter
HtmlConverter
ImageConverter
PowerPointConverter
RtfConverter
TextConverter
WordConverter
Each has file-type specific methods and properties. Refer to the following pages for more information on each file-specific converter.
- Converting HTML to PDFs
- Converting Images to PDFs
- Converting Text and RTF to PDFs
- Converting Word Documents to PDFs
- Converting PowerPoint Presentations to PDFs
For most processing needs you can use the static Converter.Convert
method rather than one of the specific converters.
ConversionOptions
Use either the ConversionOptions
parent class or one of the file specific conversion option child classes depending on the file type being converted. The ConversionOptions class is parent to the following classes:
ExcelConversionOptions
,HtmlConversionOptions
,ImageConversionOptions
,PowerPointConversionOptions
,RtfConversionOptions
,TextConversionOptions
,TiffConversionOptions
,VisioConversionOptions
, andWordConversionOptions
.
Each file specific options class adds several file specific properties depending upon the file type it handles.
You can also any of the conversion options subclasses with the Converter.Convert
method.
ExcelConversionOptions
The ExcelConversionOptions class adds the CoverSheets, Height, IgnorePrintAreas, Orientation, PageRange, PageScaling, PageSize, and Width properties in addition to the inherited ConversionOption
class's properties.
For more information on ExcelConverter
and ExcelConversionOptions
refer to the Converting Excel Spreadsheets to PDFs documentation.
ExcelConversionOptions options = new ExcelConversionOptions(false);
ExcelConverter excelConverter = new ExcelConverter(@"DocumentA.xlsx", options);
excelConverter.Convert(outputPdf);
Dim options As New ExcelConversionOptions(False)
Dim excelConverter As New ExcelConverter("DocumentA.xlsx", options)
excelConverter.Convert(outputPdf)
HtmlConversionOptions
The HtmlConversionOptions
class adds a Zoom
and DefaultConversionTimeout
property in addition to it's parent ConversionOptions
class's properties.
For more information on HtmlConverter
and HtmlConversionOptions
refer to the Converting HTML to PDFs documentation.
HtmlConversionOptions htmlConversionOptions = new HtmlConversionOptions(480, 720, 36);
HtmlConverter htmlConverter = new HtmlConverter(new Uri("http://www.dynamicpdf.com"),
htmlConversionOptions);
htmlConverter.Convert(outPath);
Dim MyHtmlConversionOptions As HtmlConversionOptions = New HtmlConversionOptions(480,
720, 36)
'Options with HtmlConverter class
Dim MyHtmlConverter As HtmlConverter = New HtmlConverter(New
Uri("http://www.dynamicpdf.com"), MyHtmlConversionOptions)
MyHtmlConverter.Convert(outPath)
ImageConversionOptions & TiffConversionOptions
Use the ImageConversionOptions or TiffConversionOptions class for image conversion.
For more information on ImageConverter
and ImageConversionOptions
refer to the Converting Images to PDFs documentation.
ImageConversionOptions
The ImageConversionOptions
inherits the ConversionOptions
class's properties and adds the ExpandToFit, ImageAlignment, ImageSizeAsPageSize, and ShrinkToFit properties.
ImageConversionOptions imageConversionOptions = new ImageConversionOptions(PageSize.A4,
PageOrientation.Landscape, 36);
imageConversionOptions.ImageSizeAsPageSize = true;
ImageConverter imageConverter = new ImageConverter(inPath, imageConversionOptions);
imageConverter.Convert(outPath);
Dim MyImageConversionOptions As ImageConversionOptions = New ImageConversionOptions(PageSize.A4, PageOrientation.Landscape, 36)
MyImageConversionOptions.ImageSizeAsPageSize = True
Dim MyImageConverter As ImageConverter = New ImageConverter(inPath, MyImageConversionOptions)
MyImageConverter.Convert(outPath)
TiffConversionOptions
The TiffConversionOptions are for Tiff images and inherits from the ImageConversionOptions
class but also adds the additional PageRange property.
TiffConversionOptions tiffConversionOptions = new TiffConversionOptions(500, 500, 12);
tiffConversionOptions.PageRange.StartPageNumber = 2;
tiffConversionOptions.PageRange.EndPageNumber = 5;
ImageConverter imageConverter = new ImageConverter(inPath, tiffConversionOptions);
imageConverter.Convert(outPath);
Dim MyTiffConversionOptions As TiffConversionOptions = New TiffConversionOptions(500, 500, 12)
MyTiffConversionOptions.PageRange.StartPageNumber = 2
MyTiffConversionOptions.PageRange.EndPageNumber = 5
Dim MyImageConverter As ImageConverter = New ImageConverter(inPath, MyTiffConversionOptions)
MyImageConverter.Convert(outPath)
RtfConversionOptions
The RtfConversionOptions class has a PageRange property in addition to the properties it inherits from ConversionOptions
.
For more information on RtfConverter
and RtfConversionOptions
refer to the Converting Text and RTF to PDFs documentation.
RtfConversionOptions rtfConversionOptions = new RtfConversionOptions(PageSize.Letter, PageOrientation.Portrait, 36);
rtfConversionOptions.Title = "RTF Document";
RtfConverter rtfConverter = new RtfConverter(inPath, rtfConversionOptions);
rtfConverter.Convert(outPath);
Dim MyRtfConversionOptions As RtfConversionOptions = New RtfConversionOptions(PageSize.Letter, PageOrientation.Portrait, 36)
MyRtfConversionOptions.Title = "RTF Document"
Dim RtfConverter As RtfConverter = New RtfConverter(inPath, MyRtfConversionOptions)
RtfConverter.Convert(outPath)
TextConversionOptions
The TextConversionOptions class has the PageRange and PrintPageNumbers properties in addition to the properties inherited from ConversionOptions
.
For more information on TextConverter
and TextConversionOptions
refer to the Converting Text and RTF to PDFs documentation.
TextConversionOptions textConversionOptions = new TextConversionOptions(PageSize.Legal, PageOrientation.Portrait, 72);
TextConverter textConverter = new TextConverter(inPath, textConversionOptions);
textConverter.Convert(outPath);
Dim MyTextConversionOptions As TextConversionOptions = New TextConversionOptions(PageSize.Legal, PageOrientation.Portrait, 72)
Dim TextConverter As TextConverter = New TextConverter(inPath, MyTextConversionOptions)
TextConverter.Convert(outPath)
WordConversionOptions
The WordConversionOptions class has the OptimizeFor, PageRange, BookmarksType and UnlinkFields properties in addition to the ConversionOptions class's properties.
The following code demonstrates Word to PDF Conversion with options using the WordConversionOptions class.
For more information on WordConverter
and WordConversionOptions
refer to the Converting Word Documents to PDFs documentation.
WordConversionOptions wordConversionOptions = new WordConversionOptions(PageSize.Letter, PageOrientation.Portrait, 36);
WordConverter wordConverter = new WordConverter(inPath, wordConversionOptions);
wordConverter.Convert(outPath);
Dim MyWordConversionOptions As WordConversionOptions = New WordConversionOptions(PageSize.Letter, PageOrientation.Portrait, 36)
Dim WordConverter As WordConverter = New WordConverter(inPath, MyWordConversionOptions)
WordConverter.Convert(outPath)
PowerPointConversionOptions
The PowerPointConversionOptions class has the OutputType, PdfA, and PowerPointSlideRange properties in addition to the inherited ConversionOptions
class's properties.
For more information on PowerPointConverter
and PowerPointConversionOptions
refer to the Converting PowerPoint Presentations to PDFs documentation.
PowerPointConversionOptions options = new PowerPointConversionOptions(false);
PowerPointConverter pptConverter = new PowerPointConverter(@"DocumentA.pptx", options);
pptConverter.Convert(outputPdf);
Dim options As PowerPointConversionOptions = New PowerPointConversionOptions(False)
Dim powerPointConverter As PowerPointConverter = New PowerPointConverter("DocumentA.pptx", options)
powerpointConverter.Convert(outputPdf)
AppendToPdf
The ConversionOptions
class has an AppendToPdf
property. This property allows appending to an existing PDF document. The following example illustrates using this property with the HtmlConversionOptions
child class.
The HtmlConversionOptions
class also has an AppendToPdf
property that allows specifying if the created PDF should be appended to a pre-existing PDF.
string html = "<html><body><p>Very simple HTML."
+ "</p></body></html>";
HtmlConverter converter = new(new Uri("http://www.google.com"));
converter.Convert(outputPdf);
HtmlConversionOptions options = new(PageSize.A4, PageOrientation.Landscape, 36);
options.AppendToPdf = true;
HtmlConverter converterB = new(html, options);
converterB.Convert(outputPdf);
Dim html As String = "<html><body><p>Very simple HTML." &
"</p></body></html>"
Dim converter As New HtmlConverter(New Uri("http://www.google.com"))
converter.Convert(Program.GetOutputDocPath(outputPdf))
Dim options As New HtmlConversionOptions(PageSize.A4, PageOrientation.Landscape, 36)
options.AppendToPdf = True
Dim converterB As New HtmlConverter(html, options)
converterB.Convert(outputPdf)
Figure 1. Appending to a PDF document