Save Multiple Workbooks into One PDF File in .NET Core and Java

Excel workbooks are often used to record data and analyze it. Organizations tend to create a plethora of workbooks, in order to keep a record of tasks. It is commonly expected that the company merges these workbooks into a PDF for the sake of easy delivery of a single file and data preservation.

For example, an organization selling stationery items maintains the sales record over two regions “Washington” and “New York” in two separate workbooks. To forward the sales information to the stakeholders, it needs to document this data in a file. To serve this purpose, the workbooks are required to be merged to a PDF file so it remains un-edited and exists in a single file.

To simplify the task of saving multiple workbooks into one PDF file, Grapecity Documents for Excel has created the SavePDF method of PrintManager class. This helps you reduce the number of files to be delivered in a go, making technology look more useful!

While using the SavePDF method, the page details are all based on the final paging results. When the first workbook has been completely rendered, the second one starts rendering in the PDF, till the final document is generated.

This process is carried out using the following simple steps:

  1. Load the workbooks in Workbook instances:
            Workbook workbook1 = new Workbook(); 


            Workbook workbook2 = new Workbook(); 

            workbook2.Open(Path.Combine("Resources", "NewYorkData.xlsx")); 
  1. Call the SavePDF method to generate a single PDF with the workbooks:
             PrintManager printManager = new PrintManager(); 

             printManager.SavePDF("TotalSales.pdf", workbook1, workbook2); 

This saves two of the workbooks (WashingtonData and NewYorkData) to a PDF named “TotalSales.pdf.”

Excel Workbooks

PDF Output

Download sample

The article illustrates how the SavePDF method of PrintManager class can be useful for the users to save multiple workbooks in one PDF file with a single line of code. It would not require manual merging of workbooks and then going for PDF conversion.

Thanks for following along! If you have any questions about the new features, please leave them in the comments below.

Happy Coding!

Esha Dhir

Associate Software Engineer
comments powered by Disqus