Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

New Post: Pictures on DOCX file

$
0
0
Dear All,

I'm have to put a picture on a DOCX file using NPOI.

Using NPOI 2.1 I have no problem to do that using this code:
XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetBold(true);
            r2.SetText("test");

            var widthEmus = (int)(400.0 * 9525);
            var heightEmus = (int)(300.0 * 9525);

            using (FileStream picData = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
            {
                r2.AddPicture(picData, (int)PictureType.PNG, "image1", widthEmus, heightEmus);
            }

            using (FileStream sw = File.Create(outputfile))
            {
                doc.Write(sw);
            }
Anyway, using the version 2.2 this code does not work correctly sinche the create DOCX file cannot be open correctly using Word (but open office can open it!)

Do you have any idea on how to insert a Picture using version 2.2?

Thanks

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>