I have an empty word document with bookmarks. I want to insert data on each bookmark that is done but I have multiple records so I have add a page break than print another record to all bookmarks on the page added. What happens each record gets printed on the bookmark added on the first page. How to resolve this?
using (MemoryStream inStream = new MemoryStream(template))
{
if (!NeRA.AggreementHelper.IsLicenseAlreadyOpen)
NeRA.AggreementHelper.InitializeLicense();
Aspose.Words.Document doc = new Aspose.Words.Document(inStream);
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
foreach (var resultrepo in resultrepos)
{
var i = 0;
builder.MoveToBookmark("FacilityName");
builder.InsertHtml("<b style='font-size:24px;font-family: Arial'>" + resultrepo.res_facility + "</b>");
builder.MoveToBookmark("AdditionalServHeader");
builder.InsertHtml("<b style='font-size:24px;font-family: Arial'>Additional Services Menu</b>");
builder.MoveToBookmark("PrintDate");
builder.InsertHtml("Date: "+DateTime.Today.ToString("dd/MM/yyyy"));
builder.MoveToBookmark("res_address");
builder.InsertHtml(resultrepo.res_address);
builder.MoveToBookmark("res_firstname");
builder.InsertHtml(resultrepo.res_firstname);
builder.MoveToBookmark("res_lastname");
builder.InsertHtml(resultrepo.res_lastname+",");
builder.MoveToBookmark("add_det");
builder.InsertHtml("Please find the list of Additional Services available in our facility.
Prices are stated per day.");
builder.MoveToBookmark("add_thanks");
builder.InsertHtml("Thank you");
builder.MoveToBookmark("res_lastname1");
builder.InsertHtml(resultrepo.res_lastname);
builder.MoveToBookmark("res_postcode");
builder.InsertHtml(resultrepo.res_postcode);
builder.MoveToBookmark("res_state");
builder.InsertHtml(resultrepo.res_state);
builder.MoveToBookmark("res_suburb");
builder.InsertHtml(resultrepo.res_suburb);
builder.MoveToBookmark("res_title");
builder.InsertHtml(resultrepo.res_title);
builder.MoveToBookmark("res_title1");
builder.InsertHtml("Dear" + resultrepo.res_title);
builder.MoveToBookmark("additionalServicesList");
builder.StartTable();
builder.InsertCell();
Aspose.Words.Tables.CellFormat cellFormat = builder.CellFormat;
cellFormat.Shading.BackgroundPatternColor = Color.LightGray;
builder.Writeln("Service Name");
builder.InsertCell();
builder.Writeln("Description");
builder.InsertCell();
builder.Writeln("Price");
builder.EndRow();
// Set the cell formatting
foreach (var service in resultrepo.serviceList)
{
builder.InsertCell();
cellFormat.Shading.BackgroundPatternColor = Color.White;
builder.Writeln(service.Name);
builder.InsertCell();
builder.Writeln(service.Description);
builder.InsertCell();
builder.Writeln("$" + Math.Round(service.price, 2).ToString());
builder.EndRow();
}
builder.EndTable();
builder.MoveToBookmark("FacilityName1");
builder.InsertHtml(resultrepo.res_facility);
builder.InsertBreak(BreakType.PageBreak);
}
doc.Save(downloadFile + ".docx", Aspose.Words.SaveFormat.Docx);