Embed multiple jpeg images into EXCEL programmatically? - java

Dear Stackoverflowers,
Outputting an Excel spreadsheet with images is a requirement of a project I'm doing. I've done a little research and found the following (perhaps incorrect) consensus :
various python libs for creating excels sheets work well
it is possible to insert images (but only in bmp)
the "internal format" of images used in excel files, is complicated, which may be why there is no 3rd party library support for inserting normal formats like jpeg.
I don't want to use or convert to bmp. Why? BMP are not compressed well, and these will be big sheets, so I want to mitigate the size impact of images (1 per row) as much as possible.
My ideal answer comes from someone who has actually done this. The method suggested can be in Java,Ruby,Python,(but not .NET) or some other creative way of doing it.
I'm really hoping someone out there has a solution, as I anticipate this could be a tricky area (similar in complexity to playing around with PDFs, perhaps).

The Perl module Excel::Writer::XLSX can insert JPEG, PNG, and BMP images into a new Excel workbook.
I am currently porting it to a Python module called XlsxWriter and the inset_image() function is near the top of the TODO list.
Update: As of version 0.1.6 of XlsxWriter it is now possible to a add PNG/JPEG images. See the example in the documentation.

As said in the comment above, Apache POI can solve your problem.
I did a little research and this example should be useful Apache POI Excel Insert an Image

Related

Libdmtx vs ZXing for DataMatrix Decoding?

How reliable is ZXing's barcode localization for DataMatrix decoding compared to libdmtx?
I have a set of png image files of stickers (proprietary, so unfortunately I'm not able to share them) containing DataMatrix barcodes. These stickers sit on flat surfaces, have very nice quiet zones and are generally centered in the image, but suffer from inequal lighting conditions and slight dust, likely the largest obstacle to reliable decoding.
I'd like to use a modifiable Java library to decode them and it seems that ZXing is the only open-source option (open to other suggestions). However, upon running these images through the ZXing online decoder, I consistently get NO BARCODE FOUND, even on the cleanest images. In contrast, when I run the same images through proprietary online decoders, like Inlite's Free Online Barcode Reader, I get reliable decodes for all the images. My company has implemented a library in C that also reliable decodes the barcode images by processing them and calling libdmtx. Similarly, this online DataMatrix decoder built on libdmtx can also reliably read my image files.
Is the barcode localization in ZXing significantly inferior to libdmtx?
If I attempt the same preprocessing on the image files before I run them through ZXing, could I achieve similar results? I have a strong preference for a Java library (ZXing), but I may have no choice but to use libdmtx. Would appreciate any insight, thanks!
I had similar problem as you but on encoding side. As per my findings Zxing is certainly inferior to Libdmtx. We are using both libraries in house in C++ and Java project.
There is a case when Zxing breaks while generating barcode look at my comments here:
https://github.com/zxing/zxing/issues/624
However Libdmtx works flowless. The other free options you have in java world are (they are for encoding):
barcode4j
OkapiBarcode
Another alternative is the relatively new ZXing cpp port here: https://github.com/nu-book/zxing-cpp.
It contains a completely new DataMatrix detector that was meant to fix serious limitations of the Java upstream version. It was specifically designed to deal with low resolution images (module size as low as around 2 pixels) and symbols that have just the required 1 module quite zone and a busy background.
The following comparison is certainly not 'fair' but I just had the dmtxread utility of the libdmtx try my test set of images and it missed 3 of 17 samples and took a whooping 300 times as long compared to my code :).

What's the best way to save PowerPoint slides as images

I'm trying to find a way to copy the whole slide, and paste it with the formatting of 'as an image' to a blank slide, using POI's APIs.
The reason why I'm trying to do this is because I want to save each slide as an image.
The POI's Slide.draw() API by itself does not do a very good job of saving the slides' contents to images.
For example it cannot draw the following two types of objects:
Tables created on PowerPoint
Charts pasted from Excel
Is there any way to 'copy' and 'paste with formatting (as an image)' via POI, just like you do these two operations on MS PowerPoint running on a Windows, in order to save the slides as they are?
Since Slide.draw() works just fine with images, once I paste all the objects as a single flat image onto a slide (using POI), I'll be good to go.
Or if there is a better way to save the slides contents as intact as possible, could you please let me know?
The license which comes along with the method needs to be Apache license or otherwise something more permissive.
Also, I read the following post:
Programmatically extracting slides as images from a PowerPoint presentation (.PPT)
unoconv is GPL-licensed, so it is not an option for us.
JODConverter is LGPL-licensed; I'm not sure if it's acceptable so I will talk to my boss and check.
Then I ran the POI as a command line tool, as suggested by Michael,
but I ended up getting the same problem (tables and pasted Excel charts
do not show up in the saved images.)
Thanks.

Converting docx/ODT to image using Java

I am working on a Spring REST service based web application (UI is based on HTML5, backbone.js). The actual requirement is, an uploaded document (could be any document like excel, word, ppt, pdf etc) requires an preview option using which an user can view the document in the browser (user may or may not have office installed).
My idea is to convert the documents into images and display them to the user. On searching, i found multiple ways to convert a PDF to image but not much ODT to image (Note: I am looking for an open source). JODConverter, docx4j can be used to convert the documents to pdf. Then I can convert these PDFs to images. But is this the right way. Is there any other efficient way to achieve the same. Please suggest and point me to the right direction.
Thanks in advance.
Gopi
Yes, you won't do any better than .docx to .pdf to image. You really need a stable workflow, and this is as good as you'll find for this purpose, unless you're running on a Microsoft server and you have access to the official Microsoft Office stuff.
For previews, docx4j or similar will do just fine. Not everything converts perfectly, but it should be fine for a preview.

java save an image in RAW format or so from a JPEG without loading its full contents

I was wondering if it is possible to load a huge JPEG (see my previous question there) and save it / use it in a quickly-loadable format, without loading its fully decoded contents into memory.
The main idea is to have a file format (or a function I'm not aware of which would do that natively in Java) allowing to load dynamically a given area of the image, without loading 800MB of data.
I'm actually using a tiling algorithm to render the image, but it needs to load the full image (thanks to mKorbel and Gerard Le Blanc), but this "preloading" step remains quite long.
I don't figure out how to do that (and first of all, is it possible ?), since Google did not help me a lot (maybe bad-english searching ?)
I found what I needed there :
very large image manipulation and tiling
The Java JAI lib has a lot of features to handle these kind of problems, and is supported by Oracle, which means it is (theoretically) stable and sustainable.
Thanks to #BryanD !

Merging pdf:s with pdfBox creates a unnecessary large file

Massive amount of hit on this topic but only crappy threads :(
I merge a bunch of pdf files with pdfBox. Easy with a class for the purpose.
But the reult is a very large file. I have no exact figure now but its easy twise the size compared to a merge done by a ordinary desctop app.
Not acceptable im afraid.
The problem seems to be similar to this (split in this case, same same but diffrent):
https://issues.apache.org/jira/browse/PDFBOX-785
After some googling I think the problem is that the merge produces a barebones merged PDF file, and a large one at that, without compresson.
According this blog some java pdf libs can handle compression:
http://pdf-house.blogspot.com/
Itext handles this according with pdfstamper setFullCompression().
PDF/CompressPdfdocument.htm">http://www.java2s.com/Tutorial/Java/0419_PDF/CompressPdfdocument.htm
But i also bumped in to the ghost script project.
https://www.linux.com/news/software/applications/8229-putting-together-pdf-files
So, I need a second opinion. This ghost script seems cool, but itext does the trick according to google.
Am I on the right track? What to choose? One of the above or somthing intirely diffrent?
Tnx!
Try mixing PDFBox for merging with itext for compression.
See groovy example: http://pastebin.com/w8Rz8uha
I tested it with http://www.tobcon.ie/assets/files/test.pdf and uncompressed.pdf is 302kb and compressed.pdf is 58kb. (100 duplicated pages)

Categories