0
    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.

Vishrant
  • 15,456
  • 11
  • 71
  • 120
  • try to set the resolution before converting to pdf doc, its obvious if you try to write large size image it will not fit the doc, else you will have to set the page layout, may be portrait or landscape. – Vishrant Feb 11 '16 at 06:17
  • Thank you for answer can you tell how can i set the size ... – Anukul Mittal Feb 11 '16 at 06:45

1 Answers1

0

The error is caused by medikmResourceRequest.getResourceImage() and b64Image.getBytes().

Your program should NOT transfer byte[](image data) via String. When JVM convert byte[] to String, if the byte data cannot mapping to char of String's charset. It will be replace to ?. The byte[] returned by b64Image.getByte() is differnet than original data and cause your image broken.

Beck Yang
  • 3,004
  • 2
  • 21
  • 26
  • Thank you for answer my problem is getting solved by using `Rectangle one = new Rectangle(1500,1100); document.setPageSize(one);` – Anukul Mittal Feb 11 '16 at 10:28