0

我最近在 android studio 上编写了这个小的 java 代码来测试 android 的 iTextG 库。这个代码应该从 editText 字段中获取文本并从文本创建一个 pdf 文件。

 public void createPDF(View view){
//reference to EditText
        EditText et=(EditText)findViewById(R.id.txt_input);
//create document object
        Document doc=new Document();
//output file path
        String outpath=Environment.getExternalStorageDirectory()+"/mypdf.pdf";
        try {
//create pdf writer instance
            PdfWriter.getInstance(doc, new FileOutputStream(outpath));
//open the document for writing
            doc.open();
//add paragraph to the document
            doc.add(new Paragraph(et.getText().toString()));
//close the document
            doc.close();

        } catch (FileNotFoundException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DocumentException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

但问题是我没有在手机中获得所需的 pdf 文件。可能是什么问题。代码有什么问题吗。

4

0 回答 0