ASPOSE customized Page setup while converting to PDF

Hi Aspose Support Team,
I am converting excel file using Aspose.Cell and I want to set customized page size(11.7 x 8.3 in) but unable to set it though standard page size(A4,A3 etc) are available.

Can someone help in this?

@amol.shelar,

Thanks for your query.

Well, you may choose the paper size that best matches your requirements using PaperSizeType enumeration, see the document/table for your reference:

Hope, this helps a bit.

@amol.shelar

Thanks for considering Aspose APIs.

Please use the Worksheet.PageSetup.CustomPaperSize() method with the most recent version i.e. 17.11.6 for your needs. Please see the following code, its output Pdf and screenshot for a reference.

output-5x6-inches.zip (9.7 KB)

C#

//Create workbook
Workbook wb = new Workbook();

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Write some data in cell B4
ws.Cells["B4"].PutValue("This is sample data.");

//Set custom paper size, it is 5 x 6 inches
ws.PageSetup.CustomPaperSize(5, 6);

//Save it as pdf
wb.Save("output-5x6-inches.pdf");

Screenshot

Thanks, Shakeel.

Need Aspose Team’s help on conversion issue.
The texts are getting truncated in one environment but work fine in the testing environment.

I saw some forum replies that to use below line in code.

wb.Worksheets[0].AutoFitRows();

Please let us know the impact of the above code change and confirm if it is solution for the issue.

If there are more solutions/ suggestions, please share with me.

Thanks in advance.

@amol.shelar

Mostly such issues occur due to fonts. Please open your Excel file in Microsoft Excel and save it as Pdf and check their fonts in Adobe Reader. Then create the Pdf using Aspose.Cells and check their fonts in Adobe Reader. See if any font is missing which is present in Excel Pdf but not in Aspose.Cells Pdf.

The better way is to see the list of fonts using Workbook.GetFonts() method as discussed in this article.

Once, you know what fonts your Excel file needs, then place them in some directory and configure the fonts folder like this (in the beginning of your code)

FontConfigs.SetFontFolder(yourFontsFolderPath, true);

Here is the reference article.

Thanks, Shakeel.

Meanwhile, can you look into the screenshots below which will give you more details about issue.

images are as follows,

  1. Aspose Version 17_11_0_0 Aspose Version 17_11_0_0.png (4.6 KB)

2.Machine-1-Truncated Machine-1-Truncated.png (104.5 KB)

  1. Machine-2-Working fine Machine-2-Working fine.png (117.7 KB)

  2. Original excel file Original excel file.png (40.1 KB)

Please assist.

@amol.shelar

Please check your OS Display DPI. Set it to 96 dpi i.e. 100% and then regenerate your files and see if it makes any difference and resolves your issue.

Screenshot of Display Settings or DPI

Hi Shakeel,

I have tried following settings and it worked for me.
AutoFitterOptions oAutoFittOptions = new AutoFitterOptions();
oAutoFittOptions.OnlyAuto = false;
oAutoFittOptions.IgnoreHidden = true;
wb.Worksheets[0].AutoFitRows(oAutoFittOptions) ;

Can you help me to understand ‘AutoFitRows’ settings exactly? and what may be the reason that it was truncating the lines in some cells?

I have one more observation that the machine having MS office installed generates PDF without any issue. But the truncation issue has occurred on the machine where MS Office is not installed.
Does it matter in this case? Please let me know if this the cause.

Do I need to set DPI setting to 96 dpi(100%)?

Thanks you :slight_smile:

@amol.shelar

Mostly it is the font issue, please make sure all used fonts are installed on your machine and set DPI setting to 96 dpi i.e. 100%.

If you still have this issue, please share with us your source Excel file and generated Pdf files in your two machines.