Free Support Forum - aspose.com

How to search blank page in word template using Aspose.word

Hi,

We are having window applicationn and using C# for development.

We do have word template file and it is having blank page.We want to search blank page and want to write data into this blank page.Can you please help us to achive this ?

Hi Atos,


Thanks for your inquiry. Please use the following code snippet to achieve your requirements. I suggest you please read following documentation links.
http://www.aspose.com/docs/display/wordsnet/LayoutCollector+Class
http://www.aspose.com/docs/display/wordsnet/LayoutEnumerator+Class

Hope this helps you. Please let us know if you have any more queries.


<span style=“font-size:10.0pt;
font-family:“Courier New”;color:#2B91AF;mso-font-kerning:0pt;mso-ansi-language:
PL;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:
“Courier New”;mso-font-kerning:0pt;mso-ansi-language:PL;mso-no-proof:yes”> doc
= new Document(MyDir

  • “in.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

String PageText = "";

LayoutCollector lc = new LayoutCollector(doc);

int pages = lc.GetStartPageIndex(doc.LastSection.Body.LastParagraph);

for (int i = 1; i <= pages; i++)

{

ArrayList nodes = GetNodesByPage(i, doc);

foreach (Paragraph para in nodes)

{

PageText += para.ToString(SaveFormat.Text).Trim();

}

//Empty Page

if (PageText == "")

{

builder.MoveTo((Paragraph)nodes[0]);

builder.Writeln("Aspose.Words for .NET");

nodes.Clear();

}

PageText = "";

}

//Get Paragraph nodes by page number

private ArrayList GetNodesByPage(int page, Document document)

{

ArrayList nodes = new ArrayList();

LayoutCollector lc = new LayoutCollector(document);

foreach (Paragraph para in document.GetChildNodes(NodeType.Paragraph, true))

{

if (lc.GetStartPageIndex(para) == page)

nodes.Add(para);

}

return nodes;

}