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.

Wed Jun 18, 2014 11:20 am

Dear Spire,

I expierence an issue when adding an image to the header section of a page (this happens when saving to DOCX and PDF).
When an image is added to the header of a section, the header is not adjusting its size. This results in drawing the body over the headersection like this:

capture_06182014_130954.jpg


When text is added to the header, the size of the header is adjusted right, as it should be. Like this:

capture_06182014_130941.jpg


Can you try to reproduce this issue?

Thanks in advance,
Johan.


edit: i use spire.office version 2.8

Here is the code i used:

Code: Select all

        private static Font font = new Font("Calibri", 9, FontStyle.Regular);
        private static Font titleFont = new Font("Calibri", 15, FontStyle.Bold);

        private static void Main()
        {
            Spire.License.LicenseProvider.SetLicenseFileName("license.elic.xml");
            CreateDetailedDocument(@"C:\temp\test3.docx");
        }

        private static void CreateDetailedDocument(string filename)
        {
            Document d = new Document();
            Section section1 = CreateSection(d);
         InsertHeader(section1);
            Table table = section1.AddTable(true);
            TableRow tr = table.AddRow(2);
         string value = "value";
            string key = "colname";
           tr.Cells[0].Width = section1.PageSetup.ClientWidth / 2;
         tr.Cells[1].Width = section1.PageSetup.ClientWidth / 2;
            TextRange t = tr.Cells[0].AddParagraph().AppendText(key);
            t.CharacterFormat.Font = titleFont;
            TextRange t2 = tr.Cells[1].AddParagraph().AppendText(value);
            t2.CharacterFormat.Font = font;

            d.SaveToFile(filename, FileFormat.Docx2013);
        }

        private static Section CreateSection(Document d)
        {
            if (d == null) return null;
            Section section1 = d.AddSection();

            section1.PageSetup.PageSize = PageSize.A4;
            section1.PageSetup.Orientation = PageOrientation.Portrait;
            return section1;
        }

      private static void InsertHeader(Section section)
      {
         //insert picture and text to header

         HeaderFooter header = section.HeadersFooters.Header;
         Paragraph titleParagraph = header.AddParagraph();
   
//         //ADD TITLE
//         TextRange title = titleParagraph.AppendText("Title");
//         title.CharacterFormat.Font = titleFont;
//         titleParagraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
//         
//         //ADD SUBTITLE
//         Paragraph subtitleParagraph = header.AddParagraph();
//         TextRange subtitle = subtitleParagraph.AppendText("Subtitle");
//         subtitle.CharacterFormat.Font = titleFont;
//         subtitleParagraph.Format.HorizontalAlignment = HorizontalAlignment.Left;

         //header picture on right top of the page.
         DocPicture headerPicture = titleParagraph.AppendPicture(ImageFactory.GetLTCLogo());
         headerPicture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;

         headerPicture.HorizontalOrigin = HorizontalOrigin.Page;
         headerPicture.HorizontalPosition = section.PageSetup.PageSize.Width - section.PageSetup.Margins.Right - headerPicture.Width;

         headerPicture.VerticalOrigin = VerticalOrigin.Page;
         headerPicture.VerticalPosition = section.PageSetup.Margins.Top;
      }


jslots
 
Posts: 48
Joined: Mon Jul 09, 2012 12:03 pm

Thu Jun 19, 2014 8:59 am

Hello,

Thanks for your inquiry. When an image is added to the header, technically, it doesn't make the header heighter, if you want to make header adjust its size, you can set the height of the header like as below.
Code: Select all
section.PageSetup.HeaderDistance = headerPicture.Height;

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Jun 19, 2014 12:15 pm

Dear Spire,

Thanks for the quick response. This works!

Johan

jslots
 
Posts: 48
Joined: Mon Jul 09, 2012 12:03 pm

Fri Jun 20, 2014 1:25 am

Good to know that your issue is resolved now.
Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc