Create an Instance of Com. Lowagie. Text. Image from Byte[]

I am working on a web-app that allows user to send some pictures to server and then server sends back a pdf file which contains those pictures and some additional data. I was able to receive pictures on my server side. Basically I have them as byte[]. To create pdf file I use iText. In order to embed pictures I have to use com.lowagie.text.Image object. However, how to create instance of com.lowagie.text.Image from byte[] that I have?

1

1 Answer

In com.lowagie.text.Image there is a method getInstance() that is overloaded to take different inputs, including String filename and byte[] imgb. (See )

com.lowagie.text.Image image01 = com.lowagie.text.Image.getInstance("test.jpg");
document.add(image01);

byte[] byte_array = .......

com.lowagie.text.Image image02 = com.lowagie.text.Image.getInstance(byte_array);
document.add(image02);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest