PdfDocumentSource allows you to export PDF documents to other file formats which can be shared electronically. The following table lists the export filters along with the description about the various export formats to which the document can be exported:
Filter | Description |
---|---|
HtmlFilter | Exports the PDF documents to HTML streams or files. |
JpegFilter | Exports the PDF documents to JPEG streams or files. |
GifFilter | Exports the PDF documents to GIF streams or files. |
PngFilter | Exports the PDF documents to PNG streams or files. |
BmpFilter | Exports the PDF documents to BMP streams or files. |
TiffFilter | Exports the PDF documents to TIFF streams or files. |
PdfDocumentSource provides support for exporting the PDF documents to any external format through the C1DocumentSource class. Learn how C1DocumentSource supports the exporting of PDF documents in detail in the following sections.
PdfDocumentSource provides support for exporting a PDF file to an external format through Export method inherited from C1DocumentSource class.
To export PDF to HTML format, follow the steps below:
C# |
Copy Code
|
---|---|
using C1.Win.C1Document.Export;
|
C# |
Copy Code
|
---|---|
c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
|
C# |
Copy Code
|
---|---|
//Create HTMLFilter object HtmlFilter filter = new HtmlFilter(); //Set the output file name filter.FileName = @"..\..\DefaultDocument.html"; filter.ShowOptions = false; if (filter.ShowOptionsDialog()) { //Export PDF c1PdfDocumentSource1.Export(filter); System.Diagnostics.Process.Start(filter.OutputFiles[0]); MessageBox.Show(this, "Document was successfully exported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } |
To export PDF to an image file format:
Similar code as above can be used for exporting a PDF document to a series of page image files in one of the supported image formats (JPEG, PNG, TIFF, etc.). It is also possible to create a single ZIP file containing the page images. The following code uses one of the image format filter class, JpegFilter, to export the multi-paged file to JPEG format and creates a single ZIP file of the exported images setting the UseZipForMultipleFiles property to true.
C# |
Copy Code
|
---|---|
//Create JPEGFilter object JpegFilter filter = new JpegFilter(); filter.FileName = @"..\..\DefaultDocument.zip"; filter.UseZipForMultipleFiles = true; filter.ShowOptions = false; if (filter.ShowOptionsDialog()) { //Export PDF c1PdfDocumentSource1.Export(filter); System.Diagnostics.Process.Start(filter.OutputFiles[0]); MessageBox.Show(this, "Document was successfully exported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } |
PdfDocumentSource allows you to enumerate the supported export formats for a PDF document using the SupportedExportProviders property. The property returns a collection of ExportProvider classes that contain information about the supported formats. This data can be used to create the corresponding export filter by using the NewExporter method of ExportProvider class, which is the base class from which all export providers with specific formats are derived. Different document types support different sets of export formats, therefore enumerating and creating the export filters via SupportedExportProviders property yields the correct results.
To export PDF using supported exporters, follow the steps below:
Example Title |
Copy Code
|
---|---|
using System.IO; using C1.Win.C1Document; using C1.Win.C1Document.Export; |
C# |
Copy Code
|
---|---|
c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
|
C# |
Copy Code
|
---|---|
var supportedProviders = c1PdfDocumentSource1.SupportedExportProviders; foreach (var sep in supportedProviders) cbExporter.Items.Add(new FileAction() { Text = string.Format("Export to {0}...", sep.FormatName), ExportProvider = sep }); |
C# |
Copy Code
|
---|---|
private class FileAction { public string Text { get; set; } public ExportProvider ExportProvider { get; set; } public override string ToString() { return Text; } } |
C# |
Copy Code
|
---|---|
private void DoExport(C1PdfDocumentSource pds, ExportProvider ep) { saveFileDialog1.DefaultExt = "." + ep.DefaultExtension; saveFileDialog1.FileName = Path.GetFileName("Document")+ "." + ep.DefaultExtension; saveFileDialog1.Filter = string.Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*", ep.FormatName, ep.DefaultExtension); if (saveFileDialog1.ShowDialog(this) != DialogResult.OK) return; try { var exporter = ep.NewExporter(); exporter.ShowOptions = false; exporter.FileName = saveFileDialog1.FileName; if (exporter.ShowOptionsDialog()) { pds.Export(exporter); MessageBox.Show(this, "Document was successfully exported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } |
C# |
Copy Code
|
---|---|
private void btnExport_Click(object sender, EventArgs e) { DoExport(c1PdfDocumentSource1, ((FileAction) cbExporter.SelectedItem).ExportProvider); } |