Framework iText generating empty file (0 kb) [closed]

1

I have a project that was generating the PDFs normally, it generated the texts and images in the file, it was a beauty, however, a while later it left unexpectedly to generate the file in the correct way, no matter what I do it will always generate the PDF with 0kb, completely empty, I did not move in the class and it appeared, I confess I do not understand, I already removed it from Gradle and put it back, I already created a new project just to test this framework and nothing if it solves, will the problem be in Android Studio? Is it asking me to upgrade to version 1.2.1.1 or will it be the framework ????

I'll send a class from my test project, it's very simple:

 public class TestePDF {

public void gerar() {
    String pathPdf = Environment.getExternalStorageDirectory()
            + "/Teste PDF/Notificações Teste/";

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try{
        File dir = new File(pathPdf);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File file = new File(dir, "Teste.pdf");
        FileOutputStream fOut = new FileOutputStream(file);
        document.open();
        Font bold = FontFactory.getFont("Times-Roman, Bold", 12, Font.BOLD);
        Paragraph p00 = new Paragraph("Teste Bold", bold);
        Paragraph p01 = new Paragraph("Teste sem bold");
        p00.setAlignment(Paragraph.ALIGN_LEFT);
        p01.setAlignment(Paragraph.ALIGN_LEFT);
        document.add(p00);
        document.add(Chunk.NEWLINE);
        document.add(p01);
        document.add(Chunk.NEWLINE);
        document.close();
        Log.i("PDF", pathPdf);
    }catch (Exception e){
        Log.e("Erro PDF", e.toString());
    }
}

}

Even so, it only generates 0 kb file.

GRADLE:

compile 'com.itextpdf:itextpdf:5.0.6'
    
asked by anonymous 25.05.2015 / 20:34

1 answer

0

Well guys, problem solved, I hope it is useful for someone, in my project, I should have deleted a line, I searched and noticed the lack:

PdfWriter.getInstance(document, fOut);

I need to add before this line:

document.open(); 
    
26.05.2015 / 20:31