Comments (8)
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.
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.
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.
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.
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.
duplicate with #373
from npoi.
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.
@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)
- lee
- SetCellFormula("T.INV(0.99,100)*126+36/2") report error HOT 2
- insert new row very slowly in middle sheet HOT 3
- Encryptor.GetDataStream throws System.NullReferenceException HOT 1
- Word Formatting changes after saving with NPOI HOT 1
- How to create scattered chart in excel without markers using NPOI 2.6.2 and C# HOT 1
- Formula calculation exception HOT 1
- Workbook.Write cause OutOfMemory exception while there are 100,000 rows in the Excel file HOT 2
- read xlsx file exception HOT 3
- Adding rows of data into existing xlsx file with pivot tables and charts result with unusable file. How to solve? HOT 5
- Having Issue while reading a excel file with .xls extension HOT 4
- To set Colors to each column in ColumnChart in NPOI package HOT 1
- XSSF AddPicture Slow HOT 4
- Charts Not Copied HOT 12
- Saving a Workbook and Re-opening It Corrupts the File HOT 13
- Error 0x800A03EC when opening with Excel.Application after saving with NPOI HOT 5
- Overwrite existing Excel results in problem with content HOT 3
- How can protected workbook excel file with npoi HOT 3
- Formula openxml gets corrupted after opened and saved by NPOI 2.7.0 HOT 12
- Excel file is always modified even if only opened for reading HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from npoi.