Excel to PDF Converter |
The Excel to PDF converter, PdfConverter, converts Excel workbooks to PDF without Microsoft Excel: .xlsx, .xlsm, .xltx, .xltm, .xls, .xlt, comma and tab separated values, the Excel 2003 XML spreadsheet and Markdown, whose tables become worksheets. The workbook is laid out by a spreadsheet engine in the library, on Windows, Linux and macOS.
using ExpertPdf.Anywhere.ExcelToPdf; PdfConverter converter = new PdfConverter(); // converter.LicenseKey = "your license key"; // page numbers in the footer converter.PdfDocumentOptions.ShowFooter = true; converter.PdfFooterOptions.ShowPageNumber = true; converter.SavePdfFromExcelFileToFile("sales.xlsx", "sales.pdf");
The workbook can come from a file, a stream or bytes (GetPdfBytesFromExcelFile, GetPdfBytesFromExcelStream, GetPdfBytesFromExcelBytes, and the SavePdfFrom... methods). The format is found from the file extension or from the content; pass an ExcelFormat to set it - tab separated values and Markdown given as a stream must name it. A password protected workbook needs Password. A workbook that cannot be read fails with ExcelConvertException.
Every visible sheet is converted, in workbook order, as Excel prints it: its print area, its page breaks and its own printed header and footer. Each sheet becomes a bookmark of the PDF (SheetBookmarks), and Worksheets converts only the sheets it names, for example "Summary, Q1".
By default (PageSetup = ExcelPageSetup.Document) every sheet is printed on the paper size, orientation and margins of its own page setup. With ExcelPageSetup.Options the sheets are laid out on the page size, orientation and margins of PdfDocumentOptions. Layout scales the content of each sheet - the whole sheet, all its columns or all its rows on one page - and GridLines draws or hides the cell gridlines:
PdfConverter converter = new PdfConverter(); converter.PageSetup = ExcelPageSetup.Options; converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; converter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape; converter.PdfDocumentOptions.LeftMargin = 36; converter.PdfDocumentOptions.RightMargin = 36; converter.Layout = ExcelLayout.FitAllColumnsOnOnePage; converter.GridLines = ExcelGridLines.Visible; byte[] pdf = converter.GetPdfBytesFromExcelFile("sales.xlsx");
SheetHeadersAndFooters: draw the headers and footers set in the sheets' page setup (the default).
ConvertBlankSheets and ConvertBlankPages: keep empty sheets and empty pages.
PageRanges: convert only some pages, for example "1-3,5".
PreserveFormFields: keep the form controls of the sheets as PDF form fields.
AutoDetectComplexScript: shape Arabic, Hebrew, Thai and other complex scripts the workbook does not mark.
PdfStandardSubset and AccessibilityStandard: PDF/A, PDF/X and tagged PDF/UA output - the sheets' tables with their header cells, charts and pictures with their alternative text, and links; set Language and the title for an accessible document.
The header and footer options (title, footer text, page numbers, a Word document as header or footer with WordToPdfArea), the security options and the document information work as they do for the HTML to PDF converter.
A font the workbook uses and the host does not have is replaced by a font with the same metrics; on Linux and macOS hosts without fonts, add the ExpertPdf.Anywhere.Fonts package.