问题
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 ?
回答1:
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.
来源:https://stackoverflow.com/questions/29329325/how-to-save-pdf-file-on-sdcard-created-using-itext