1
I was trying to create a pdf file on my Android application, as I could not find anything that worked, today I managed to solve the problem on my own. Follow the code to whom you are interested.
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 for implementing more advanced features such as, inserting borders and lines. It’s not a question, just post anything relevant, just to aggregate and help anyone who’s trying the same.
Thanks friend, it is very useful yes. Here is a link with some basic functions to those who need to create a table. http://itextpdf.com/themes/keyword.php?id=152
– Cesar Roberto Martins