【发布时间】:2014-09-02 07:17:58
【问题描述】:
在我的 android 应用程序中,如果我单击“生成 PDF”按钮,则会在 sd 卡中创建 pdf。如果我打开此 pdf,我可以复制文本,但我不会。意思是我想要只读 使用生成的 pdf 文件。
以下是代码,
public void createPDF()
{
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
File dir = new File(path);
if(!dir.exists())
dir.mkdirs();
Log.d("PDFCreator", "PDF Path: " + path);
System.out.println("PDF Path: "+ path);
File file = new File(dir, "sample.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1 = new Paragraph("Hi! I am generating my first PDF using DroidText");
Font paraFont= new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
//add paragraph to document
doc.add(p1);
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
}
finally
{
doc.close();
}
}
【问题讨论】:
-
我还没有测试,请告诉我这是否有效:)
-
你在使用 apache poi 吗?
-
我正在使用 droidText 0.2 jar
标签: android pdf pdf-generation android-droidtext