Access assets folder in iText pdf library in android
<p>I want to write some image from assets folder to pdf file using iText library.
If I access using sdcard then it work fine.
But if I access using assets folder then it display file not found exception.
My code is</p>

<pre><code>package com.app.ipro;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Date;

import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class MakeInvoice {
    private static String FILE = "";

    public static void main() {
        try {
            String externalStoragePath = Environment
                    .getExternalStorageDirectory().getAbsolutePath();
            System.out.println("externalStoragePath:" + externalStoragePath);
            boolean f = new File(externalStoragePath + "\\MyPDF").mkdirs();
            System.out.println("f:" + f);
            FILE = externalStoragePath + "\\MyPDF\\" + "FirstPdfabc6.pdf";
            Document document = new Document(PageSize.A4);
            PdfWriter.getInstance(document, new FileOutputStream(FILE));
            document.open();
            addMetaData(document);
            addTitlePage(document);
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private static void addMetaData(Document document) {
        document.addTitle("My first PDF");
        document.addSubject("Using iText");
        document.addKeywords("Java, PDF, iText");
        document.addAuthor("Lars Vogel");
        document.addCreator("Lars Vogel");
    }

    private static void addTitlePage(Document document)
            throws DocumentException {
        Paragraph preface = new Paragraph();
        addEmptyLine(preface, 1);
        preface.add(new Paragraph("Title of the document"));

        addEmptyLine(preface, 1);

        document.add(preface);
        String strLogo = "file:///android_asset/tmpl1/Vector_background1.jpg";


        PdfPTable table = new PdfPTable(2);
        table.setTableEvent(new tableEvent(strLogo));
        table.addCell("Name");
        table.addCell("Place");
        table.addCell("RoseIndia");
        table.addCell("Delhi");
        document.add(table);

        document.newPage();
    }

    private static void addEmptyLine(Paragraph paragraph, int number) {
        for (int i = 0; i &lt; number; i++) {
            paragraph.add(new Paragraph(" "));
        }
    }
}
</code></pre>

<p>and in table event i have write </p>

<pre><code>package com.app.ipro;

import java.io.IOException;
import java.net.MalformedURLException;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPTableEvent;


public class tableEvent implements PdfPTableEvent{
    String img;
    public tableEvent(String imgPath){
        img = imgPath;
    }

    @Override
    public void tableLayout(PdfPTable arg0, float[][] arg1, float[] arg2,
            int arg3, int arg4, PdfContentByte[] arg5) {
        // TODO Auto-generated method stub
        PdfContentByte pdfContentByte = arg5[PdfPTable.BACKGROUNDCANVAS];
        Image bgImage;
        try {
            bgImage = Image.getInstance(img);
            bgImage.setAbsolutePosition(10, 10);
            bgImage.setWidthPercentage(50);
            pdfContentByte.addImage(bgImage);
        } catch (BadElementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
</code></pre>

<p>so run time it shows exception,</p>

<pre><code>08-11 15:24:45.817: WARN/System.err(18022): java.io.FileNotFoundException: /android_asset/tmpl1/Vector_background1.jpg (No such file or directory)
08-11 15:24:45.837: WARN/System.err(18022):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
08-11 15:24:45.837: WARN/System.err(18022):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
08-11 15:24:45.847: WARN/System.err(18022):     at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:82)
08-11 15:24:45.857: WARN/System.err(18022):     at org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:85)
08-11 15:24:45.857: WARN/System.err(18022):     at org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:184)
08-11 15:24:45.867: WARN/System.err(18022):     at java.net.URL.openStream(URL.java:653)
08-11 15:24:45.867: WARN/System.err(18022):     at com.itextpdf.text.Image.getInstance(Image.java:245)
08-11 15:24:45.877: WARN/System.err(18022):     at com.itextpdf.text.Image.getInstance(Image.java:341)
08-11 15:24:45.877: WARN/System.err(18022):     at com.app.ipro.tableEvent.tableLayout(tableEvent.java:28)
08-11 15:24:45.897: WARN/System.err(18022):     at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:731)
08-11 15:24:45.897: WARN/System.err(18022):     at com.itextpdf.text.pdf.PdfPTable.writeSelectedRows(PdfPTable.java:824)
08-11 15:24:45.907: WARN/System.err(18022):     at com.itextpdf.text.pdf.ColumnText.goComposite(ColumnText.java:1524)
08-11 15:24:45.907: WARN/System.err(18022):     at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:807)
08-11 15:24:45.907: WARN/System.err(18022):     at com.itextpdf.text.pdf.ColumnText.go(ColumnText.java:795)
08-11 15:24:45.907: WARN/System.err(18022):     at com.itextpdf.text.pdf.PdfDocument.addPTable(PdfDocument.java:2361)
08-11 15:24:45.907: WARN/System.err(18022):     at com.itextpdf.text.pdf.PdfDocument.add(PdfDocument.java:673)
08-11 15:24:45.917: WARN/System.err(18022):     at com.itextpdf.text.Document.add(Document.java:282)
08-11 15:24:45.927: WARN/System.err(18022):     at com.app.ipro.MakeInvoice.addTitlePage(MakeInvoice.java:87)
08-11 15:24:45.927: WARN/System.err(18022):     at com.app.ipro.MakeInvoice.main(MakeInvoice.java:45)
08-11 15:24:45.937: WARN/System.err(18022):     at com.app.ipro.Other$1.onClick(Other.java:47)
08-11 15:24:45.937: WARN/System.err(18022):     at android.view.View.performClick(View.java:2408)
08-11 15:24:45.937: WARN/System.err(18022):     at android.view.View$PerformClick.run(View.java:8816)
08-11 15:24:45.947: WARN/System.err(18022):     at android.os.Handler.handleCallback(Handler.java:587)
08-11 15:24:45.947: WARN/System.err(18022):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-11 15:24:45.967: WARN/System.err(18022):     at android.os.Looper.loop(Looper.java:123)
08-11 15:24:45.967: WARN/System.err(18022):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-11 15:24:45.977: WARN/System.err(18022):     at java.lang.reflect.Method.invokeNative(Native Method)
08-11 15:24:45.977: WARN/System.err(18022):     at java.lang.reflect.Method.invoke(Method.java:521)
08-11 15:24:45.987: WARN/System.err(18022):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-11 15:24:45.987: WARN/System.err(18022):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-11 15:24:45.987: WARN/System.err(18022):     at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>If I refer same image from sdcard then it work perfect, but I want to do using assets folder.
Please help me to come out</p>
