0

I am trying to create pdf files using iText.

I included itextpdf-5.5.3.jar into my project and following steps in this tutorial:

http://blog.mettletech.co/wp/blog/generate-pdf-file-in-android/

But when this code i getting following errors:

10-30 16:52:57.163: E/dalvikvm(28969): Could not find class 'com.itextpdf.awt.PdfPrinterGraphics2D', referenced from method com.itextpdf.text.pdf.PdfContentByte.createPrinterGraphicsShapes
10-30 16:52:57.213: E/dalvikvm(28969): Could not find class 'java.awt.image.PixelGrabber', referenced from method com.itextpdf.text.Image.getInstance
10-30 16:52:57.223: E/dalvikvm(28969): Could not find class 'java.awt.image.BufferedImage', referenced from method com.itextpdf.text.Image.getInstance

I dont get any errors on simplier pdf but i am getting thesee errors while creating more complex pdfs including tables etc.

Can you give me a lead on this?

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
Bahadir Gul
  • 152
  • 3
  • 19

1 Answers1

4

The problem you are experiencing isn't caused by iText, but by a specific design choice made by the people who created Android. If you look at the official page about iText for Android (better known as iTextG), you learn that some classes are forbidden on Android. That's why it's important to use the iTextG jar and not the ordinary iText jar:

References to any of the classes not on the Google App Engine whitelist have been removed.

As you know from your Android lessons, all classes in the awt packages (and in the nio packages, etc...) can not be used on Android. Hence you can not use classes such as PdfGraphics2D because that class is an implementation of the abstract java.awt.Graphics2D class that is not on Google's white list for Android and GAE.

So either you are making the mistake of introducing AWT-related functionality, or you are not using the Android port of iText.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • You are totally right. And as i found i was getting error on setting Image. i set it with this code: Bitmap bitmap =BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.imageName); ByteArrayOutputStream out = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 85 , out); Image image = Image.getInstance(out.toByteArray()); – Bahadir Gul Oct 30 '14 at 16:04
  • @Bruno Lowagie, it seems that the awt is still in the itextg, when including the itextg jar into the project, it is generating an error related to awt, like here, https://stackoverflow.com/questions/31098721/including-itextg-in-an-android-project-using-android-studio – Noor Jun 28 '15 at 10:27