This project has moved and is read-only. For the latest updates, please go here.

Can't add multiple images

Sep 24, 2010 at 12:04 AM
Edited Sep 24, 2010 at 12:07 AM

I'm trying to add more than one image in different paragraphs and when I try to add the second one I got a null reference exception....

using (DocX document = DocX.Load("test.docx"))
    Novacode.Image img1 = document.AddImage("img1.png");
    Novacode.Image img2 = document.AddImage("img2.png");

    var p1= document.InsertParagraph(string.Empty);
    p1.AppendPicture(img1.CreatePicture()); //When the picture is added, the paragraph list (Docx.Paragraphs) is NULL

    var p2 = document.InsertParagraph(string.Empty);


I tried different ways of doing this and I always got the same error.

Also, I cant load a docx with an image inserted, I got an "Object reference not set to an instance of an object".



Nov 6, 2010 at 5:01 PM

I had this problem too, please fix this

Thank you for saving us work with hard com classes

Nov 6, 2010 at 8:56 PM

Hi emiguliyev1987,

I finally was able to insert images, what I did was to download the current source code and refereced it from my code... I know, its weird but it worked.

Nov 7, 2010 at 10:00 AM
ArielH & emiguliyev1987,

the latest source should contain a fix for the Image insertion bug your are talking about.
Please download and build your own copy of DocX.dll from source and reference this in your projects.

Kind regards,
Nov 8, 2010 at 6:51 AM

I did as you sad, ArielH, it worked, thank you.

coffeycathal, thank you too

this is very  useful dll

Nov 24, 2011 at 2:48 PM
how can I change orientation of document to landscaped?

thanks in advance
Nov 24, 2011 at 2:50 PM
Hi eminguliyev1987,

I hope this helps,
Nov 24, 2011 at 3:04 PM
thank you Cathal, I have used your DocX before, but when I know downloaded latest version of DocX I could not compile this, it gives error :
"Error 3 Cannot import the following key file: StrongNameFile.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_C9AB9DBB6B3DDF28 DocX"

what have i do?

thank you for your work

Nov 24, 2011 at 3:36 PM
I fixed it :) just removed from project StrongNamedKey file in VS2010

Nov 24, 2011 at 3:40 PM
Hi eminguliyev1987,

you are correct. If you do not need the assembly to be signed then you can remove StrongNameKey.

If you need it to be signed, this forum has some good suggestions.

Nov 24, 2011 at 3:42 PM
thank you ,if I need I'll follow