Free Support Forum - aspose.com

Remove blank pages form MS documents

Hi

Anyone guide me to remove blank pages from Word, Excel and PowerPoint documents before converting these documents to TIFF format using Aspose SDK's.

Thanks,

Dhivya

Hi,


I am a representative of Aspose.Cells team, I think you may try ImageOrPrintOptions.PrintingPage property to set to IgnoreBlank before rendering Excel worksheets to Tiff images.

ImageOrPrintOptions outputOptions = new ImageOrPrintOptions();

outputOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
outputOptions.PrintingPage = Aspose.Cells.PrintingPageType.IgnoreBlank;
outputOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;
outputOptions.HorizontalResolution = 300;
outputOptions.VerticalResolution = 300;
Workbook doc = new Workbook(“e:\test\book1.xlsx”);
Aspose.Cells.Worksheet worksheet = doc.Worksheets[0];
Aspose.Cells.Rendering.SheetRender sheetRender = new Aspose.Cells.Rendering.SheetRender(worksheet, outputOptions);
int sheetPageCount = sheetRender.PageCount;
for (int sheetPage = 0; sheetPage < sheetPageCount; sheetPage++)
{
sheetRender.ToImage(sheetPage, “e:\test\Img_” + sheetPage + “.tiff”);

}

Thank you.

Hi Dhivya,


Please visit this documentation link to see which methods are available for removing slides. Unfortunately, there is no direct method to identify whether a give slide is blank or not. You need to get count of shapes inside slide and if the shape count returns 0, it means slide is blank and you remove that.

Presentation pres=new Presentation(“D:\Test.ppt”);
Slides slide;
for (int i=0; i<pres.Slides.Count;i++)
{
slide=pres.Slides[i];
if(slide.Shapes.Count==0)
{
pres.Slides.Remove(slide);
i–;

}
}

Thanks and Regards,

Hello Dhivya,

Thanks for your request. I'm a representative for Aspose.Words.

MS Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document.

But I think in your case you can delete all empty paragraphs from the end of the document, please see the following code:

// Remove empty paragraphs from the end of the document.

while (doc.LastSection.Body.LastParagraph != null &&

string.IsNullOrEmpty(doc.LastSection.Body.LastParagraph.GetText().Trim()))

doc.LastSection.Body.LastParagraph.Remove();

Hope this helps.

Best regards,