)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to insert image on each page of Word document?

Platform: WinForms |
Control: DocIO |
Published Date: March 3, 2017 |
Last Revised Date: September 18, 2019

The Word document is a flow document in which contents will not be preserved page by page; instead the contents will be preserved sequentially section by section. Each section may extend to various pages based on its contents like table, text, images etc.

Word viewer/editor renders the contents of the Word document page by page dynamically when opened for viewing or editing and this page wise rendered information will not be preserved in the document level as per the Word file format specification. Whereas Essential DocIO is a non-UI component that provides a full-fledged document object model to manipulate the Word document contents.

In the following ways can insert image in a Word document.

  1. Insert image in Header/Footer of each section.
  2. Insert image in each section of Word document.
  3. Insert image as picture Watermark in Word document.

Please refer the below UG links to know more about the above-mentioned scenarios.

Working with sections

Working with headers and footers

Picture watermark

Insert image in Header/Footer of each section.

The following code examples shows how to insert image in Header and Footer of each section in existing Word document using Essential DocIO.

C#

//Loads an existing Word document
WordDocument wordDocument = new WordDocument("Essential DocIO.docx");
//Iterates each section and appends image in header of each section
//It will display image in each page of Word document
foreach (WSection section in wordDocument.Sections)
{
    //Creates new WPicture instance and gets Image from file
    WPicture picture = new WPicture(wordDocument);
    picture.LoadImage(Image.FromFile("AdventureCycle.jpg"));
    picture.Height = 50;
    picture.Width = 250;
    //Insert image in Header and Footer of section
    section.HeadersFooters.Header.AddParagraph().ChildEntities.Add(picture);
}
//Saves Word document and closes WordDocument instance
wordDocument.Save("Sample.docx");
wordDocument.Close();

 

VB

'Loads an existing Word document
Dim wordDocument As wordDocument = New WordDocument("Essential DocIO.docx")
'Iterates each section and appends image in header of each section
'It will display image in each page of Word document
For Each section As WSection In wordDocument.Sections
    'Creates new WPicture instance and gets Image from file
    Dim picture As WPicture = New WPicture(wordDocument)
    picture.LoadImage(System.Drawing.Image.FromFile("AdventureCycle.jpg"))
    picture.Height = 50
    picture.Width = 250
    'Insert image in Header and Footer of section
    section.HeadersFooters.Header.AddParagraph().ChildEntities.Add(picture)
Next
'Saves Word document and closes WordDocument instance
wordDocument.Save("Sample.docx")
wordDocument.Close()

Insert image in each section of Word document.

The following code examples shows how to insert image in each section of existing Word document using Essential DocIO.

C#

//Loads an existing Word document
WordDocument wordDocument = new WordDocument("Essential DocIO.docx");
//Iterates each section and appends image in each section
//It will display image in each section of Word document
foreach (WSection section in wordDocument.Sections)
{
    //Creates new WPicture instance and gets Image from file
    WPicture picture = new WPicture(wordDocument);
    picture.LoadImage(Image.FromFile("AdventureCycle.jpg"));
    picture.Height = 50; picture.Width = 250;
    //Gets paragraph using index and adds picture into that paragraph
    WParagraph paragraph  = section.Body.LastParagraph;
    if (paragraph != null)
        paragraph.ChildEntities.Add(picture);
}
//Saves Word document and closes WordDocument instance
wordDocument.Save("Sample.docx");
wordDocument.Close();

VB

'Loads an existing Word document
Dim wordDocument As wordDocument = New WordDocument("Essential DocIO.docx")
'Iterates each section and appends image in each section
'It will display image in each section of Word document
For Each section As WSection In wordDocument.Sections
    'Creates new WPicture instance and gets Image from file
    Dim picture As WPicture = New WPicture(wordDocument)
    picture.LoadImage(System.Drawing.Image.FromFile("AdventureCycle.jpg"))
    picture.Height = 50
    picture.Width = 250
    Dim paragraph As WParagraph = section.Body.LastParagraph
    If paragraph IsNot Nothing Then
        paragraph.ChildEntities.Add(picture)
    End If
Next
'Saves Word document and closes WordDocument instance
wordDocument.Save("Sample.docx")
wordDocument.Close()

Insert image as picture Watermark in Word document.

The following code examples shows how to insert image as picture watermark in existing Word document using Essential DocIO.

C#

//Loads an existing Word document
WordDocument wordDocument = new WordDocument("Essential DocIO.docx");
//Gets the image from file
Image image = Image.FromFile("AdventureCycle.jpg");
//Sets the picture watermark to document
wordDocument.Watermark = new PictureWatermark(image, true);
//Saves Word document and closes WordDocument instance
wordDocument.Save("Sample.docx");
wordDocument.Close();

VB

'Loads an existing Word document
Dim wordDocument As wordDocument = New WordDocument("Essential DocIO.docx")
'Gets the image from file
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile("AdventureCycle.jpg")
'Sets the picture watermark to document
wordDocument.Watermark = New PictureWatermark(image, True)
'Saves Word document And closes WordDocument instance
wordDocument.Save("Sample.docx")
wordDocument.Close()

Please find the complete sample with above mentioned use cases from the below link.

Sample link

Note:

Refer the Assemblies required section to refer and run the sample without error.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon