How to set up a report with photos in pdf ITEXT

0

I have tried everything and everything happens. But now I put a code and it ran ok with no problem but the file can not generate so I do not know if I have to link with something in xml.

main activity

'package e.danie.testee;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileOutputStream;

public class MainActivity extends AppCompatActivity {
    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_main);

    try
    {
        Document document=new Document();
        File path = Environment.getExternalStoragePublicDirectory ( Environment.DIRECTORY_DOCUMENTS );
        File pdffile = new File(path, "FooBar.pdf");
        PdfWriter.getInstance(document, new FileOutputStream(pdffile));
        document.open();
        document.add(new Paragraph("Foo Bar Bar Baz Baz Foo"));
        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(""));
        }
    }
}

xml

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

'

    
asked by anonymous 06.04.2018 / 02:06

0 answers