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:
When text is added to the header, the size of the header is adjusted right, as it should be. Like this:
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;
}