如何在使用iText创建的Sdcard上保存PDF文件? [英] How to save PDF file on Sdcard created using iText?

查看:182
本文介绍了如何在使用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.

这篇关于如何在使用iText创建的Sdcard上保存PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆