在android中创建PDF

编程入门 行业动态 更新时间:2024-10-25 21:28:40
本文介绍了在android中创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用此代码在android中生成pdf文件,但它给了我找不到文件异常

I am using this code to generate pdf file in android but it gives me "File not found exception"

try { OutputStream file = new FileOutputStream(new File("D:\\Test.pdf")); Document document = new Document(); // PdfWriter.getInstance(document, new FileOutputStream(FILE)); PdfWriter.getInstance(document, file); document.open(); addMetaData(document); addTitlePage(document); addContent(document); //createImage(); document.close(); } catch (Exception e) { e.printStackTrace(); }

PdfWriter.getInstance(document, file);

它表示Java.io.FileNotFOundException。我必须创建新文件然后为什么打开一个甚至没有生成的文件?这段代码出了什么问题?

It says "Java.io.FileNotFOundException". I have to create new file then why is it open a file which is not even generated yet? what is wrong with this code?

推荐答案

我不认为D:\是android中的有效文件位置

I dont think "D:\" is a valid file location in android

尝试

OutputStream file = new FileOutputStream(newFile(Environment.getExternalStorageDirectory()。toString ,test.pdf));

如果你正在处理android中的文件系统,将来会有一些额外的信息,因为android是基于unix的路径分隔符是'/'而不是'\'。 '\'分隔符(据我所知)是Windows独有的东西,因为 D:

As a bit of extra info for in future if you are dealing with file systems in android, becasue android is unix based the path separator is '/' not '\'. The '\' separator is (as far as I know) something unique to windows as is D:

更多推荐

在android中创建PDF

本文发布于:2023-10-31 01:49:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:android   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!