I have a problem creating a PDF using iText on Android.
I have to save in the internal memory of the device,
but it is giving error because I do not know the way to save because in the tutorial it 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
is where the path goes.
An image of LogCat: