Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:20:14+00:00 2026-06-04T19:20:14+00:00

I am adding images to a DOCX files using the WordprocessingDocument method found here

  • 0

I am adding images to a DOCX files using the WordprocessingDocument method found here (Open XML) http://msdn.microsoft.com/en-us/library/bb497430.aspx.

I can add images, but the sizing is not correct.

MainDocumentPart mainPart = doc.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
      {
           imagePart.FeedData(stream);
      }


return AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), fileName);

private static Drawing AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string filename)
    { 
       long imageWidthEMU = 1900000;
       long imageHeightEMU = 350000;

       double imageWidthInInches = imageWidthEMU / 914400.0;
       double imageHeightInInches = imageHeightEMU / 914400.0;

        new DW.Extent();

        //Define the reference of the image.
        var element =
             new Drawing(
                 new DW.Inline(
                     new DW.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU },

As you can see, you specify the sizes (length + width) manually. I am unable to get them dynamically. How can you get the right correct image size to pass to this code?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:20:16+00:00Added an answer on June 4, 2026 at 7:20 pm

    Your problem solved here:
    Inserting Image into DocX using OpenXML and setting the size

    There is no way to solve it via instruction in the xml file. OOXML offers only <a:fill> and <a:tile> options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using JQuery masonry and now I'm adding infinite scroll. There are images
Here is javascript code (jquery) for adding a row of images: var tr =
I am uploading some images using plupload and adding those images to div container.And
I have a thumbnail control where I am adding Images using openfiledialog and after
Okay so here is a random error. I'm dynamically adding images to an html
I have been playing with the list activity tutorial here: http://developer.android.com/resources/tutorials/views/hello-listview.html which tells you
there are plenty of tutorials showing how to blend two images in opencv: http://opencv.itseez.com/doc/tutorials/core/adding_images/adding_images.html
Normally using a ListView adding images and text to the ListView items is straight
I've been looking for something about adding images to videos, but i haven't found
I am adding images to a JPanel but the images are getting cut off.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.