Q:
How do I add an image on a PDF page in Android?
I tried this code
Image img = Image.create(doc.getSDFDoc(), (
"com.pdftron.pdfnet.demo.pdfviewctrl:raw/" + "background.png"));
And I get an exception. The raw folder is inside the res folder.
Not sure how to load the image from the local resources in an Android app.
----------
A:
You can not access files in the raw/assets folder using an absolute path
because the files are stored inside the apk (see *
http://stackoverflow.com/a/9563467* <http://stackoverflow.com/a/9563467>).
One way to access them is to use the *Resources*<http://developer.android.com/reference/android/content/res/Resources.html>class, method openRawResource(), but then you only have either an
InputStream or a file descriptor. And since there is no support for ImageIO
in Android, there is no easy way to get a java.awt.Image object from a
resource file.
You can store the image in the sdcard and then use something like this:
String path = Environment.getExternalStorageDirectory().toString() +
"/background.png";
Image img = Image.create(doc, path);