Fit All Worksheet Columns on Single PDF Page
Contents
[
Hide
]
Sometimes you want to generate a PDF file that fits all a worksheet’s columns onto one page. The PdfSaveOptions.all_columns_in_one_page_per_sheet property provides this feature in a very easy-to-use manner. Complex calculations such as the height and width of the output PDF are handled internally and are based on the data in the worksheet.
Fit Worksheet Columns on Single PDF Page
PdfSaveOptions.all_columns_in_one_page_per_sheet ensures that all columns in a worksheet are rendered to a single PDF page, although rows may expand to several pages depending on the data in worksheet.
The sample code below shows how to use PdfSaveOptions.all_columns_in_one_page_per_sheet property to render a large worksheet of 100 columns.
When a given worksheet has many columns, the rendered PDF file may show the content in a very small size. It is still readable when scaled up in a viewing application such as Acrobat Reader.
If your spreadsheet contains formulas, it is best to call Workbook.calculate_formula method just before rendering the spreadsheet to PDF format. Doing so will ensure that the formula dependent values are recalculated, and the correct values are rendered in the PDF.