static void InsertHeader(Section section)
{
HeaderFooter header = section.HeadersFooters.Header;
Paragraph paragraph = header.AddParagraph();
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
paragraph.Format.Borders.Bottom.BorderType = BorderStyle.ThickThinMediumGap;
paragraph.Format.Borders.Bottom.Space = 0.05f;
paragraph.Format.Borders.Bottom.Color = Color.DarkGray;
DocPicture headerimage = paragraph.AppendPicture(Image.FromFile("MacLogo90px.jpg"));
headerimage.HeightScale = 200;
headerimage.WidthScale = 200;
Table table = header.AddTable();
table.TableFormat.Borders.BorderType = BorderStyle.Single;
table.ResetCells(3, 2);
// set table position
table.TableFormat.WrapTextAround = true;
table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Margin;
table.TableFormat.Positioning.HorizPosition = headerimage.Width * headerimage.WidthScale / 100 + section.PageSetup.Margins.Left;
table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Paragraph;
table.TableFormat.Positioning.VertPosition = -30;
String[][] data = {
new string[] {"Elgin, City of (General Obligation Debt)","Last Revised 10/12/2014"},
new string[] {"","TMR # 1447"},
new string[] {"Bastrop, Travis Counties",""}
};
for (int r = 0; r < 3; r++)
{
TableRow dataRow = table.Rows[r];
for (int c = 0; c < 2; c++)
{
if (c == 0)
{
Paragraph par = dataRow.Cells[c].AddParagraph();
par.AppendText(data[r][c]);
// apply "FontStyle" to the paragraph
par.ApplyStyle("FontStyle");
par.Format.HorizontalAlignment = HorizontalAlignment.Left;
dataRow.Cells[c].Width = (section.PageSetup.ClientWidth - headerimage.Width * headerimage.WidthScale / 100) / 2;
}
else
{
Paragraph par = dataRow.Cells[c].AddParagraph();
par.AppendText(data[r][c]);
// apply "FontStyle" to the paragraph
par.ApplyStyle("FontStyle");
par.Format.HorizontalAlignment = HorizontalAlignment.Right;
dataRow.Cells[c].Width = (section.PageSetup.ClientWidth - headerimage.Width * headerimage.WidthScale / 100) / 2;
}
}
}
//insert page number on the header
Paragraph headerParagraphRight = table.Rows[2].Cells[1].Paragraphs[0];
headerParagraphRight.AppendField("page number", FieldType.FieldPage);
headerParagraphRight.AppendText(" of ");
headerParagraphRight.AppendField("number of pages", FieldType.FieldNumPages);
headerParagraphRight.Format.HorizontalAlignment = HorizontalAlignment.Right;
}
static void InsertHeader(Section section)
{
HeaderFooter header = section.HeadersFooters.Header;
Table table = header.AddTable();
//table.TableFormat.Borders.BorderType = BorderStyle.Single;
table.ResetCells(3, 3);
// merge the cells
table.ApplyVerticalMerge(0, 0, 2);
//insert the picture
Paragraph paraPic = table.Rows[0].Cells[0].AddParagraph();
DocPicture pic = paraPic.AppendPicture(Image.FromFile("MacLogo90px.jpg"));
table.Rows[0].Cells[0].Width = pic.Width;
pic.WidthScale = 300;
pic.HeightScale = 300;
String[][] data = {
new string[] {"","Elgin, City of (General Obligation Debt)","Last Revised 10/12/2014"},
new string[] {"","","TMR # 1447"},
new string[] {"","Bastrop, Travis Counties",""}
};
for (int r = 0; r < 3; r++)
{
TableRow dataRow = table.Rows[r];
//set the row height
dataRow.Height = pic.Height*pic.HeightScale / 300;
for (int c = 0; c < 3; c++)
{
if (c == 1)
{
Paragraph par = dataRow.Cells[c].AddParagraph();
par.AppendText(data[r][c]);
par.ApplyStyle("FontStyle");
par.Format.HorizontalAlignment = HorizontalAlignment.Left;
//set the row width
dataRow.Cells[c].Width = (section.PageSetup.ClientWidth) / 2;
}
if ( c ==2)
{
Paragraph par = dataRow.Cells[c].AddParagraph();
par.AppendText(data[r][c]);
// apply "FontStyle" to the paragraph
par.ApplyStyle("FontStyle");
par.Format.HorizontalAlignment = HorizontalAlignment.Right;
//set the row width
dataRow.Cells[c].Width = (section.PageSetup.ClientWidth) / 2;
}
}
}
//insert page number on the header
Paragraph headerParagraphRight = table.Rows[2].Cells[2].Paragraphs[0];
headerParagraphRight.AppendField("page number", FieldType.FieldPage);
headerParagraphRight.AppendText(" of ");
headerParagraphRight.AppendField("number of pages", FieldType.FieldNumPages);
headerParagraphRight.Format.HorizontalAlignment = HorizontalAlignment.Right;
// set the cell alignment
table.Rows[0].Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Bottom;
table.Rows[0].Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Bottom;
table.Rows[2].Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Top;
table.Rows[2].Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Top;
}
section.PageSetup.Margins.Left = 11;
section.PageSetup.Margins.Right = 11;
section.PageSetup.Margins.Top = 11;
section.PageSetup.Margins.Bottom = 1;
section.PageSetup.HeaderDistance = 0;
section.PageSetup.FooterDistance = 0;
Paragraph para = wdSection.AddParagraph();
para.ApplyStyle(BuiltinStyle.Heading3);
para.AppendBookmarkStart(tmrSection.ToString());
para.AppendText(tmrSectionName);
para.AppendBookmarkEnd(tmrSection.ToString());
para = wdSection.AddParagraph();
para.ApplyStyle("TinyFontStyle");
para.AppendText(tmrSectionText);
ToPdfParameterList toPdf = new ToPdfParameterList();
toPdf.CreateWordBookmarks = true;
document.SaveToFile(fileName, toPdf);