What is the way to save a workbook to PDF with PDF pages being exactly the excel print-preview pages ?
Hi Sébastien,
It’s not what I get with my document.
See here same process saving as XLSX and as PDF.
PDF pages are splitted at columns that do not match the print-areas.
Hi again,
I’ve got the same error with 8.7.0.2.
Edit: Apparently, the conversion error occurs on a Linux server, I cannot reproduce it on Windows.
Hi,
Thanks for your posting and using Aspose.Cells.
Actually your excel file needs font Calibri which is present in Windows. But when you convert your excel file to Pdf, this font is not present there and Aspose.Cells uses some different font instead.
You should get the Calibri font from your Windows machine inside some directory say “/usr/share/temp” and then set the font directory like
CellsHelper.setFontDir(“/usr/share/temp”);
before the beginning of the workbook creation. Then you will get the correct pdf. I have also attached the two screenshots showing your fonts in Windows and Linux.
Please also see the following article for your reference.
( How to Specify TrueType Fonts Location|Documentation )
At the beginning of my application, I call now : CellsHelper.setFontDirs()
In one of , I’ve dropped the TTF files taken from windows : CALIBRI.TTF, CALIBRIB.TTF, CALIBRII.TTF, CALIBRIL.TTF, CALIBRILI.TTF, CALIBRIZ.TTF
Wihtout this call, I had : WithoutFontDirs.jpg
The font is similar in appearance but not Calibri.
With the above setting, I obtain : WithFontDirs.jpg
The font is completely different and still not Calibri.
Edit 1 :
Just before saving, calling CellsHelper.getFontDirs() returns:
{
/usr/ipbx//lib/override/dev/reports,
/usr/ipbx//lib/override/reports,
/usr/ipbx//reports,
c:\windows\fonts,
c:\winnt\fonts,
/usr/share/fonts,
/usr/local/share/fonts,
/Library/Fonts,
/usr/java/jdk1.7.0_51/jre/lib/fonts
}
Here the 3 first paths are the ones I’ve set and the second one contains the Calibri TTF files.
Edit 2:
I’ve added a WarningCallback as documented HERE and I’m getting a bunch of traces concerning Calibri font substitution like these:
WARNING INFO: Font substitution: Font [ Calibri; Regular ] has been substituted in Cell [ C47 ] in Sheet [ Cover ].
WARNING INFO: Font substitution: Font [ Calibri; Bold ] has been substituted in Cell [ A1 ] in Sheet [ Data ].
Hi Sébastien,
String infile = dir + “FILE.xlsx”;
String outfile = dir + “file.pdf”;
CellsHelper.setFontDir(dir + “calibri”); //calibri is the folder containing TTFs of Calibri font
li.setLicense(dir + “Aspose.Total.Java.lic”);
new Workbook(infile).save(outfile, SaveFormat.PDF);
Hi again,
list.add(dir + “calibri”);
CellsHelper.setFontDirs(list);
babar.raza:Please try moving the font setting statements before the license setting statement.
This is the information I needed to make it work, thanks !
It is somehow strange to have to do it before loading the license, by the way.
centile:
It is somehow strange to have to do it before loading the license, by the way.