How to save PDF file on Sdcard created using iText?

自闭症网瘾萝莉.ら 提交于 2019-12-24 23:22:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!