I'm getting an IOException while i'm trying to create a PDF using Itext. The error says i'm trying to write to read-only storage where as I have added the required permissions in the manifest file.
Also i'm using Cordova 3.5.
Here is the code:
public class PdfCreator {
String TAG = "PdfCreator";
public void createPdf(){
try {
Log.d(TAG, Environment.getExternalStorageDirectory().getPath() + "/Hello.pdf");
OutputStream file = new FileOutputStream(new File(Environment.getExternalStorageDirectory().getPath() + "/Hello.pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
document.add(new Paragraph("Hello world, iText"));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Stake Trace:
09-08 05:15:42.501: W/System.err(1114): java.io.FileNotFoundException: /storage/sdcard/Hello.pdf: open failed: EROFS (Read-only file system)
09-08 05:15:42.531: W/System.err(1114): at libcore.io.IoBridge.open(IoBridge.java:409)
09-08 05:15:42.531: W/System.err(1114): at java.io.FileOutputStream.<init> (FileOutputStream.java:88)
09-08 05:15:42.581: W/System.err(1114): at java.io.FileOutputStream.<init> (FileOutputStream.java:73)
09-08 05:15:42.581: W/System.err(1114): at com.idsil.pdfapp.PdfCreator.createPdf(PdfCreator.java:19)
09-08 05:15:42.581: W/System.err(1114): at com.idsil.pdfapp.PdfApp.onCreate(PdfApp.java:36)
09-08 05:15:42.581: W/System.err(1114): at android.app.Activity.performCreate(Activity.java:5133)
09-08 05:15:42.581: W/System.err(1114): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-08 05:15:42.581: W/System.err(1114): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-08 05:15:42.581: W/System.err(1114): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-08 05:15:42.591: W/System.err(1114): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-08 05:15:42.591: W/System.err(1114): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-08 05:15:42.631: W/System.err(1114): at android.os.Handler.dispatchMessage(Handler.java:99)
09-08 05:15:42.631: W/System.err(1114): at android.os.Looper.loop(Looper.java:137)
09-08 05:15:42.658: W/System.err(1114): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-08 05:15:42.661: W/System.err(1114): at java.lang.reflect.Method.invokeNative(Native Method)
09-08 05:15:42.661: W/System.err(1114): at java.lang.reflect.Method.invoke(Method.java:525)
09-08 05:15:42.661: W/System.err(1114): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-08 05:15:42.661: W/System.err(1114): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-08 05:15:42.661: W/System.err(1114): at dalvik.system.NativeStart.main(Native Method)
09-08 05:15:42.691: W/System.err(1114): Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system)
09-08 05:15:42.691: W/System.err(1114): at libcore.io.Posix.open(Native Method)
09-08 05:15:42.691: W/System.err(1114): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-08 05:15:42.691: W/System.err(1114): at libcore.io.IoBridge.open(IoBridge.java:393)
Any help is appreciated.
Thanks in advance.
0 comments:
Post a Comment