0

I am using iText library to create a pdf file from given string. But how can i save this document file to external storage ?

        Document document = new Document();
        fileName = "Hello" + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(fileName));
        document.open();
        document.add(new Paragraph("Hellooo"));
        document.close();

What should i do after it to save this document to external storage ?

Wahib
  • 259
  • 1
  • 2
  • 8

1 Answers1

2

Have fileName point to a location on external storage, rather than be "Hello" + ".pdf".

You can access your own app's specific spot on external storage via getExternalFilesDir(), called on your Activity or other Context. Or, you could consider storing the file in a common location, such as those available from getExternalStoragePublicDirectory() on Environment.

Most likely, you will need to hold the WRITE_EXTERNAL_STORAGE permission, by having a <uses-permission> element for it in the right spot in your manifest. If your minSdkVersion is 19 or higher, and you are using getExternalFilesDir(), you will not need this permission.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491