Set DefaultFont property of PdfSaveOptions and ImageOrPrintOptions to have priority

Possible Usage Scenarios

While setting the DefaultFont property of PdfSaveOptions and ImageOrPrintOptions, you might expect that saving to PDF or image would apply that DefaultFont to all the text in a workbook that uses a missing (not installed) font.

Generally, when saving to PDF or image, Aspose.Cells for Python via .NET will first try to set the workbook’s default font (i.e., Workbook.DefaultStyle.Font). If the workbook’s default font still cannot display/render the text properly, Aspose.Cells for Python via .NET will try to render with the font specified by the DefaultFont attribute in PdfSaveOptions / ImageOrPrintOptions.

To meet your expectation, we have a Boolean property named check_workbook_default_font in PdfSaveOptions / ImageOrPrintOptions. You can set it to false to disable checking the workbook’s default font, or let the default_font setting in PdfSaveOptions / ImageOrPrintOptions have priority.

Set DefaultFont property of PdfSaveOptions/ImageOrPrintOptions

The following sample code opens an Excel file. The A1 cell (in the first worksheet) contains the text “Christmas Time Font text”. The font name is “Christmas Time Personal Use”, which is not installed on the machine. We set the default_font attribute of PdfSaveOptions / ImageOrPrintOptions to “Times New Roman”. We also set the check_workbook_default_font Boolean property to false, which ensures that the text in cell A1 is rendered with the “Times New Roman” font and does not use the workbook’s default font (“Calibri” in this case). The code renders the first worksheet to PNG and TIFF image formats and finally to a PDF file.

This is the screenshot of the template file used in the example code.

todo:image_alt_text

This is the output PNG image after setting the ImageOrPrintOptions.default_font property to “Times New Roman”.

todo:image_alt_text

See the output TIFF image after setting the ImageOrPrintOptions.default_font property to “Times New Roman”.

See the output PDF file after setting the PdfSaveOptions.default_font property to “Times New Roman”.

Sample Code