Document document = new Document();
String b64Image = medikmResourceRequest.getResourceImage();
String fileName = resourceDir+"/"+medikmResourceRequest.getPhysicianId()+"/"+medikmResourceRequest.getName()+" "+ System.currentTimeMillis() +".pdf";
PdfWriter.getInstance(document, new FileOutputStream(new File(fileName)));
document.open();
byte[] decoded = Base64.decodeBase64(b64Image.getBytes());
document.add(Image.getInstance(decoded));
document.close();
Above code is not working properly for large images, they are getting cropped but its working fine for small image.
Please suggest.
The error is caused by
medikmResourceRequest.getResourceImage()
andb64Image.getBytes()
.Your program should NOT transfer
byte[]
(image data) via String. When JVM convertbyte[]
to String, if the byte data cannot mapping to char of String's charset. It will be replace to?
. Thebyte[]
returned byb64Image.getByte()
is differnet than original data and cause your image broken.