Example usage for com.itextpdf.text Document Document

List of usage examples for com.itextpdf.text Document Document

Introduction

In this page you can find the example usage for com.itextpdf.text Document Document.

Prototype


public Document() 

Source Link

Document

Constructs a new Document -object.

Usage

From source file:bencoding.pdf.ConvertersProxy.java

License:Open Source License

@Kroll.method
public TiBlob convertImageToPDF(TiBlob blob, @Kroll.argument(optional = true) Object resolution)
        throws Exception {
    TiBlob result = null;// w  w  w .  ja  va  2  s . c om
    Bitmap bitmap = null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    TiDrawableReference ref = TiDrawableReference.fromBlob(getActivity(), blob);
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, outputStream);
        document.open();
        bitmap = ref.getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bitmapdata = stream.toByteArray();
        Image image1 = Image.getInstance(bitmapdata);
        document.add(image1);
        document.close();
        byte[] bytes = outputStream.toByteArray();
        result = TiBlob.blobFromData(bytes);
        return result;

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        Log.i(PdfModule.MODULE_FULL_NAME, e.toString());
    } catch (DocumentException e) {
        Log.i(PdfModule.MODULE_FULL_NAME, e.toString());
        e.printStackTrace();
    } finally {
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        outputStream = null;
        ref = null;
        document = null;
    }

    return result;
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

/**
 * createPdf es una funcin estatica que funciona como plantilla para generar
 * reportes dinamicos, segn la necesidad del usuario.
 * @param path La direccin del archivo donde se guardar el pdf
 * @param titulo El Ttulo que llevar el pdf
 * @param encabezado Un texto que se mostrar bajo el ttulo
 * @param tabla La tabla de resultados que mostrar el pdf
 */// w ww  . j a v a  2 s  .  c om
static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) {
    Document document = new Document();
    // step 2
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(14);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle);
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1)));
        document.add(new Paragraph("\r\n"));
        document.add(tabla);
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

static public void createArrayListPdf(String path, String titulo, String encabezado,
        ArrayList<PdfPTable> tablas) {
    Document document = new Document();
    ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas();
    //step 2/* ww  w  .  ja va2  s .c o  m*/
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(12);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle);
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        for (int i = 0; i < tablas.size(); i++) {
            document.add(new Paragraph(NombreTablas.get(i)));
            document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1)));
            document.add(new Paragraph("\r\n"));
            document.add(tablas.get(i));
        }
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

static public void createDinamicPdf(String path, String titulo, String encabezado,
        ArrayList<Element> contenido) {
    Document document = new Document();
    //step 2/*from  w  w  w.  j  av  a2  s  . com*/
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(12);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle);
        //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados");
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        // document.add(Introduccion);
        document.add(new Paragraph("\r\n"));
        for (int i = 0; i < contenido.size(); i++) {
            document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass())
                    ? (PdfPTable) contenido.get(i)
                    : contenido.get(i));
        }
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:bicimotos3hermanos.MainFrom.java

public void toPFD(String out, String in) {
    try {/*from w  w  w . ja va2s.  c  om*/
        //Create Document Object
        Document convertJpgToPdf = new Document();
        //Create PdfWriter for Document to hold physical file
        PdfWriter.getInstance(convertJpgToPdf, new FileOutputStream(out));//"c:\\java\\ConvertImagetoPDF.pdf"
        convertJpgToPdf.open();
        //Get the input image to Convert to PDF
        Image convertJpg = Image.getInstance(in);
        convertJpg.setAbsolutePosition(0f, 260f);//posicion en x,y

        convertJpg.scalePercent(72, 85);//porcentaje en escala 
        //Add image to Document
        convertJpgToPdf.add(convertJpg);
        //Close Document
        convertJpgToPdf.close();
        System.out.println("Successfully Converted JPG to PDF in iText");
    } catch (Exception i1) {
        i1.printStackTrace();
    }
}

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;/*from w  w w  .  jav  a  2  s .c  o  m*/
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}

From source file:bl.pdf.PDFFile.java

public PDFFile(File file) throws DocumentException, IOException {
    document = new Document();
    if (!file.exists()) {
        file = new File(file.getPath() + ".pdf");
        file.createNewFile();//  ww w  .j a  va 2 s .c  o m
    }
    PdfWriter.getInstance(document, new FileOutputStream(file));
}

From source file:bodyfitness.relatorios.Relatorio.java

public void GeraRelatorioAdimplente(String caminho) {
    Document documento = new Document();
    try {/*from w w w .  j  a v  a 2 s  .c o m*/
        PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf"));
        documento.open();
        ClienteDAO dao = new ClienteDAO();
        List<Cliente> clientes = dao.consultarAdimplentes();
        PdfPTable tabela = new PdfPTable(2);
        tabela.addCell("ID");
        tabela.addCell("Nome");
        Paragraph p = new Paragraph("     Relatrio - Clientes Adimplentes\n\n\n");
        documento.add(p);
        for (Cliente c : clientes) {
            tabela.addCell(c.getId().toString());
            tabela.addCell(c.getNome());
        }
        documento.add(tabela);
        documento.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:bodyfitness.relatorios.Relatorio.java

public void GeraRelatorioInadimplente(String caminho) {
    Document documento = new Document();
    try {/* www . j  a v  a 2 s  .  c  om*/
        PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/Adimplentes.pdf"));
        documento.open();
        ClienteDAO dao = new ClienteDAO();
        List<Cliente> clientes = dao.consultarInadimplentes();
        PdfPTable tabela = new PdfPTable(2);
        tabela.addCell("ID");
        tabela.addCell("Nome");
        Paragraph p = new Paragraph("     Relatrio - Clientes Inadimplentes\n\n\n");
        documento.add(p);
        for (Cliente c : clientes) {
            tabela.addCell(c.getId().toString());
            tabela.addCell(c.getNome());
        }
        documento.add(tabela);
        documento.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:bodyfitness.relatorios.Relatorio.java

public void GeraRelatorioMaquinaSManutencao(String caminho) {
    Document documento = new Document();
    try {// w w w.  j a  v a2s. c  om
        PdfWriter.getInstance(documento, new FileOutputStream(caminho + "/MaquinaSManutencao.pdf"));
        documento.open();
        EquipamentoDAO dao = new EquipamentoDAO();
        List<Equipamento> equips = dao.consultarSemManutancao();
        PdfPTable tabela = new PdfPTable(3);
        tabela.addCell("ID");
        tabela.addCell("Nome");
        tabela.addCell("D. Ultima Mantencao");
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
        Paragraph p = new Paragraph("     Relatrio - Clientes Mquinas Sem Manuteno\n\n\n");
        documento.add(p);
        for (Equipamento e : equips) {
            tabela.addCell(e.getId().toString());
            tabela.addCell(e.getNome());
            tabela.addCell(formato.format(e.getDataDaUltimaManutencao()));
        }
        documento.add(tabela);
        documento.close();

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao gerar documento:\n" + e.getMessage(), "Erro",
                JOptionPane.ERROR_MESSAGE);
    }
}