Example usage for com.lowagie.text.pdf PdfWriter getInstance

List of usage examples for com.lowagie.text.pdf PdfWriter getInstance

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter getInstance.

Prototype


public static PdfWriter getInstance(Document document, OutputStream os) throws DocumentException 

Source Link

Document

Use this method to get an instance of the PdfWriter.

Usage

From source file:mesquite.lib.MesquitePDFFile.java

License:Open Source License

/**
@arg component Component to display/*from w w  w .java  2  s .c o m*/
@arg dim
@return Graphics for pdf output
 */
public Graphics getPDFGraphicsForComponent(Component component, Dimension dim) {
    final String exceptionMessage = "Error, an exception occurred while creating the PDF document: ";
    float pageMatrix[] = zeroPageMatrix();
    int pageOrientation = PageFormat.LANDSCAPE;
    float imageableHeight;
    float imageableWidth;
    float pageHeight; //dimensions of the virtual page, not the imageable area
    float pageWidth; // actually these are only different for Java2D pages
    Graphics g = null;

    if ((component == null)) {
        return null;
    }
    if (dim == null)
        dimension = component.getSize();
    else
        dimension = dim;

    if (fitToPage >= 0) {
        if (dimension == null || dimension.width <= 0 || dimension.height <= 0) {
            return null;
        }
        double shrinkWidth;
        double shrinkHeight;
        double shrinkRatioLANDSCAPE = 0.0;
        double shrinkRatioPORTRAIT = 0.0;
        double shrink;
        //Java2Davailable == true
        if ((job2 == null) || pf == null)
            return null;
        //pf = job2.defaultPage();

        pf.setOrientation(PageFormat.LANDSCAPE);
        shrinkWidth = pf.getImageableWidth() * 1.0 / dimension.width;
        shrinkHeight = pf.getImageableHeight() * 1.0 / dimension.height;
        if (shrinkWidth < shrinkHeight)
            shrinkRatioLANDSCAPE = shrinkWidth;
        else
            shrinkRatioLANDSCAPE = shrinkHeight;
        pf.setOrientation(PageFormat.PORTRAIT);
        shrinkWidth = pf.getImageableWidth() * 1.0 / dimension.width;
        shrinkHeight = pf.getImageableHeight() * 1.0 / dimension.height;
        if (shrinkWidth < shrinkHeight)
            shrinkRatioPORTRAIT = shrinkWidth;
        else
            shrinkRatioPORTRAIT = shrinkHeight;
        if (shrinkRatioPORTRAIT < shrinkRatioLANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
            shrink = shrinkRatioLANDSCAPE;
        } else {
            pf.setOrientation(PageFormat.PORTRAIT);
            shrink = shrinkRatioPORTRAIT;
        }
        pageOrientation = pf.getOrientation();

        imageableWidth = (float) pf.getImageableWidth();
        imageableHeight = (float) pf.getImageableHeight();
        pageWidth = (float) pf.getWidth();
        pageHeight = (float) pf.getHeight();
        //pageMatrix = zeroPageMatrix();
        pageMatrix[0] = (float) shrink;
        pageMatrix[3] = (float) shrink;

    } else { // not fit to page
        // Java2Davailable == true
        if (job2 == null)
            return null;
        imageableWidth = (float) pf.getImageableWidth();
        imageableHeight = (float) pf.getImageableHeight();
        pageHeight = (float) pf.getHeight();
        pageWidth = (float) pf.getWidth();
        //pageMatrix = pf.getMatrix();
        //pageMatrix = zeroPageMatrix();
        pageOrientation = pf.getOrientation();
        pageMatrix[0] = pageMatrix[3] = 1f;

    }
    pageRectangle = new com.lowagie.text.Rectangle(0.0f, imageableHeight, imageableWidth, 0.0f);
    try {
        document = new Document(pageRectangle);
        writer = PdfWriter.getInstance(document, new FileOutputStream(pdfPathString));
        addMetaData(document);
        document.open();
        cb = writer.getDirectContent();
        tp = cb.createTemplate((int) pageWidth, (int) pageHeight); //dump this??

        cb.concatCTM(pageMatrix[0], pageMatrix[1], pageMatrix[2], pageMatrix[3], pageMatrix[4], pageMatrix[5]);
        g = cb.createGraphics((float) dimension.getWidth(), (float) dimension.getHeight()); //HEADLESS :  comment this line out for headless mode

    } catch (java.io.IOException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    } catch (com.lowagie.text.BadElementException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    } catch (com.lowagie.text.DocumentException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    }
    return g;
}

From source file:mesquite.lib.MesquitePDFFile.java

License:Open Source License

/**
@arg component Component to display//  w  ww. j  a  va 2s.co m
@arg dim
@arg font
 */
public void printComponent(Component component, Dimension dim, java.awt.Font font) {
    final String exceptionMessage = "Error, an exception occurred while creating the PDF document: ";
    float pageMatrix[] = zeroPageMatrix();
    int pageOrientation = PageFormat.LANDSCAPE;
    float imageableHeight;
    float imageableWidth;
    float pageHeight; //dimensions of the virtual page, not the imageable area
    float pageWidth; // actually these are only different for Java2D pages

    if ((component == null)) {
        return;
    }
    if (dim == null)
        dimension = component.getSize();
    else
        dimension = dim;

    if (fitToPage >= 0) {
        if (dimension == null || dimension.width <= 0 || dimension.height <= 0) {
            return;
        }
        double shrinkWidth;
        double shrinkHeight;
        double shrinkRatioLANDSCAPE = 0.0;
        double shrinkRatioPORTRAIT = 0.0;
        double shrink;
        //Java2Davailable == true
        if ((job2 == null) || pf == null)
            return;
        //pf = job2.defaultPage();

        pf.setOrientation(PageFormat.LANDSCAPE);
        shrinkWidth = pf.getImageableWidth() * 1.0 / dimension.width;
        shrinkHeight = pf.getImageableHeight() * 1.0 / dimension.height;
        if (shrinkWidth < shrinkHeight)
            shrinkRatioLANDSCAPE = shrinkWidth;
        else
            shrinkRatioLANDSCAPE = shrinkHeight;
        pf.setOrientation(PageFormat.PORTRAIT);
        shrinkWidth = pf.getImageableWidth() * 1.0 / dimension.width;
        shrinkHeight = pf.getImageableHeight() * 1.0 / dimension.height;
        if (shrinkWidth < shrinkHeight)
            shrinkRatioPORTRAIT = shrinkWidth;
        else
            shrinkRatioPORTRAIT = shrinkHeight;
        if (shrinkRatioPORTRAIT < shrinkRatioLANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
            shrink = shrinkRatioLANDSCAPE;
        } else {
            pf.setOrientation(PageFormat.PORTRAIT);
            shrink = shrinkRatioPORTRAIT;
        }
        pageOrientation = pf.getOrientation();

        imageableWidth = (float) pf.getImageableWidth();
        imageableHeight = (float) pf.getImageableHeight();
        pageWidth = (float) pf.getWidth();
        pageHeight = (float) pf.getHeight();
        //pageMatrix = zeroPageMatrix();
        pageMatrix[0] = (float) shrink;
        pageMatrix[3] = (float) shrink;
    }

    else { // not fit to page
             // Java2Davailable == true
        if (job2 == null)
            return;
        imageableWidth = (float) pf.getImageableWidth();
        imageableHeight = (float) pf.getImageableHeight();
        pageHeight = (float) pf.getHeight();
        pageWidth = (float) pf.getWidth();
        //pageMatrix = zeroPageMatrix();
        pageOrientation = pf.getOrientation();
        pageMatrix[0] = pageMatrix[3] = 1f;

    }
    pageRectangle = new com.lowagie.text.Rectangle(0.0f, imageableHeight, imageableWidth, 0.0f);
    try {
        document = new Document(pageRectangle);
        writer = PdfWriter.getInstance(document, new FileOutputStream(pdfPathString));
        addMetaData(document);
        document.open();
        cb = writer.getDirectContent();
        tp = cb.createTemplate((int) pageWidth, (int) pageHeight); //dump this??

        java.awt.Image jImage = component.createImage((int) dimension.getWidth(), (int) dimension.getHeight());

        Graphics j2 = jImage.getGraphics();
        component.printAll(j2);
        //com.lowagie.text.Image outImage = null; //HEADLESS  Use this line for headless mode
        com.lowagie.text.Image outImage = com.lowagie.text.Image.getInstance(jImage, null); //HEADLESS  Comment this line out for headless mode
        float verticalIncrement = imageableHeight / pageMatrix[0];
        float horizontalIncrement = imageableWidth / pageMatrix[3];
        float heightLimit = (imageableHeight / pageMatrix[0]);
        float widthLimit = -1 * outImage.width();
        float verticalStart = (imageableHeight / pageMatrix[0]) - outImage.height();
        for (float vertical = verticalStart; vertical < heightLimit; vertical += verticalIncrement) {
            for (float horizontal = 0; horizontal > widthLimit; horizontal -= horizontalIncrement) {
                document.newPage();
                cb.concatCTM(pageMatrix[0], pageMatrix[1], pageMatrix[2], pageMatrix[3], pageMatrix[4],
                        pageMatrix[5]);
                switch (pageOrientation) {
                case PageFormat.LANDSCAPE: {
                    cb.addImage(outImage, outImage.width(), 0f, 0f, outImage.height(), horizontal, vertical);
                    break;
                }
                case PageFormat.PORTRAIT:
                default: {
                    cb.addImage(outImage, outImage.width(), 0.0f, 0.0f, outImage.height(), horizontal,
                            vertical);
                    break;
                }
                }
            }
        }
    } catch (java.io.IOException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    } catch (com.lowagie.text.BadElementException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    } catch (com.lowagie.text.DocumentException e) {
        MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + e);
    }
    end();
}

From source file:mitm.common.pdf.MessagePDFBuilder.java

License:Open Source License

private PdfWriter createPdfWriter(Document document, OutputStream pdfStream) throws DocumentException {
    PdfWriter pdfWriter = PdfWriter.getInstance(document, pdfStream);

    if (fullCompression) {
        pdfWriter.setFullCompression();/*  www.  j  av  a 2  s  . c  o m*/
    }

    pdfWriter.setViewerPreferences(getViewerPreferencesIntValue());

    return pdfWriter;
}

From source file:model.relatorio.java

public void getRelatorioTodosAlunos() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Alunos.pdf"));
    doc.open();/* ww w .  jav a 2  s.  com*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                            RELATORIO ALUNOS"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aluno");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_aluno") + "   Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "  Idade : " + rs.getInt("idade")
                    + "  Altura : " + rs.getString("altura") + "  Peso : " + rs.getString("peso")));
            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Alunos.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioTodosProfessores() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Professores.pdf"));
    doc.open();//from  w  w w. j  ava  2  s  . c o  m
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO PROFESSORES"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from professor");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_prof") + "   Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "     Salario : "
                    + rs.getDouble("salario")));

            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Professores.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioTodasAulas() throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Aulas.pdf"));
    doc.open();//ww w.j  a  v  a2  s . c  o  m
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO AULAS"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;
    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aula");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_aula") + "   Nome : " + rs.getString("nome")
                    + "\nPreo : " + rs.getDouble("preco") + "   Horario : " + rs.getString("horario")));

            doc.add(new Paragraph(" "));
            doc.add(new Paragraph(
                    "_____________________________________________________________________________"));
            doc.add(new Paragraph(" "));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Aulas.pdf"));

}

From source file:model.relatorio.java

public void getRelatorioAula(String idParaProcurar)
        throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Aula ID " + idParaProcurar + ".pdf"));
    doc.open();/*  w  w w .j av a 2 s.  c o  m*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO AULA"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aula where id_aula = " + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {

            doc.add(new Paragraph("ID: " + rs.getInt("id_aula") + "  Nome : " + rs.getString("nome")
                    + "  Preo : " + rs.getDouble("preco") + "   Horario : " + rs.getString("horario")));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" ALUNOS MATRICULADOS:"));

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select aluno.id_aluno, aluno.nome from aluno\n" + "inner join matricula\n"
                + "on aluno.id_aluno = matricula.id_aluno\n" + "inner join aula\n"
                + "on aula.id_aula = matricula.id_aula\n" + " where aula.id_aula =" + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {

            doc.add(new Paragraph("\nID: " + rs.getInt("id_aluno") + "   | Nome : " + rs.getString("nome")));

        }

        doc.close();
        JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
        Desktop.getDesktop().open(new File("Relatorio Aula ID " + idParaProcurar + ".pdf"));

    } catch (SQLException ex) {
        Logger.getLogger(relatorio.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:model.relatorio.java

public void getRelatorioAluno(String idParaProcurar)
        throws DocumentException, FileNotFoundException, IOException {

    double totalAulas = 0;
    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Aluno ID " + idParaProcurar + ".pdf"));
    doc.open();/*from  ww w  .  java 2 s.  c om*/
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO ALUNO"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from aluno where id_aluno = " + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_aluno") + "   Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "   Idade : " + rs.getInt("idade")
                    + "   Altura : " + rs.getString("altura") + "   Peso : " + rs.getString("peso")));
        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }

    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" AULAS MATRICULADAS"));

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select matricula.id_matricula, aula.nome from aluno\n"
                + "inner join matricula\n" + "on aluno.id_aluno = matricula.id_aluno\n" + "inner join aula\n"
                + "on aula.id_aula = matricula.id_aula\n" + "where aluno.id_aluno =" + idParaProcurar);
        ResultSet rt = stmt.executeQuery();
        while (rt.next()) {
            doc.add(new Paragraph(
                    "ID: " + rt.getInt("id_matricula") + "  | Nome : " + rt.getString("nome") + "\n"));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select sum(aula.preco) Valor from aluno\n" + "inner join matricula\n"
                + "on aluno.id_aluno = matricula.id_aluno\n" + "inner join aula\n"
                + "on aula.id_aula = matricula.id_aula\n" + "where aluno.id_aluno =" + idParaProcurar);
        ResultSet rt = stmt.executeQuery();
        while (rt.next()) {
            totalAulas += (rt.getDouble("valor"));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }

    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("MENSALIDADE: " + totalAulas));

    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Aluno ID " + idParaProcurar + ".pdf"));

}

From source file:model.relatorio.java

public void getRelatorioProfessor(String idParaProcurar)
        throws DocumentException, FileNotFoundException, IOException {

    Document doc = new Document();
    PdfWriter.getInstance(doc, new FileOutputStream("Relatorio Professor ID " + idParaProcurar + ".pdf"));
    doc.open();// w  ww.ja  v a  2  s .com
    Image imagem = Image.getInstance(caminhoImagemRelatorio);
    imagem.scaleToFit(550, 100);
    doc.add(imagem);
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph("                                                           RELATORIO PROFESSOR"));
    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" "));

    PreparedStatement stmt = null;
    Connection conn = null;

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select * from professor where id_prof = " + idParaProcurar);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            doc.add(new Paragraph("ID: " + rs.getInt("id_prof") + "  Nome : " + rs.getString("nome")
                    + "\nCpf : " + rs.getString("cpf") + "   Endereo : " + rs.getString("endereco")
                    + "\nTelefone : " + rs.getString("telefone") + "   Salario : " + rs.getDouble("salario")));
        }

    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);
    }

    doc.add(new Paragraph(" "));
    doc.add(new Paragraph(" AULAS: "));

    try {
        conn = ConexaoBanco.getAbreConexao();
        stmt = conn.prepareStatement("select aula.horario, aula.nome from professor\n" + "inner join aula\n"
                + "on aula.id_prof = professor.id_prof\n" + "where professor.id_prof = " + idParaProcurar);
        ResultSet rt = stmt.executeQuery();
        while (rt.next()) {
            doc.add(new Paragraph(
                    "Horario: " + rt.getString("horario") + "  | Nome : " + rt.getString("nome") + "\n"));

        }
    } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, " Erro   \n" + e);

    }
    doc.close();
    JOptionPane.showMessageDialog(null, " Arquivo Gerado com Sucesso! ");
    Desktop.getDesktop().open(new File("Relatorio Professor ID " + idParaProcurar + ".pdf"));

}

From source file:mpv5.utils.export.Export.java

License:Open Source License

private static File mergeFiles(List<File> p) {

    Document document = new Document();
    try {// ww  w. j  a v a2s.  c om
        List<InputStream> pdfs = new ArrayList<InputStream>();
        for (int i = 0; i < p.size(); i++) {
            File inputStream = p.get(i);
            pdfs.add(new FileInputStream(inputStream));
        }
        List<PdfReader> readers = new ArrayList<PdfReader>();
        int totalPages = 0;
        Iterator<InputStream> iteratorPDFs = pdfs.iterator();

        while (iteratorPDFs.hasNext()) {
            InputStream pdf = iteratorPDFs.next();
            PdfReader pdfReader = new PdfReader(pdf);
            readers.add(pdfReader);
            totalPages += pdfReader.getNumberOfPages();
        }

        File f = FileDirectoryHandler.getTempFile("pdf");
        FileOutputStream outputstream = new FileOutputStream(f);
        PdfWriter writer = PdfWriter.getInstance(document, outputstream);

        document.open();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage page;
        int currentPageNumber = 0;
        int pageOfCurrentReaderPDF = 0;
        Iterator<PdfReader> iteratorPDFReader = readers.iterator();

        // Loop through the PDF files and add to the output.
        while (iteratorPDFReader.hasNext()) {
            PdfReader pdfReader = iteratorPDFReader.next();

            // Create a new page in the target for each source page.
            while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
                document.newPage();
                pageOfCurrentReaderPDF++;
                currentPageNumber++;
                page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
                cb.addTemplate(page, 0, 0);

            }
            pageOfCurrentReaderPDF = 0;
        }
        outputstream.flush();
        document.close();
        outputstream.close();

        return f;
    } catch (Exception e) {
        Log.Debug(e);
    } finally {
        if (document.isOpen()) {
            document.close();
        }
    }

    return null;
}