0

I recently wrote this small java code on android studio to test the iTextG library for android.This code is supposed to take the text from the editText field and create a pdf file from the text.

 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();
        }
    }

}

But the problem is I am not getting the desired pdf file in my phone. What could be the possible problem. Is there anything wrong with the code.

Sourav Das
  • 33
  • 1
  • 5

0 Answers0