4
I have a problem to create a PDF using iText on Android.
I have to save in the device’s internal memory,
but this giving error because I do not know the way to save because in the tutorial he saved in C:/temp
.
This is the code
public class PdfActivity extends Activity {
private static String file = "texto";
private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
private static Font smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12,Font.BOLD);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pdf);
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
addTitlePage(document);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void addTitlePage(Document document)
throws DocumentException{
Paragraph preface = new Paragraph();
//pula uma linha
addEmptyFile(preface, 1);
//titulo com font grande
preface.add(new Paragraph("Documento de Teste", catFont));
addEmptyFile(preface, 1);
preface.add(new Paragraph("Conteudo teste do corpo, um texto simples para ser exibido como corpo do documento", smallBold));
document.add(preface);
document.newPage();
}
//metodo para pular uma linha
private static void addEmptyFile(Paragraph paragraph, int number) {
for(int i=0; i<number; i++){
paragraph.add(new Paragraph(""));
}
}
}
The variable file
That’s where the road goes.
A picture of Logcat:
I got what was happening was that he did not find the library classes even exporting the jar, so I copied the file and pasted it in the libs folder and it worked, his code helped me a lot created the document, thanks
– Vinicius