Git Product home page Git Product logo

Comments (8)

Tschakah avatar Tschakah commented on May 11, 2024 1

Hi,
thanks for the work you put in TQ, i'm having a similar problem and can maybe narrow this down a little bit.

Problem: Adding picture data to docx-structure i.e. word/media/xxx.jpg
NPOI Version: 2.4.1.

While trying to add an image to a new XWPF-Document: I can add the specific bytes to the XWPFDocument-Object as PictureData and/or PackagePictureData without a problem but the write method isn't creating a word/media content.

XWPFDocument outDoc = new XWPFDocument();
outDoc.CreateParagraph().CreateRun().AddPicture(new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite), (int)PictureType.JPEG, "Background.jpg", 200, 400);
FileStream outStream = new FileStream("Print.docx", FileMode.Create,FileAccess.ReadWrite);
outDoc.Write(outStream);
...

Without having a media-dir and image-file in the docx archive , there is a placeholder in the word doc instead of the actual picture (as to be expected).

I also tried to read a template docx in that contains the image and write it out into another file (respect. copy it) and in that case the picture is in the docx but the file is having 100s of pages instead of 1 making it useless.

That looks like iam just missing something while adding the picture as written above but maybe this is a bug. It would be really nice if you could check this out and come up with a fix or advise.

Thanks in advance.

from npoi.

tonyqus avatar tonyqus commented on May 11, 2024

As I remember, this issue has been fixed in 2.4.1. Can you check the latest release on nuget and come back to this issue again?

from npoi.

ssementsov avatar ssementsov commented on May 11, 2024

Hi,
I'm having the same problem:

           XWPFDocument document = new XWPFDocument();
            XWPFParagraph paragraph = document.CreateParagraph();
            XWPFRun run = paragraph.CreateRun();

            byte[] pictureData = ResourceHelper.GetEmbeddedResourceAsBytes("logo.jpeg");

            run.AddPicture(new MemoryStream(pictureData), (int)PictureType.JPEG, "image1.jpeg", 229, 74);

            // count = 1
            var count = run.GetEmbeddedPictures().Count;

            var stream = new FileStream("D:\\addPicture.docx", FileMode.Create);
            document.Write(stream);
            stream.Close();

I also saw your Test "TestAddPicture":

          XWPFDocument doc = XWPFTestDataSamples.OpenSampleDocument("TestDocument.docx");
            XWPFParagraph p = doc.GetParagraphArray(2);
            XWPFRun r = p.Runs[0];

            Assert.AreEqual(0, doc.AllPictures.Count);
            Assert.AreEqual(0, r.GetEmbeddedPictures().Count);

            r.AddPicture(new MemoryStream(new byte[0]), (int)PictureType.JPEG, "test.jpg", 21, 32);

            Assert.AreEqual(1, doc.AllPictures.Count);
            Assert.AreEqual(1, r.GetEmbeddedPictures().Count);

But in result file, we don't get any images...
Thanks!

from npoi.

ssementsov avatar ssementsov commented on May 11, 2024

Hi,
I'm trying to add a picture into the footer of a word document, using the method AddPicture of Run object.
The word document is generated, but open the document the image is not available.

Using the same method with a Paragraph and a Run contained into the body of the document it work well.

How can I fix this problem?

Thanks

Hi,
can you show me please your code with a Paragraph and a Run that work well?
Thanks!

from npoi.

WagnerSereia avatar WagnerSereia commented on May 11, 2024

Hi @tonyqus, did you manage to solve this bug?
I am getting the same problem in my tests, following the same code suggestions.

from npoi.

tonyqus avatar tonyqus commented on May 11, 2024

duplicate with #373

from npoi.

jorgelodev avatar jorgelodev commented on May 11, 2024

Hi,
I'm trying to add a picture into the footer of a word document, using the method AddPicture of Run object.
The word document is generated, but open the document the image is not available.

Using the same method with a Paragraph and a Run contained into the body of the document it work well.

How can I fix this problem?

Thanks

Hello, the problem tha I'm facing is: when I add a image first into the header, and after into the body, the image from the body is not available. And if I add the image first into the body, and after into the header, the image from the body is not available...

How can I fix this problem?

Thanks

from npoi.

tonyqus avatar tonyqus commented on May 11, 2024

@jorgelodev can you open a new issue for your case? This one is closed and released with NPOI 2.5.2.

from npoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.