DsExcel .NET allows users to save multiple workbooks into a single Portable Document File (PDF) by using the SavePDF() method of the PrintManager class. Each workbook is saved to a new page in the PDF file. The information in the PDF such as the page number, number of pages, odd and even pages, first page etc. is saved on the basis of the final pagination results.
This feature is useful especially when you need consolidated information at one place for enhanced analysis and visualization. For instance - let's say you have sales information about different versions of a product in different workbooks. Instead of sharing multiple spreadsheets or PDF files; you can share a combined PDF (by saving all the workbooks to a single PDF file) showcasing the annual sales figures of the product. This will not only help users to analyse all the crucial information at one place but it will also facilitate them in sharing, manipulating and printing all the sales data in an efficient way.
Refer to the following example code in order to export a spreadsheet to a PDF file.
C# |
Copy Code |
---|---|
// Initialize workbook1 Workbook workbook1 = new Workbook(); // Open an Excel file workbook1.Open("Book1.xlsx"); workbook1.Worksheets[0].PageSetup.CenterFooter = "&P of &N"; // Set page header with some company logo workbook1.Worksheets[0].PageSetup.CenterHeader = "&G"; workbook1.Worksheets[0].PageSetup.CenterHeaderPicture.Filename = "logo.png"; workbook1.Worksheets[0].PageSetup.CenterHeaderPicture.Width = 150; workbook1.Worksheets[0].PageSetup.CenterHeaderPicture.Height = 50; workbook1.Worksheets[0].PageSetup.TopMargin = 100; workbook1.Worksheets[1].PageSetup.CenterFooter = "&P of &N"; // Set page header with some company logo workbook1.Worksheets[1].PageSetup.CenterHeader = "&G"; workbook1.Worksheets[1].PageSetup.CenterHeaderPicture.Filename = "logo.png"; workbook1.Worksheets[1].PageSetup.CenterHeaderPicture.LockAspectRatio = false; workbook1.Worksheets[1].PageSetup.CenterHeaderPicture.Width = 150; workbook1.Worksheets[1].PageSetup.CenterHeaderPicture.Height = 50; workbook1.Worksheets[1].PageSetup.TopMargin = 100; // Initialize workbook2 Workbook workbook2 = new Workbook(); // Open an Excel file workbook2.Open("Book2.xlsx"); workbook2.Worksheets[0].PageSetup.CenterFooter = "&P of &N"; workbook2.Worksheets[0].PageSetup.CenterHeader = "Google"; workbook2.Worksheets[0].PageSetup.TopMargin = 100; // Create an instance of the PrintManager class PrintManager printManager = new PrintManager(); // Save the workbook1 and workbook2 into the pdf file printManager.SavePDF(@"SaveDiffWorkBooksToOnePDF.pdf", workbook1, workbook2); |