PdfWriter类不会创建任何pdf

时间:2019-02-22 12:10:10

标签: android pdf-generation pdf-writer

这是我的代码。它工作正常,但是在我的Android手机中没有pdf文件。它在Toast消息中显示路径storage/emulated/0pdfcc.pdf,但是在我的手机中没有这样的文件。
我该怎么办?
预先感谢

public void PdfCreate(View view){
    Toast.makeText(this,"1",Toast.LENGTH_SHORT).show();
    try {
        Toast.makeText(this,"2",Toast.LENGTH_SHORT).show();
        // File root=Environment.getExternalStorageDirectory();
        //File directory=new File(root.getAbsolutePath()+"createPDF.pdf");
        String path = Environment.getExternalStorageDirectory()
                                 .getAbsolutePath() + "/pdfcc.pdf";
        Toast.makeText(this," not done" +path,Toast.LENGTH_SHORT).show();

        PdfWriter.getInstance(document,new FileOutputStream(path));
        document.open();
        document.add(new Paragraph(text.getText().toString()));
        document.close();

        Toast.makeText(this,"done",Toast.LENGTH_SHORT).show();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案