Converting Excel Workbook to PDF
PDF files are widely used to exchange documents between organizations, government sectors, and individuals. It is a standard document format and software developers are often asked to find a way to convert Microsoft Excel files into PDF documents.
Aspose.Cells supports converting Excel files to PDF and maintains high visual fidelity in the conversion.
Aspose.Cells for .NET directly writes the information about API and Version Number in output documents. For example, upon rendering Document to PDF, Aspose.Cells for .NET populates Application field with value ‘Aspose.Cells’ and PDF Producer field with value, e.g ‘Aspose.Cells v17.9’.
Please note that you cannot instruct Aspose.Cells for .NET to change or remove this information from output Documents.
Aspose.Cells for .NET supports conversion from spreadsheets to PDF independently of other software. Simply save an Excel file to PDF using the Workbook class' Save method. The Save method provides the SaveFormat.Pdf enumeration member that converts the native Excel files to PDF format.
Follow the below steps to directly convert the Excel spreadsheets to PDF format:
- Instantiate an object of the Workbook class by calling its empty constructor.
- You may open/load an existing template file or skip this step if you are creating the workbook from scratch.
- Do any work (input data, apply formatting, set formulas, insert pictures or other drawing objects, and so on) on the spreadsheet using Aspose.Cells' APIs.
- When the spreadsheet code is complete, call the Workbook class' Save method to save the spreadsheet.
The file format should be PDF so select Pdf (a pre-defined value) from the SaveFormat enumeration to generate the final PDF document.
You may also opt to use the PdfSaveOptions class to set different attributes for the conversion. Setting different properties of the PdfSaveOptions class gives you control over the print, font, security and compression settings for the output PDF. The most important property is Compliance which enables you to save the Excel files to PDF/A compliant PDF files.
Saving Workbook to PDF/A Complied Files
The below-provided code snippet demonstrates how to use the PdfSaveOptions class to save Excel files to PDF/A compliant PDF format.
Set the PDF Creation Time
Set ContentCopyForAccessibility option
Export Custom properties to PDF
With the PdfSaveOptions class, you can export the custom properties in the source workbook to the PDF. PdfCustomPropertiesExport enumerator is provided for specifying the way by which properties are exported. These properties can be observed in Adobe Acrobat Reader by clicking on File and then properties option as shown in the following image. Template file “sourceWithCustProps.xlsx” can be downloaded here for testing and output PDF file “outSourceWithCustProps” is available here for analysis.
We work to enhance the conversion features with each new release. Aspose.Cell’s Excel to PDF conversion still has a couple of limitations. Some spreadsheet formatting might be lost when converting to PDF format. Also, some drawing objects are not yet supported.
The table that follows lists all features that are fully or partially supported when exporting to PDF using Aspose.Cells. This table is not final and does not cover all the spreadsheet attributes but it does identify those features that are not supported or partially supported for conversion to PDF.
|Drawing Objects||Partially||Supported Objects: TextBox, Line, Rectangle, Oval, GroupBox, Button, CheckBox, RadioButton, ListBox, ComboBox, Label|
|Font||Effects||Partially||Only strike through effect is supported|
|Page Setup||Page Orientation||Yes|
|Page Setup||Page Size||Yes|
|Page Setup||Print Area||Yes|
|Page Setup||Print Titles||Yes|
|Row Height/Column Width||Yes|
|RTL (Right to Left) Language||Yes|
- Add PDF Bookmarks
- Add PDF Bookmarks with Named Destinations
- Avoid Blank Page in Output PDF when there is Nothing to Print
- Change the Font on just the specific Unicode characters while saving to PDF
- Control loading of External Resources in MS Excel Workbook while rendering to PDF
- Convert an XLS File to PDF Format
- Convert Excel file to PDF format compatible with PDFA-1a
- Convert XLS File with Images or Charts to PDF
- Create PdfBookmarkEntry for Chart Sheet
- Fit All Worksheet Columns on Single PDF Page
- Get DrawObject and Bound while rendering to PDF using DrawObjectEventHandler class
- Get Warnings for Font Substitution while Rendering Excel File
- Ignore Errors while Rendering Excel to PDF
- Limit the Number of Pages Generated - Excel to PDF Conversion
- Print Comments while saving to PDF
- Render Office Add-Ins while converting Excel to PDF
- Render One PDF Page Per Excel Worksheet - Excel to PDF Conversion
- Render Unicode Supplementary characters in output PDF by Aspose.Cells
- Resampling Added Images - Excel to PDF Conversion
- Save Each Worksheet to a Different PDF File
- Save Excel into PDF with Standard or Minimum Size
- Secure PDF Documents
- Specify how to cross string in output PDF and image