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

Free Support Forum - aspose.com

Reg: Write pagination

Hi,

I am using Aspose.Words for .NET to generate the word document.I tried to save the html content into html document and load the saved html document into the word document.Can anyone help me how to write pagination in word document.Please find the code i used to generate the word document.

string strFilePath = strDeskTopFolder + Convert.ToString(DateTime.Now.Millisecond) + ".docx";
var itemDto = SerializationHelper.Deserialise(itemJSON);
string strHtmlFileName = Path.ChangeExtension(strFilePath, ".html");
using (StreamWriter outfile = new StreamWriter(strHtmlFileName))
{
    outfile.Write(itemDto.Content);
}
Document doc = new Document(strHtmlFileName);
//doc.FirstSection.PageSetup.PageStartingNumber = 1;
//doc.UpdatePageLayout();
// Set the appended document to appear on the next page.
doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
// Restart the page numbering for the document to be appended.
doc.FirstSection.PageSetup.RestartPageNumbering = true;
doc.Save(strFilePath, SaveFormat.Docx);

Hi,

Thanks for your inquiry. You should just insert PAGE field into header or footer of your document. For example, please see the following code:

// Create new Docuemnt and
DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert PAGE field into the header and footer
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("- ");
builder.InsertField("PAGE", null);
builder.Write(" -");
// do the same for primary footer
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("- ");
builder.InsertField("PAGE", null);
builder.Write(" -");
// Now move cursor to the document's body and insert page break (just for testing)
builder.MoveToDocumentStart();
builder.InsertBreak(BreakType.PageBreak);
// Save output document
doc.Save(MyDir + @"out.docx");

I hope, this helps.

Best regards,

Thanks for your reply. I got the solution. I need a solution for one more functionality, I need write Header in left and right corner, I used the below code but it is writing both in the right corner…

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; 
builder.Write("Business Continuity Plan");
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.Write("Head office – East Kilbride");

Hi,

Thanks for your inquiry. Please create your target/expected Word document using Microsoft Word and attach it here for our reference. We will provide you code to achieve the same using Aspose.Words.

Best regards,

Hi,

Thanks for your reply. Please find the attachment to see the actual result with the code i used and the expected result.

Regards,

Kavi

Hi Kavi,

Thanks for your inquiry. I have already answered a similar query of yours here in this post. I would suggest you please follow that thread for further proceedings. If we can help you with anything else, please feel free to ask.

Best regards,

Hi,

Thanks for reply, I will check another thread for further information.

Regards,

Kavi