How to insert a picture into the HEADER of a RadFlowDocument Word document
1 Answer 10 Views
Francois
Top achievements
Rank 1
Francois asked on 07 Jul 2021, 11:41 PM | edited on 07 Jul 2021, 11:43 PM

Here is what I tried:

            

using (FileStream stream = new FileStream(FullFileNameDOC, FileMode.Open)) wordDocument = new DocxFormatProvider().Import(stream); Header header = wordDocument.Sections.First().Headers.Default; RadFlowDocumentEditor editor = new RadFlowDocumentEditor(header.Document); using (Stream stream = new FileStream($@"{TemplatesDirectory}FormHeader.PNG", FileMode.Open)) editor.InsertImageInline(stream, "png");

using (FileStream stream = new FileStream(FullFileNameDOC, FileMode.Open)) wordDocument = new DocxFormatProvider().Import(stream); Header header = wordDocument.Sections.First().Headers.Default; RadFlowDocumentEditor editor = new RadFlowDocumentEditor(header.Document); using (Stream stream = new FileStream($@"{TemplatesDirectory}FormHeader.PNG", FileMode.Open)) editor.InsertImageInline(stream, "png");

... this inserts the image but not in the Word document Header; it inserts the image in the Word document Body.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 12 Jul 2021, 01:55 PM

Hello Francois,

You can achieve this by inserting the ImageInline using the RadFlowDocument model by adding it to a Paragraph into the Header/Footer in the following way:

ImageInline imageInline = new ImageInline(wordDocument);
using (Stream stream = new FileStream($@"{TemplatesDirectory}FormHeader.PNG", FileMode.Open))
{
	imageInline.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(stream, "png");
}

Header header = wordDocument.Sections.First().Headers.Default;
Paragraph paragraph = header.Blocks.AddParagraph();
paragraph.Inlines.Insert(0, imageInline);

As a side note, the RadFlowDocumentEditor doesn't provide APIs for manipulating the RadFlowDocument`s Header/Footer. So, we have a feature request logged in our backlog to provide such support: Implement an API for navigating and manipulating of a block container with RadFlowDocumentEditor. You can cast your vote for the implementation as well as subscribe to the task by clicking the Follow button so you can be notified when its status changes.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Asked by
Francois
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or