We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to delete empty page in between from PDF document

Hi,


I want to delete an empty page from pdf document. Empty page may come in between pdf document.

I am using Aspose Words for Java (Licensed), Please suggest.

Thanks.
Hi there,

Thanks for your inquiry. Your query is related to Aspose.Pdf APIs. I am moving this forum thread to Aspose.Pdf forum where you'll be guided appropriately.

Hi,


Thanks for your reply.
My query is related to Aspose Word for JAVA. I want to delete the first page of WORD Document (if it is empty) before converting to PDF.

Thanks
Sumit
Hi Sumit,

Thanks for your inquiry. Please use following code example to remove the first page of document. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
doc.updatePageLayout();

String PageText =
"";

LayoutCollector lc =
new LayoutCollector(doc);

ArrayList nodes = GetNodesByPage(
1, doc);
for (Paragraph para : (Iterable)nodes)
{
if(para.getText().contains(ControlChar.PAGE_BREAK))
{
PageText =
"Page Break";
break;
}
PageText += para.toString(SaveFormat.
TEXT).trim();
}

//Empty Page
if (PageText == "")
{
for(Node node : (Iterable)nodes)
{
node.remove();
}
}
nodes.clear();

doc.save(
MyDir + "Out.docx");

private static ArrayList GetNodesByPage(int page, Document document) throws Exception
{
ArrayList nodes =
new ArrayList();
LayoutCollector lc =
new LayoutCollector(document);
for (Paragraph paragraph : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH, true))
{
if (lc.getStartPageIndex(paragraph) == page)
nodes.add(paragraph);

}
return nodes;
}