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.

Mon Oct 30, 2023 7:52 pm

I would like to add an image to a header with square formatting so the following text is shown to the right of the image within the header. When I use square formatting, the image is placed on top of the text both when the file is saved as .docx and when it is saved as .pdf. Is there a workaround for this problem?

My code is something like the following:

var header = section.HeadersFooters.Header;
var headerParagraph = header.AddParagraph();

DocPicture image = headerParagraph.AppendPicture(imageInfo.Source);
image.TextWrappingStyle = TextWrappingStyle.Square;

headerParagraph.AppendText(reportText.Text).ApplyCharacterFormat(format);

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Tue Oct 31, 2023 3:43 am

Hi,

Thank you for your inquiry.
I have tested the code you provided and generated the following screenshot of the effect:
1.png

Please provide a screenshot or a word file of the desired effect you want to help us do further investigation, you can attach here or send it to us via email (support@e-iceblue.com). Thank you in advance.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Wed Nov 01, 2023 9:54 pm

I've attached a file where you can see that the image in the header is overlapping the text. The header is also not resized in order to fit the image.

I would like for the image to be adjacent to the text, so that the text is shown to the right of the image in the header. And the header is automatically resized in order to fit the image.
Last edited by nataliegracegibbons on Fri Nov 03, 2023 3:27 pm, edited 1 time in total.

nataliegracegibbons
 
Posts: 13
Joined: Tue Oct 03, 2023 4:45 pm

Thu Nov 02, 2023 7:25 am

Hi,

Thank you for your inquiry.
Our product follows the Microsoft Word specification and only supports header adaptive text, not adaptive image size.I have achieved the following screenshot effect according to your requirements:
result.png

I put the complete code below for your referenece:
Code: Select all
// Create a new document object
Document doc = new Document();

// Load the existing Word document
doc.LoadFromFile(@"E:\34986\header image\test1.docx");

// Get the header of the first section
HeaderFooter header = doc.Sections[0].HeadersFooters.Header;

// Add a new table to the header
Table table = header.AddTable(false);

// Reset the cells in the table
table.ResetCells(1, 1);

// Create a new paragraph and add it to the first cell of the first row of the table
Paragraph Para = table.Rows[0].Cells[0].AddParagraph();

// Append a picture to the paragraph
DocPicture image = Para.AppendPicture(@"E:\34986\2.png");

// Set the text wrapping style of the picture
image.TextWrappingStyle = TextWrappingStyle.Square;

// Append additional text to the paragraph
Para.AppendText("Reporting Project\r\nComputers and Structures, Inc.\r\nNovember 01, 2023\r\n");

// Save the modified document with the new header image
doc.SaveToFile(@"E:\\34986\\result8.docx", FileFormat.Docx2019);

If you have any issue just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.Doc