将数组项保存在列表视图中,然后将其显示给用户,并在用户填写后将其另存为pdf文件

时间:2018-08-30 00:50:12

标签: android itext

我试图将TextView和EditText保存在ListView中,并让用户写入EditText并将其另存为PDF文件。如何将数组添加到文档?请看我的代码。

public List<Product> getProductList() {
    //pseudo code to get product, replace your code to get real product here
    productList = new ArrayList<>();
    productList.add(new Product("item1 : " ,"  /  /     "));
    productList.add(new Product("item2:" ,""));
    productList.add(new Product("item3:" ,""));

    return productList;
}

 public void createPDF(View view){

//create document object
        Document doc=new Document();

//output file path
        String outpath=Environment.getExternalStorageDirectory()+"/HHelpFolder/allfile.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(String.valueOf(productList)));
//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();
        }
    }}

我应该使用Paragraph()还是PageInfo还是类似的东西?

0 个答案:

没有答案