I was trying to create a pdf file in my Android application, as I did not find anything that worked, today I was able to solve the problem on my own. Follow the code to whoever interests.
Here are the imports corresponding to iText.jar
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
Here the code working perfectly
private void criandoPdf() {
try {
String filename = "teste.pdf";
document = new Document(PageSize.A4);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/MeuPdf";
File dir = new File(path, filename);
if (!dir.exists()) {
dir.getParentFile().mkdirs();
}
FileOutputStream fOut = new FileOutputStream(dir);
fOut.flush();
PdfWriter.getInstance(document, fOut);
document.open();
document.add(new Paragraph("Aqui esta meu pdf"));
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
document.close();
}
}
If someone knows how to work well with iText, feel free to post a good link to implement more advanced features such as insert borders and lines. It's not a question, just post anything relevant, just to add and help those who are trying the same.