Auto-generate document

Hi,
I have created the document that I want to auto-generate.
I managed to generate the header and footers as appear in the document, however, I had problems to generate the textual shapes.
Here are my problems:

  1. How to generate more than one shape and control its location?
  2. I want to use a document with 2 columns formatting and in some places (when I use a graph) one column fomatting.
  3. How to generate the header underline orange color? - In word I added a bottom border to the header text - I could not find the way to do it in Aspose.
  4. How to generate a textual shape as I did without border? I have looked into the sample in Aspose site that shows how to generate a text inside a rectangle, however, I could not managed to remove the border color.

Thanks,
- Gal

Try to use the following example to generate target document.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

Section currentSection = builder.CurrentSection;
PageSetup pageSetup = currentSection.PageSetup;

// — Create header for pages other than first. —
pageSetup.HeaderDistance = 20;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// Specify another header title for other pages.
builder.Write("Header Section");
builder.InsertBreak(BreakType.ParagraphBreak);
builder.InsertImage(@"031_Gal\logo.gif");

// Create and insert shapes
builder.MoveToDocumentStart();

// Get shape widht
double shapeWidht = pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin;
// create first shape
Shape shape1 = new Shape(doc, ShapeType.Rectangle);
shape1.Height = shapeWidht / 2;
shape1.WrapType = WrapType.Inline;
shape1.Width = shapeWidht / 2;
shape1.StrokeColor = Color.Transparent;
// create paragraph for first shape
Paragraph par = new Paragraph(doc);
par.ParagraphFormat.Borders[BorderType.Bottom].Color = Color.Orange;
par.ParagraphFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
par.ParagraphFormat.Borders[BorderType.Bottom].LineWidth = 2;
Run run = new Run(doc);
run.Font.Color = Color.Blue;
run.Font.Size = 12;
run.Font.Name = "Verdana";
run.Text = "[Header1Text]";
par.Runs.Add(run);
shape1.AppendChild(par);

Paragraph par1 = new Paragraph(doc);
Run run1 = new Run(doc);
run1.Font.Color = Color.Black;
run1.Font.Size = 9;
run1.Font.Name = "Verdana";
run1.Text = "Inserted text";
par1.Runs.Add(run1);
shape1.AppendChild(par1);

builder.InsertNode(shape1);
builder.InsertNode(shape1.Clone(true));

builder.InsertBreak(BreakType.ParagraphBreak);

// Inserting third shape
Shape shape2 = new Shape(doc, ShapeType.Rectangle);
shape2.Height = shapeWidht / 2;
shape2.WrapType = WrapType.Inline;
shape2.Width = shapeWidht;
shape2.StrokeColor = Color.Transparent;

Paragraph par2 = new Paragraph(doc);
par2.ParagraphFormat.Borders[BorderType.Bottom].Color = Color.Orange;
par2.ParagraphFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
par2.ParagraphFormat.Borders[BorderType.Bottom].LineWidth = 2;
Run run2 = new Run(doc);
run2.Font.Color = Color.Blue;
run2.Font.Size = 12;
run2.Font.Name = "Verdana";
run2.Text = "[Header1Text]";
par2.Runs.Add(run2);
shape2.AppendChild(par2);

Shape shape3 = new Shape(doc, ShapeType.Image);
shape3.Width = shapeWidht;
shape3.Height = shapeWidht / 2 - 50;
shape3.ImageData.SetImage(@"031_Gal\diagram.JPG");

Paragraph par3 = new Paragraph(doc);
par3.AppendChild(shape3);
shape2.AppendChild(par3);

builder.InsertNode(shape2);

// — Create footer for pages other than first. —
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// We use table with two cells to make one part of the text on the line (with page numbering)
// to be aligned left, and the other part of the text (with copyright) to be aligned right.
builder.StartTable();
// Calculate table width as total page width with left and right margins subtracted.
// PageSetup pageSetup = builder.CurrentSection.PageSetup;
double tableWidth = pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin;
builder.InsertCell();
// Set first cell to 1/3 of the page width.
builder.CellFormat.Width = tableWidth / 3;
// Insert page numbering text here.
// It uses PAGE and NUMPAGES fields to autocalculate current page number and total number of pages.
builder.Write("Page ");
builder.InsertField("PAGE", "");
builder.Write(" of ");
builder.InsertField("NUMPAGES", "");
// Align this text to the left.
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell();
// Set the second cell to 2/3 of the page width.
builder.CellFormat.Width = tableWidth * 2 / 3;
builder.Write("© 2006 Aspose Pty Ltd. All rights reserved.");
// Align this text to the right.
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.EndRow();
builder.EndTable();
builder.MoveToDocumentEnd();
// Save the resulting document.

string filename = @"031_Gal\out.doc";
doc.Save(filename);

Best regards.

Hi, thank you for the informative reply, this is great and answer all the needs that I raised in that case.
I have one more (hopefully last) issue in regards to how to populate the Text objects with HTML input instead of regular strings. I saw that the insertHTML can work only on the builder level and understand that it actually cuts the HTML content into multiple Run objects. Is there a way to make it work on a Textbox object? I tried to copy the Run objects from a temporary DocumentBuilder that works with a temporary Doc, but since it is a different Doc it didn’t let me to copy the Run objects, is there any other way around?

Replied here.