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

Free Support Forum - aspose.com

Paragraphs and DocumentBuilder


I have a problem with paragraphs using the document builder. I have a loop that generates input like this:

DocumentBuilder builder = new DocumentBuilder(doc);


foreach (Contract contract in contracts)
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.Borders.Bottom.LineStyle = LineStyle.Single;
paragraphFormat.Borders.Bottom.LineWidth = 1.5;
paragraphFormat.Borders.Bottom.Color = Color.Red;
paragraphFormat.KeepTogether = true;

builder.Write(“Kund: “);
builder.Write(” Kundnummer: “);
builder.Write(” Uppdrag: “);
builder.Write(“Lönekostnad dag “);
builder.Write(String.Format(”{0:# ##0 kr}”, contract.prognos.WeekDaySalaryCost));
builder.Write(” Lönekostnad kväll “);
builder.Write(String.Format(”{0:# ##0 kr}”, contract.prognos.EveneingSalaryCost));
builder.Write(" Lönekostnad totalt “);
builder.Write(String.Format(”{0:# ##0 kr}", contract.prognos.TotalSalaryCost));

This way I thought that I would get a separate pragraph for each iteration in the foreach loop. Looking at the result however gives me the impression that I have one paragraph per page since the red border appears at the bottom of each page - not after each iteration as I thought it would

What is wrong in the code above?

Best regards
Robert Tell

Hi Robert,

Thanks for your inquiry. In your case, please only insert the break of type ParagraphBreak at the end of foreach loop.

Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.