在Android的将文本转换为PDF格式,利用iText [英] Converting text to PDF in Android, using iText
本文介绍了在Android的将文本转换为PDF格式,利用iText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将文本转换为PDF在Android中,利用iText(这里),但它给出了找不到文件异常。 这里是code:
I tried to convert a text to PDF in Android, using iText (here ), but it gives the "File not found" exception. Here is the code:
try
{
PdfWriter.getInstance(document, new FileOutputStream("hello.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
document.close();
Log.d("OK", "done");
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (DocumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
你可以帮我吗?谢谢
Would you please help me? Thanks
推荐答案
这完美的作品在我的情况,
This works perfect in my case,
try
{
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory() + "/hello.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
document.close();
Log.d("OK", "done");
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (DocumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
和清单文件,
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这篇关于在Android的将文本转换为PDF格式,利用iText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文