I’m encountering an issue when saving an XLS file to PDF using the method save(String fileName, int saveFormat)
from the com.aspose.cells.Workbook
class. If the workbook template contains any variable fonts—a modern font format that includes multiple variations within a single font file—the font formatting does not render correctly in the resulting PDF. However, when I replace the variable font with an equivalent traditional font in OTF format, the formatting works as expected.
It seems that the Aspose.Cells library is not fully supporting variable fonts during the PDF export process. Please clarify the situation and assist in resolving this issue.
Let me know if any additional information is needed
It appears that you are experiencing issues with variable fonts not rendering correctly when saving an XLS file to PDF using Aspose.Cells. This is a known limitation, as the library may not fully support variable fonts during the PDF export process.
To address this issue, you can utilize the DefaultFont
property of the PdfSaveOptions
class. This property allows you to specify a fallback font that will be used when the original font is not available or cannot be rendered properly. Additionally, you can set the CheckWorkbookDefaultFont
property to false
to ensure that the specified DefaultFont
takes priority over the workbook’s default font.
Here’s a sample code snippet demonstrating how to set these properties:
import com.aspose.cells.*;
public class ExcelToPdf {
public static void main(String[] args) {
try {
// Load the workbook
Workbook workbook = new Workbook("input.xls");
// Create PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setDefaultFont("Times New Roman"); // Set your desired fallback font
pdfSaveOptions.setCheckWorkbookDefaultFont(false); // Disable workbook's default font
// Save the workbook to PDF
workbook.save("output.pdf", pdfSaveOptions);
} catch (Exception e) {
e.printStackTrace();
}
}
}
In this example, replace "Times New Roman"
with a font that you know will render correctly. This approach should help mitigate the issues you are facing with variable fonts in your PDF output.
If you continue to experience problems, please provide additional details about the specific fonts you are using or any error messages you encounter.
Thank you for the quick response.
What if I’m using multiple fonts in one document? In my case, I’m using:
1. DM Sans
2. Bricolage Grotesque
Both of them are variable fonts.
@arutski
Variable fonts are not supported when converting to pdf file now.
We have logged an issue CELLSJAVA-46126 to research this feature.
Hello.
Is there any update on this issue?
I would also like to add that we are experiencing the same issue even with non-variable OTF fonts Bricolage Grotesque from attached archive
bricolage-grotesque-font-family-1686865527-0.zip (3.8 MB)
Thanks for the font files in the zipped archive.
Please also zip and attach your sample input Excel file (in which you have used the underlying fonts) and output PDF (by Aspose.Cells). We will evaluate your issue soon.
Hi @amjad.sahi
Thank you for the quick response. Here is a sample Excel file together with PDFs:
Archive.zip (60.3 KB)
One PDF produced by Aspose Cells Java and another one produced by Excel. I have used simpl code from above message in this thread:
// Load the workbook
Workbook workbook = new Workbook("input.xls");
// Create PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setDefaultFont("Times New Roman"); // Set your desired fallback font
pdfSaveOptions.setCheckWorkbookDefaultFont(false); // Disable workbook's default font
// Save the workbook to PDF
workbook.save("output.pdf", pdfSaveOptions);
The only installed font from the archive is “BricolageGrotesque-Light-BF648bd57867903.otf”
The font used in the source “demo.xlsx” file is “Bricolage Grotesque”, but the font you installed is “Bricolage Grotesque Light”.
You should install “BricolageGrotesque-Regular-BF648bd5781d794.otf” or change the font used in the source file to “Bricolage Grotesque Light”.
Also, the font used in the pdf your shared(“demo - Excel.pdf”) is “Courier New”.
Hi @peyton.xu .
Thank you for a quick update. Actually I do confirm that it works for me after installing the “Bricolage Grotesque” regular. I think this particular issue can be ignored for now because I cannot reproduce it. I will get back here if it it reproduced.
@vitalyfundcount
You are welcome. Thank you for your feedback. I’m glad your issue has been resolved. If you have any questions, please feel free to contact us at any time.