We try converting Excel file to pdf using Aspose.Cells. But it takes about 40 seconds and after converting we get a pdf file that contains a lot of blank pages. We use this code:
Workbook workbook = new Workbook(@"C:\test\Template_Excel.xlsx");
workbook.Save(@"C:\test\Template_Excel.pdf");
Please look attached files.
Is there any way to get a file without blank pages after converting?
Thank you for help.
test.7z (469.1 KB)
@apkarpunin
By using sample file for testing, we can reproduce the issue. Even when setting the printing page type to PrintingPageType.IgnoreBlack, the result file still contains many blank pages.
Testing code as follows:
Workbook workbook = new Workbook(filePath + @"Template_Excel.xlsx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.PrintingPageType = PrintingPageType.IgnoreBlank;
workbook.Save(filePath + @"out_net.pdf", pdfSaveOptions);
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-54741
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@apkarpunin,
I checked your file by opening it into MS Excel manually. I took the print preview of the sheets (one by one) in MS Excel manually. I found there huge list of unnecessary (blank) pages. Now you can well understand that and to remove such huge list of blank pages will take time by Aspose.Cells APIs.
As a workaround and to cope with it, you may use try to use DeleteBlankRows and DeleteBlankColumns methods in your code. See the following (updated) sample code that works efficiently and blank pages are not rendered in the output PDF file:
e.g.
Sample code:
Workbook workbook = new Workbook("g:\\test2\\Template_Excel.xlsx");
for(int i= 0; i < workbook.Worksheets.Count; i++)
{
// Delete all blank rows and columns which do not contain any data.
workbook.Worksheets[i].Cells.DeleteBlankRows();
workbook.Worksheets[i].Cells.DeleteBlankColumns();
}
workbook.Save("g:\\test2\\out1.pdf");
Hope, this helps a bit.
@apkarpunin ,
The tons of blank pages are caused by lots of blank cells are filled by white background or lots of blank cells are merged. You can set a proper print area for the content that needs to be output in the source xlsx file. e.g. “A1:I163” for sheet “ОТЧЕТ” and “A1:Q27” for sheet “ПАМЯТКА”.
@amjad.sahi
Thank you for your idea, it works as we need for this file.
But we have often files that contain some rows with a content then a number of blank rows than a content again and so on. It’s not correct for us to delete blank rows and blank columns if there is some content around them.
Is there any way to delete blank rows and blank columns only if there is not any content below or to the right of them?
@apkarpunin
For you requirement, we think you may delete rows behind MaxDataRow by DeleteRows(int, int) and delete columns behind MaxDataColumn by DeleteColumns(int, int, bool).