c# - Novacode Docx Create Image from Bitmap -
c# - Novacode Docx Create Image from Bitmap -
background
my project urgent , requires iterate big xml file , homecoming base64 encoded images.
each image must inserted ms word doc, , using docx library that.
i converting base64 strings bitmap no problem.
problemfor life of me, can't seem bitmaps novacode.image object can inserted document. note: know how convert system.drawing.image format. novacode.image format (docx) giving me grief.
if seek convert la (novacode.image)somebitmap;
can not cast look of type image bitmap
. if seek initialize new novacode.image
object can not access internal constructor image here
.
using c#, .net 4, forms app, lots of coffee.
questiononly novacode.image objects can inserted ms word doc via library, how heck bitmap in there??
i bleary-eyed @ point perhaps missing simple.
you have utilize docx.addimage()
method create novacode.image
object.
follow these 5 steps add together image word document:
save image memory stream. createnovacode.image
object calling addimage()
method. create image calling createpicture()
on novacode.image
object created in step 2. set shape of image (if needed). insert image pragraph. the sample below shows how insert image word document:
using (docx doc = docx.create(@"example.docx")) { using (memorystream ms = new memorystream()) { system.drawing.image myimg = system.drawing.image.fromfile(@"test.jpg"); myimg.save(ms, myimg.rawformat); // save image in memory stream. ms.seek(0, seekorigin.begin); novacode.image img = doc.addimage(ms); // create image. paragraph p = doc.insertparagraph("hello", false); image pic1 = img.createpicture(); // create picture. pic1.setpictureshape(basicshapes.cube); // set image shape (if needed) p.insertpicture(pic1, 0); // insert image paragraph. doc.save(); } }
hope, helps.
c# .net ms-office docx
Comments
Post a Comment