我已宣布在android清单中
I have declared in android manifest
使用权限android:name =android.permission.WRITE_EXTERNAL_STORAGE
和build gradle版本是:
and build gradle version is :
compileSdkVersion 24 buildToolsVersion '24.0.0' minSdkVersion 8 targetSdkVersion 24应用程序可以正常运行,但是可以不创建pdf文件,我找不到。
The application can run normally, but can't create pdf file and I can't find.
推荐答案如果我看一下你问题的主题,那么答案就是答案很简单。你正在使用 FileOutputStream 在文件系统上创建一个PDF。在主题中你问:如何在内存中创建pdf文件?这很简单.iText接受任何 OutputStream ,所以答案是:使用 ByteArrayOutputStream 而不是 FileOutputStream 。
If I look at the subject of your question, then the answer is simple. You are creating a PDF on the file system using a FileOutputStream. In the subject you ask: "How to create pdf files in memory?" That is simple. iText accepts any OutputStream, so the answer is: use a ByteArrayOutputStream instead of a FileOutputStream.
参见使用iText,在内存上生成一个在磁盘上生成的PDF而不是
Document document = new Document(); ByteArrayOutputStream out = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(documento, out); (...) byte[] pdf = out.getBytes();但是,为什么要在Android设备的内存中创建PDF?你打算用这些字节做什么?如果您只有 byte [] ,则无法显示PDF。在我对这个问题的回答中解释了这一点:显示存储在ByteArrayOutputStream中的PDF文档(不在文件中)
However, why would you want to create a PDF in memory on an Android device? What are you going to do with those bytes? You can't show the PDF if you only have a byte[]. That is explained in my answer to this question: Display PDF document stored in a ByteArrayOutputStream (not in a file)
您还会注意到以下问题仍未得到答复(因为没有答案): 如何在Android上将ByteArrayOutputStream可视化为PDF?
You will also notice that the following question remained unanswered (because there is no answer): How to visualize a ByteArrayOutputStream as PDF on Android?
您的问题在最后更改主题,您写道:应用程序可以正常运行,但无法创建pdf文件,我找不到。这听起来好像你不知道如何在Android上的文件系统中编写PDF。这与你在这个主题中提到的问题不同。之前已经多次回答过这个问题:
Your question changes subject towards the end, where you write: "The application can run normally, but can't create pdf file and I can't find." This sounds as if you don't know how to write a PDF to the file system on Android. That's a different question than what you mention in the subject. That question has been answered many times before:
- 创建Android中的PDF
- 如何使用eclipse解决android编程中的只读文件系统错误
- 如何在使用iText创建的Sdcard上保存PDF文件?
- 无法在Android中运行iText库的简单程序
- 将iText创建的PDF文件保存为内部存储器为MODE_WORLD_READABLE
- Creating PDFs in android
- how to solve read only file system error in android programming with eclipse
- How to save PDF file on Sdcard created using iText?
- Not able to run simple program of iText library in android
- Save iText created PDF to internal memory as MODE_WORLD_READABLE
更多推荐
如何在内存中创建pdf文件
发布评论