如何在使用iText创建的Sdcard上保存PDF文件?
我正在使用iText库从给定字符串创建pdf文件。但是如何将此文档文件保存到外部存储?
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 ?
让 fileName
指向外部存储,而不是Hello+。pdf
。
您可以通过 getExternalFilesDir()
访问您自己应用在外部存储设备上的特定位置,调用活动
或其他上下文
。或者,您可以考虑将文件存储在公共位置,例如 getExternalStoragePublicDirectory()
在 Environment
上提供的位置。
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
.
最有可能的是,您需要持有 WRITE_EXTERNAL_STORAGE
权限,方法是< ;使用权限>
元素,用于清单中的正确位置。如果您的 minSdkVersion
为19或更高,并且您使用 getExternalFilesDir()
,则不需要此权限。
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.