Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(float leading, String string) 

Source Link

Document

Constructs a Paragraph with a certain String and a certain leading.

Usage

From source file:br.com.tcc.view.BairroView.java

/**
 * Evento responsvel por fechar o sistema
 * @param evt // w w  w .j  a v  a  2s . c o m
 */
private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFecharActionPerformed
    Document documento = new Document();
    try {
        OutputStream outputStream = new FileOutputStream(
                "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Registro Bairros.pdf");
        PdfWriter.getInstance(documento, outputStream);
        documento.open();
        Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 36, Font.BOLD);
        Paragraph paragrafo = new Paragraph("Relatrio da Bairro", fonte);
        paragrafo.setAlignment(Element.ALIGN_CENTER);
        documento.add(paragrafo);
        Paragraph paragrafoLista = new Paragraph(bairroList.toString());
        documento.add(paragrafoLista);
        documento.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(MovimentoVendaView.class.getName()).log(Level.SEVERE, null, ex);
    }
    dispose();
}

From source file:br.edu.unipampa.recipemanager.pdf.CreatePDF.java

public boolean newPdf(List<MenuRecipe> menuRecipe, String month, String responsibleName) {
    double valueMonth = 0;
    try {//from ww  w. j a v a  2 s .  c  o m
        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);
        OutputStream os = new FileOutputStream(namePdf(menuRecipe));
        PdfWriter.getInstance(doc, os);

        doc.open();
        Paragraph p;
        Font f = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);

        p = new Paragraph("Ms: " + month, f);
        doc.add(p);

        f = new Font(Font.FontFamily.COURIER, 14, Font.ITALIC);

        for (MenuRecipe menu : menuRecipe) {
            valueMonth += menu.priceMenu();
            p.setSpacingBefore(5);
            p.setSpacingAfter(5);
            p = new Paragraph(menu.toString(), f);
            doc.add(p);
        }

        p = new Paragraph("Preo total de todos os cardpios: " + valueMonth, f);
        doc.add(p);

        f = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
        p = new Paragraph("_____________________________________\n" + responsibleName, f);
        p.setSpacingAfter(15);
        p.setAlignment(Element.ALIGN_RIGHT);
        doc.add(p);

        doc.close();
        os.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:br.unisc.video_locadora.controll.Generator_PDF.java

public void geraRelatorio() throws DocumentException, FileNotFoundException {
    // Cria um novo documento com tamanho e margens definidas pelo usurio
    // new Document(tamanho da pgina, margem esquerda, margem direita,
    // margem topo, margem rodap);
    Document doc = new Document(PageSize.A4, 10, 10, 10, 10);
    try {// w ww  .j a v a2  s. c  om

        JFileChooser jFileChooser = new JFileChooser();

        //seta para selecionar apenas arquivos
        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        //desabilita todos os tipos de arquivos
        jFileChooser.setAcceptAllFileFilterUsed(false);

        //filtra por extensao
        jFileChooser.setFileFilter(new FileFilter() {
            @Override
            public String getDescription() {
                return "Extenso PDF";
            }

            @Override
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith("pdf");
            }
        });

        //mostra janela para salvar
        int acao = jFileChooser.showSaveDialog(null);

        //executa acao conforme opcao selecionada
        if (acao == JFileChooser.APPROVE_OPTION) {
            //escolheu arquivo
            System.out.println(jFileChooser.getSelectedFile().getAbsolutePath());
            PdfWriter.getInstance(doc,
                    new FileOutputStream(jFileChooser.getSelectedFile().getAbsolutePath() + ".pdf"));
            doc.open();

            listaF = f.buscaFilme("");

            // Definindo uma fonte, com tamanho 20 e negrito
            Font f = new Font(Font.FontFamily.COURIER, 30, Font.BOLD);
            Font f2 = new Font(Font.FontFamily.HELVETICA, 20, Font.BOLD);

            // adicionando um pargrafo ao documento com a fonte acima
            Paragraph pa = new Paragraph("Relatrio", f);
            // Setando o alinhamento p/ o centro
            pa.setAlignment(Paragraph.ALIGN_CENTER);

            // Definindo
            pa.setSpacingAfter(50);
            doc.add(pa);

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

            // Criando uma tabela com 4 colunas
            PdfPTable table = new PdfPTable(7);
            // Ttulo para a tabela
            Paragraph tableHeader = new Paragraph("Todos os Ttulos", f2);

            PdfPCell header = new PdfPCell(tableHeader);
            // Definindo que o header vai ocupar as 4 colunas
            header.setColspan(7);
            // Definindo alinhamento do header
            header.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
            // Adicionando o header  tabela
            table.addCell(header);

            List<String> list = new ArrayList<>();
            list.add("Id");
            list.add("Ttulo");
            list.add("Ano");
            list.add("Diretor");
            list.add("Gnero");
            list.add("Linguagem");
            list.add("Locado");
            for (Filmes p : listaF) {
                list.add(String.valueOf(p.getId()));
                list.add(p.getTitulo());
                list.add(String.valueOf(p.getAno()));
                list.add(p.getDiretor());
                list.add(p.getGenero());
                list.add(p.getIdioma());
                list.add(p.getLocado());
            }

            for (String s : list) {
                table.addCell(s);
            }

            doc.add(table);

            /* doc.add(new Paragraph(" ID | Nome | Idade | Cidade"));
            for (Pessoa p : lista) {
                doc.add(new Paragraph(p.getId() + " |  " + p.getNome() + "  |  " + p.getIdade() + "  |  " + p.getCidade()));
            }*/
        }
    } catch (FileNotFoundException | DocumentException e) {
        System.err.println(e.getMessage());
    }
    doc.close();
}

From source file:BUS.ExportPDF.java

public boolean ExportPN(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/* w  w  w.  j av  a2  s  .  c  o m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuNhap_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data

        PdfPTable t = new PdfPTable(7);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu nhp", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Nh cung cp", f));
        t.addCell(c6);
        PdfPCell c7 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c7);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(new Phrase(al.get(i)[4], f));
            t.addCell(al.get(i)[5]);
        }
        document.add(t);
        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportPX(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from   ww  w.jav  a2s. c o m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "PhieuXuat_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M phiu xut", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("M Nhn Vin", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportHD(ArrayList<String[]> al) throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from   w  ww . j a v  a  2 s .  c o  m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "Hoadon_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Data
        PdfPTable t = new PdfPTable(6);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M ha n", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn khch hng", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tn Nhn Vin", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Ngy lp", f));
        t.addCell(c5);
        PdfPCell c6 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c6);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(new Phrase(al.get(i)[2], f));
            t.addCell(al.get(i)[3]);
            t.addCell(al.get(i)[4]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKDT(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {//from   w  w  w  .j av a2  s  .c o m
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nam can bao cao
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\barChart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(4);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("Thng", f));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Li", f));
        t.addCell(c4);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(al.get(i)[2]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKSP(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from www .j  a  va 2  s . c  om*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeSanPham_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nm c bo co
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\pie_Chart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(5);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("STT"));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("M sn phm", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Tn sn phm", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Tng s lng", f));
        t.addCell(c4);
        PdfPCell c5 = new PdfPCell(new Phrase("Tng ti?n", f));
        t.addCell(c5);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(new Phrase(al.get(i)[1], f));
            t.addCell(al.get(i)[2]);
            t.addCell(al.get(i)[3]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}

From source file:BusinessLogic.Controller.HandleCertificate.java

public void downloadCertificate(ContractDAO contrDAO, CertificateDAO certificateDAO, UserDAO usDAO,
        HttpServletResponse response, int idUser, int option) throws DocumentException, IOException {
    User user = usDAO.searchByPkID(idUser);
    List<Certificate> certificateObject = certificateDAO.searchUserAproved();
    List<Certificate> certificateReturn = new ArrayList<Certificate>();
    if (certificateObject != null) {
        certificateReturn.clear();/*  w  w  w  .  j  av  a2s .c o  m*/
        for (int i = 0; i < certificateObject.size(); i++) {
            if (certificateObject.get(i).getFkuserID().getPkID().equals(user.getPkID())) {
                certificateReturn.add(certificateObject.get(i));
            }
        }
    }
    Contract contractObject = contrDAO.getUserContract(new User(user.getPkID()));
    Certificate cert = certificateReturn.get(option);
    Document document = new Document();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    document.open();
    Font fuente = new Font();
    fuente.setStyle(Font.BOLD);
    fuente.setColor(BaseColor.BLACK);
    fuente.setFamily(Font.FontFamily.TIMES_ROMAN.toString());
    fuente.setSize(15);
    Paragraph header = new Paragraph("\n\n\n\n\nEL DEPARTAMENTO DE GESTION HUMANA\n"
            + "DE TALENTO-HUMANO LTDA\n\n\n\n\n" + "CERTIFICA QUE:\n\n\n\n\n", fuente);
    header.setAlignment(Element.ALIGN_CENTER);
    Calendar fecha = new GregorianCalendar();
    int annio = fecha.get(Calendar.YEAR);
    int mes = fecha.get(Calendar.MONTH) + 1;
    int dia = fecha.get(Calendar.DAY_OF_MONTH);
    Paragraph endtext = new Paragraph("\n\nSe expide la presente certificacion a solicitud"
            + " del interesado a la fecha de : " + dia + "/" + mes + "/" + annio
            + "\n\n\nCordialmente\n\n\nEdwin Alexander Bohorquez\nGERENTE GENERAL DE TALENTO-HUMANO LTDA");
    endtext.setAlignment(Element.ALIGN_LEFT);
    String typeCertificate = "";
    if (cert.getType().toLowerCase().equals("laboral")) {
        typeCertificate = "Laboral";
        document.add(header);
        List<String> positionlist = new ArrayList<String>();
        for (Position cargo : contractObject.getPositionSet()) {
            positionlist.add(cargo.getName());
        }
        Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase()
                + " con cedula de ciudadania No." + user.getIdentifyCard() + ", trabaja en esta empresa"
                + " desde " + contractObject.getStartDate() + ", desempeandose actualmente como "
                + positionlist + " con una asignacion mensual de $" + contractObject.getSalary()
                + ".Su contrato de trabajo es a termino " + contractObject.getType() + ".");
        body.setAlignment(Element.ALIGN_JUSTIFIED_ALL);
        document.add(body);
        document.add(endtext);
    } else if (cert.getType().toLowerCase().equals("nmina")) {
        typeCertificate = "Nomina";
        Paragraph Payroll_header = new Paragraph("DEPARTAMENTO DE CONTABILIDAD\n" + "TALENTO-HUMANO LTDA\n\n"
                + "LIQUIDACION DE NOMINA:\n" + "Nombre del empleado : " + user.getName() + " "
                + user.getLastname() + "\n" + "Cedula : " + user.getIdentifyCard() + "\n\n", fuente);
        Payroll_header.setAlignment(Element.ALIGN_CENTER);
        document.add(Payroll_header);
        double commissions = 10000;
        double extra_hours = 50000;
        double transportation_aid = 63600;
        double totalAccrued = contractObject.getSalary() + commissions + extra_hours + transportation_aid;

        PdfPTable basetable = new PdfPTable(2);
        PdfPCell headertable = new PdfPCell(new Paragraph("Tabla Base", fuente));
        headertable.setColspan(2);
        basetable.addCell(headertable);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Salario Basico : "));
        PdfPCell cell2 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary())));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Comisiones : "));
        PdfPCell cell4 = new PdfPCell(new Paragraph(String.valueOf(commissions)));
        PdfPCell cell5 = new PdfPCell(new Paragraph("Horas Extras : "));
        PdfPCell cell6 = new PdfPCell(new Paragraph(String.valueOf(extra_hours)));
        PdfPCell cell7 = new PdfPCell(new Paragraph("Auxilio de transporte : "));
        PdfPCell cell8 = new PdfPCell(new Paragraph(String.valueOf(transportation_aid)));
        PdfPCell ce9 = new PdfPCell(new Paragraph("Total Devengado : "));
        PdfPCell ce10 = new PdfPCell(new Paragraph(" $ " + String.valueOf(totalAccrued)));
        basetable.setWidthPercentage(100F);
        basetable.setHorizontalAlignment(Element.ALIGN_CENTER);
        basetable.addCell(cell1);
        basetable.addCell(cell2);
        basetable.addCell(cell3);
        basetable.addCell(cell4);
        basetable.addCell(cell5);
        basetable.addCell(cell6);
        basetable.addCell(cell7);
        basetable.addCell(cell8);
        basetable.addCell(ce9);
        basetable.addCell(ce10);
        document.add(basetable);

        PdfPTable tableliquidation = new PdfPTable(2);
        PdfPCell title = new PdfPCell(
                new Paragraph("Liquidacion. Deducciones de nomina(Conceptos a cargo del empleado) ", fuente));
        title.setColspan(2);
        tableliquidation.addCell(title);
        PdfPCell cell9 = new PdfPCell(new Paragraph("Salud (4%) : "));
        PdfPCell cell10 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04)));
        PdfPCell cell11 = new PdfPCell(new Paragraph("Pension (4%) : "));
        PdfPCell cell12 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.04)));

        tableliquidation.setWidthPercentage(100F);
        tableliquidation.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableliquidation.addCell(cell9);
        tableliquidation.addCell(cell10);
        tableliquidation.addCell(cell11);
        tableliquidation.addCell(cell12);
        document.add(tableliquidation);

        PdfPTable tablesocialSecurity = new PdfPTable(2);
        PdfPCell title2 = new PdfPCell(new Paragraph("Seguridad Social a cargo del empleador", fuente));
        title2.setColspan(2);
        tablesocialSecurity.addCell(title2);
        PdfPCell cell13 = new PdfPCell(new Paragraph("Salud (8.5%) : "));
        PdfPCell cell14 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.085)));
        PdfPCell cell15 = new PdfPCell(new Paragraph("Pension (12%) : "));
        PdfPCell cell16 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.12)));
        PdfPCell cell17 = new PdfPCell(new Paragraph("A.R.P : "));
        PdfPCell cell18 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.00522)));

        tablesocialSecurity.setWidthPercentage(100F);
        tablesocialSecurity.setHorizontalAlignment(Element.ALIGN_CENTER);
        tablesocialSecurity.addCell(cell13);
        tablesocialSecurity.addCell(cell14);
        tablesocialSecurity.addCell(cell15);
        tablesocialSecurity.addCell(cell16);
        tablesocialSecurity.addCell(cell17);
        tablesocialSecurity.addCell(cell18);
        document.add(tablesocialSecurity);

        PdfPTable social_benefits = new PdfPTable(2);
        PdfPCell title3 = new PdfPCell(new Paragraph("Prestaciones Sociales", fuente));
        title3.setColspan(2);
        social_benefits.addCell(title3);
        PdfPCell cell19 = new PdfPCell(new Paragraph("Prima de servicios : "));
        PdfPCell cell20 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833)));
        PdfPCell cell21 = new PdfPCell(new Paragraph("Cesantias : "));
        PdfPCell cell22 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833)));
        PdfPCell cell23 = new PdfPCell(new Paragraph("Intereses sobre las cesantias : "));
        PdfPCell cell24 = new PdfPCell(new Paragraph(String.valueOf(totalAccrued * 0.0833 * 0.12)));
        PdfPCell cell25 = new PdfPCell(new Paragraph("Vacaciones : "));
        PdfPCell cell26 = new PdfPCell(new Paragraph(String.valueOf(contractObject.getSalary() * 0.0417)));
        social_benefits.setWidthPercentage(100F);
        social_benefits.setHorizontalAlignment(Element.ALIGN_CENTER);
        social_benefits.addCell(cell19);
        social_benefits.addCell(cell20);
        social_benefits.addCell(cell21);
        social_benefits.addCell(cell22);
        social_benefits.addCell(cell23);
        social_benefits.addCell(cell24);
        social_benefits.addCell(cell25);
        social_benefits.addCell(cell26);
        document.add(social_benefits);

        PdfPTable fiscal_contributions = new PdfPTable(2);
        PdfPCell title4 = new PdfPCell(new Paragraph("Aportes Parafiscales", fuente));
        title4.setColspan(2);
        fiscal_contributions.addCell(title4);
        PdfPCell cell27 = new PdfPCell(new Paragraph("Cajas de compensacion familiar (4%) : "));
        PdfPCell cell28 = new PdfPCell(
                new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.04)));
        PdfPCell cell29 = new PdfPCell(new Paragraph("I.CB.F (3%) : "));
        PdfPCell cell30 = new PdfPCell(
                new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.03)));
        PdfPCell cell31 = new PdfPCell(new Paragraph("Sena (2%) : "));
        PdfPCell cell32 = new PdfPCell(
                new Paragraph(String.valueOf((contractObject.getSalary() + extra_hours + commissions) * 0.02)));
        fiscal_contributions.setWidthPercentage(100F);
        fiscal_contributions.setHorizontalAlignment(Element.ALIGN_CENTER);
        fiscal_contributions.addCell(cell27);
        fiscal_contributions.addCell(cell28);
        fiscal_contributions.addCell(cell29);
        fiscal_contributions.addCell(cell30);
        fiscal_contributions.addCell(cell31);
        fiscal_contributions.addCell(cell32);
        document.add(fiscal_contributions);

        PdfPTable totalValue = new PdfPTable(2);
        PdfPCell title5 = new PdfPCell(new Paragraph("Neto a pagar al empleado", fuente));
        title5.setColspan(2);
        totalValue.addCell(title5);
        PdfPCell cell33 = new PdfPCell(new Paragraph(" Total devengado - salud - pension"));
        cell33.setColspan(2);
        PdfPCell cell34 = new PdfPCell(new Paragraph(
                " $ " + String.valueOf(totalAccrued - contractObject.getSalary() * 0.08), fuente));
        cell34.setColspan(2);
        totalValue.setWidthPercentage(100F);
        totalValue.setHorizontalAlignment(Element.ALIGN_CENTER);
        totalValue.addCell(cell33);
        totalValue.addCell(cell34);
        document.add(totalValue);

        document.add(endtext);
    } else if (cert.getType().toLowerCase().equals("salud")) {
        typeCertificate = "Salud";
        document.add(header);
        Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase()
                + " con cedula de ciudadania No." + user.getIdentifyCard() + ", esta afiliado desde "
                + contractObject.getStartHealthDate() + " a la empresa de salud "
                + contractObject.getHealthEnterprise() + ".");
        body.setAlignment(Element.ALIGN_JUSTIFIED_ALL);
        document.add(body);
        document.add(endtext);
    } else if (cert.getType().toLowerCase().equals("pensin")) {
        typeCertificate = "Pension";
        document.add(header);
        Paragraph body = new Paragraph(user.getName().toUpperCase() + " " + user.getLastname().toUpperCase()
                + " con cedula de ciudadania No." + user.getIdentifyCard()
                + ", esta afiliado a la empresa de pension " + contractObject.getPensionEnterprise()
                + ".La fecha de inicio de pension es " + contractObject.getStartPensionDate() + ".");
        body.setAlignment(Element.ALIGN_JUSTIFIED_ALL);
        document.add(body);
        document.add(endtext);
    }
    document.close();
    response.setHeader("Expires", "0");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
    response.setHeader("Pragma", "public");
    response.setContentType("application/octet-strem");
    File f = new File("Certificado" + typeCertificate + ".pdf");
    response.setHeader("Content-Disposition", "attachment;filename=" + f.getName());
    response.setContentLength(baos.size());
    System.out.println("Hasta aca crea el pdf bien");
    OutputStream os = response.getOutputStream();
    System.out.println("Ac'a ya deberia haber descargado");
    baos.writeTo(os);
    os.flush();
    os.close();
}

From source file:bussiness.ReportHandler.java

private void BuildHeaderPrescription(Document veterinaryPrescription, String clientName, String petName)
        throws DocumentException, IOException {
    BaseFont baseFont = BaseFont.createFont("Cookie.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
    Font font = new Font(baseFont);
    font.setStyle(Font.BOLDITALIC);
    font.setSize(35);//from   w  w w .j  av  a2 s  .  c o m
    Doctor doctor = SessionManager.getLoggedDoctor();
    Paragraph p1 = new Paragraph("Dr. " + doctor.getName(), font);
    p1.setAlignment(Element.ALIGN_CENTER);
    veterinaryPrescription.add(p1);
    // veterinaryPrescription.add(new Chunk("\n"));

    Font font2 = new Font();
    font2.setSize(20);

    Paragraph p2 = new Paragraph("CEDULA PROFESIONAL  " + doctor.getIdentityCard(), font2);

    p2.setAlignment(Element.ALIGN_CENTER);

    veterinaryPrescription.add(p2);
    veterinaryPrescription.add(new Chunk("\n"));
    Paragraph p3 = new Paragraph("Nombre del cliente: " + clientName, font2);
    veterinaryPrescription.add(p3);
    Paragraph p4 = new Paragraph("Nombre de la mascota: " + petName, font2);
    veterinaryPrescription.add(p4);
}