Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jun 04, 2015 7:26 pm

Betsy, I have run your code and the header still looks messed up. I have attached a snip of the header.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Jun 05, 2015 7:43 am

Hello,

Please note if the image size is changed, the position of the table will need to do the appropriate adjustments.
Here is code for your reference:
Code: Select all
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;
        }

If there is any questions, welcome to get it back to us.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jun 09, 2015 9:16 am

Hello,

Have you tried the code ? Has your issue been resolved ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Tue Jun 09, 2015 9:37 pm

Betsy, do you have an example where you are doing colspan and rowspan in the tables?

I want to include the image in the header table

table.ResetCells(3, 3);

image would go into
table.row[0], row.cells[0]
table.row[1], row.cells[0]
table.row[2], row.cells[0]

So the header would look like my original post on Tue May 19, 2015 3:34 pm

Thank you.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Wed Jun 10, 2015 9:58 am

Hello,

Thanks for your response.
You can use the table.ApplyVerticalMerge(0, 0, 2) method to merge cells.
For the insert picture in the header table, there is the code for your reference:
Code: Select all
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;
        }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Jun 10, 2015 7:54 pm

Thank you that worked very nicely as you can see in the attached image.

My top and bottom margins are too big and the code does not seem to help.
I would like to make the top and bottom page margins smaller.

Code: Select all
         section.PageSetup.Margins.Left = 11;
         section.PageSetup.Margins.Right = 11;
         section.PageSetup.Margins.Top = 11;
         section.PageSetup.Margins.Bottom = 1;

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Thu Jun 11, 2015 3:46 am

Hello,

Thanks for your response.
Please try the following method to make the top and bottom page margins smaller.
Code: Select all
section.PageSetup.HeaderDistance = 0;
section.PageSetup.FooterDistance = 0;


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Jun 11, 2015 2:32 pm

Thank you that worked great!

Now, what margin do I use to push the text down from the header, and up from the footer so there is some white space between the header and text and footer and text?

Thank you.

TopBottomMargins2.JPG

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Jun 12, 2015 8:47 am

Hello,

You can add a blank paragraph between header and text, the same to the footer.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Jun 12, 2015 6:35 pm

Betsy, that worked, thanks.

Now my problem is with the bookmarks. I am getting nested bookmarks in my pdf file and I an NOT nesting the bookmarks.
This code is in a loop that adds data to the document.

It looks like it is creating a Parent bookmark for each page. Can I eliminate the parent bookmarks?

Code: Select all
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);



Then her is my code to save the document to pdf

Code: Select all
ToPdfParameterList toPdf = new ToPdfParameterList();
toPdf.CreateWordBookmarks = true;
document.SaveToFile(fileName, toPdf);

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Mon Jun 15, 2015 8:28 am

Hello,

Thanks for your inquiry.
Sorry that at present Spire.Doc doesn’t support to eliminate the parent bookmarks.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Doc