Example usage for com.itextpdf.text Font Font

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

Introduction

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

Prototype


public Font(final FontFamily family, final float size, final int style) 

Source Link

Document

Constructs a Font.

Usage

From source file:gov.va.cem.eoas.business.FaxArchivesPDF.java

public InputStream generatePDF(FaxRecord data) {
    SimpleDateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy");

    Date curDate = new Date();
    String caseIdData = (data.getCaseId() != null) ? data.getCaseId() : "";
    String currentDate = new String(newFormat.format(curDate));
    String sepDocs = (data.getSepDocs()) ? "X" : "";
    String marLicense = (data.getMarLicense()) ? "X" : "";
    String adminDecision = (data.getAdminDecision()) ? "X" : "";
    String deathCert = (data.getDeathCert()) ? "X" : "";
    String divorceDecree = (data.getDivorceDecree()) ? "X" : "";
    String otherCheck = (data.getOtherCheck()) ? "X" : "";
    String transDate = (data.getTransDate() != null) ? new String(newFormat.format(data.getTransDate())) : "";
    String priorLoc = (data.getPriorLoc() != null) ? data.getPriorLoc() : "";
    String otherComments = (data.getOtherComments() != null) ? data.getOtherComments() : "";
    String remarks = (data.getRemarks() != null) ? data.getRemarks() : "";
    String to = data.getTo().getDisplayName();
    String fileNo = (data.getFileNo() != null) ? data.getFileNo() : "";
    String vetName = (data.getVetName() != null) ? data.getVetName() : "";
    String ssnData = (data.getSSN() != null) ? data.getSSN() : "";
    String snData = (data.getSN() != null) ? data.getSN() : "";
    String farcNo = (data.getFarcNo() != null) ? data.getFarcNo() : "";
    String boxNoData = (data.getBoxNo() != null) ? data.getBoxNo() : "";
    String faxPages = (data.getFaxPages() != null) ? data.getFaxPages() : "";

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*  ww  w  . j  a v  a  2  s . com*/
        PdfWriter.getInstance(document, outputStream);
        //Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 9);
        Font font2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        Font font3 = new Font(Font.FontFamily.TIMES_ROMAN, 11);
        Font fontBold = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD);
        //Font fontUnderline = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.UNDERLINE);
        Font fontHeader = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

        document.open();

        String dirPath = FacesContext.getCurrentInstance().getExternalContext()
                .getInitParameter("image_file_path");
        // Check servlet context for invalid character
        if (dirPath.contains(".."))
            throw new IllegalArgumentException(
                    "Servlet context contains invalid character(s).  Security may have been compromised.");
        File dir = new File(dirPath);

        Image image = Image.getInstance(dir + "/ArchiveFaxHeader.jpg");
        image.scalePercent(69, 66);
        document.add(image);

        // Create first table
        float[] colsWidthTo = { .3f, 2f, .4f, 2f };
        PdfPTable addressTable = new PdfPTable(colsWidthTo);
        addressTable.setWidthPercentage(100);
        PdfPCell toLabel = new PdfPCell(new Phrase("TO:", fontBold));
        toLabel.setRowspan(3);
        toLabel.setBorderWidthRight(0);
        addressTable.addCell(toLabel);
        PdfPCell toName = new PdfPCell(new Phrase(to, fontBold));
        toName.setBorderWidthLeft(0);
        toName.setBorderWidthBottom(0);
        addressTable.addCell(toName);
        PdfPCell fromLabel = new PdfPCell(new Phrase("FROM:", fontBold));
        fromLabel.setBorderWidthRight(0);
        fromLabel.setBorderWidthBottom(0);
        addressTable.addCell(fromLabel);
        PdfPCell fromName = new PdfPCell(new Phrase("Eligibility Case Manager", fontBold));
        fromName.setBorderWidthBottom(0);
        fromName.setBorderWidthLeft(0);
        addressTable.addCell(fromName);
        PdfPCell toAddress = new PdfPCell(new Phrase("", fontBold));
        toAddress.setBorderWidthLeft(0);
        toAddress.setBorderWidthTop(0);
        addressTable.addCell(toAddress);
        PdfPCell fromDateLabel = new PdfPCell(new Phrase("DATE:", fontBold));
        fromDateLabel.setBorderWidthRight(0);
        fromDateLabel.setBorderWidthTop(0);
        //toLabel.setRowspan(2);
        addressTable.addCell(fromDateLabel);
        PdfPCell dateFrom = new PdfPCell(new Phrase(currentDate, fontBold));
        dateFrom.setBorderWidthTop(0);
        dateFrom.setBorderWidthLeft(0);
        addressTable.addCell(dateFrom);
        addressTable.setSpacingBefore(15);
        addressTable.setSpacingAfter(15);
        document.add(addressTable);

        float[] colsWidthCaseId = { .7f, 3f };
        PdfPTable caseTable = new PdfPTable(colsWidthCaseId);
        caseTable.setWidthPercentage(100);
        PdfPCell caseIdLabel = new PdfPCell(new Phrase("Eligibility Case Id:", font3));
        caseIdLabel.setBorderWidth(0);
        caseTable.addCell(caseIdLabel);
        PdfPCell caseIdInput = new PdfPCell(new Phrase(caseIdData, font3));
        caseIdInput.setBorderWidth(0);
        caseTable.addCell(caseIdInput);
        caseTable.setSpacingAfter(8);
        document.add(caseTable);

        float[] colsWidthFolder = { .5f, 3f };
        PdfPTable folderTable = new PdfPTable(colsWidthFolder);
        folderTable.setWidthPercentage(100);
        PdfPCell folderLabel = new PdfPCell(new Phrase("VA file No:", font3));
        folderLabel.setBorderWidth(0);
        folderTable.addCell(folderLabel);
        PdfPCell folder = new PdfPCell(new Phrase(fileNo, font3));
        folder.setBorderWidth(0);
        folderTable.addCell(folder);
        folderTable.setSpacingAfter(8);
        document.add(folderTable);

        float[] colsWidthRef = { .7f, 3f };
        PdfPTable refTable = new PdfPTable(colsWidthRef);
        refTable.setWidthPercentage(100);
        PdfPCell ref = new PdfPCell(new Phrase("Veteran's Name:", font3));
        ref.setBorderWidth(0);
        refTable.addCell(ref);
        PdfPCell refName = new PdfPCell(new Phrase(vetName, font3));
        refName.setBorderWidth(0);
        refTable.addCell(refName);
        refTable.setSpacingAfter(8);
        document.add(refTable);

        float[] colsWidthSSN = { .3f, 2f, .25f, 2f };
        PdfPTable ssnTable = new PdfPTable(colsWidthSSN);
        ssnTable.setWidthPercentage(100);
        PdfPCell ssnLabel = new PdfPCell(new Phrase("SSN:", font3));
        ssnLabel.setBorderWidth(0);
        ssnTable.addCell(ssnLabel);
        PdfPCell ssn = new PdfPCell(new Phrase(ssnData, font3));
        ssn.setBorderWidth(0);
        ssnTable.addCell(ssn);
        PdfPCell snLabel = new PdfPCell(new Phrase("SN:", font3));
        snLabel.setBorderWidth(0);
        ssnTable.addCell(snLabel);
        PdfPCell sn = new PdfPCell(new Phrase(snData, font3));
        sn.setBorderWidth(0);
        ssnTable.addCell(sn);
        ssnTable.setSpacingAfter(8);
        document.add(ssnTable);

        float[] colsWidthFARC = { .6f, 2f, .8f, 2f };
        PdfPTable farcTable = new PdfPTable(colsWidthFARC);
        farcTable.setWidthPercentage(100);
        PdfPCell farcLabel = new PdfPCell(new Phrase("FARC No:", font3));
        farcLabel.setBorderWidth(0);
        farcTable.addCell(farcLabel);
        PdfPCell farc = new PdfPCell(new Phrase(farcNo, font3));
        farc.setBorderWidth(0);
        farcTable.addCell(farc);
        PdfPCell farcDateLabel = new PdfPCell(new Phrase("Transfer Date:", font3));
        farcDateLabel.setBorderWidth(0);
        farcTable.addCell(farcDateLabel);
        PdfPCell farcDate = new PdfPCell(new Phrase(transDate, font3));
        farcDate.setBorderWidth(0);
        farcTable.addCell(farcDate);
        farcTable.setSpacingAfter(8);
        document.add(farcTable);

        float[] colsWidthLoc = { .8f, 2f, .6f, 2f };
        PdfPTable locTable = new PdfPTable(colsWidthLoc);
        locTable.setWidthPercentage(100);
        PdfPCell locLabel = new PdfPCell(new Phrase("Prior Location:", font3));
        locLabel.setBorderWidth(0);
        locTable.addCell(locLabel);
        PdfPCell location = new PdfPCell(new Phrase(priorLoc, font3));
        location.setBorderWidth(0);
        locTable.addCell(location);
        PdfPCell boxNoLabel = new PdfPCell(new Phrase("Box No:", font3));
        boxNoLabel.setBorderWidth(0);
        locTable.addCell(boxNoLabel);
        PdfPCell boxNo = new PdfPCell(new Phrase(boxNoData, font3));
        boxNo.setBorderWidth(0);
        locTable.addCell(boxNo);
        locTable.setSpacingAfter(8);
        document.add(locTable);

        float[] colsWidthRemarks = { .6f, 5f };
        PdfPTable remarks1Table = new PdfPTable(colsWidthRemarks);
        remarks1Table.setWidthPercentage(100);
        PdfPCell remark1Label = new PdfPCell(new Phrase("Remarks:", font3));
        remark1Label.setBorderWidth(0);
        remarks1Table.addCell(remark1Label);
        PdfPCell remarks1Input = new PdfPCell(new Phrase(
                "Please provide copy(ies) of the following document(s) to establish eligibility for burial in a national cemetery.",
                font3));
        remarks1Input.setBorderWidth(0);
        remarks1Table.addCell(remarks1Input);
        remarks1Table.setSpacingAfter(8);
        document.add(remarks1Table);

        float[] colsWidthDocs = { .4f, 2f, .4f, 2f };
        PdfPTable docsTable = new PdfPTable(colsWidthDocs);
        docsTable.setWidthPercentage(100);
        PdfPCell docsLabel = new PdfPCell(new Phrase(sepDocs, font3));
        docsLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
        docsLabel.setBorderWidth(0);
        docsLabel.setBorderWidthBottom(1);
        docsTable.addCell(docsLabel);
        PdfPCell docs1 = new PdfPCell(new Phrase("Separation Document(s)", font3));
        docs1.setBorderWidth(0);
        docsTable.addCell(docs1);
        PdfPCell docs2 = new PdfPCell(new Phrase(deathCert, font3));
        docs2.setHorizontalAlignment(Element.ALIGN_CENTER);
        docs2.setBorderWidth(0);
        docs2.setBorderWidthBottom(1);
        docsTable.addCell(docs2);
        PdfPCell docs3 = new PdfPCell(new Phrase("Death Certificate", font3));
        docs3.setBorderWidth(0);
        docsTable.addCell(docs3);
        PdfPCell docs4 = new PdfPCell(new Phrase(marLicense, font3));
        docs4.setHorizontalAlignment(Element.ALIGN_CENTER);
        docs4.setBorderWidth(0);
        docs4.setBorderWidthBottom(1);
        docsTable.addCell(docs4);
        PdfPCell docs5 = new PdfPCell(new Phrase("Marriage License", font3));
        docs5.setBorderWidth(0);
        docsTable.addCell(docs5);
        PdfPCell docs6 = new PdfPCell(new Phrase(divorceDecree, font3));
        docs6.setHorizontalAlignment(Element.ALIGN_CENTER);
        docs6.setBorderWidth(0);
        docs6.setBorderWidthBottom(1);
        docsTable.addCell(docs6);
        PdfPCell docs7 = new PdfPCell(new Phrase("Divorce Decree", font3));
        docs7.setBorderWidth(0);
        docsTable.addCell(docs7);
        PdfPCell docs8 = new PdfPCell(new Phrase(adminDecision, font3));
        docs8.setHorizontalAlignment(Element.ALIGN_CENTER);
        docs8.setBorderWidth(0);
        docs8.setBorderWidthBottom(1);
        docsTable.addCell(docs8);
        PdfPCell docs9 = new PdfPCell(new Phrase("VA Admin Decision", font3));
        docs9.setBorderWidth(0);
        docsTable.addCell(docs9);
        PdfPCell docs10 = new PdfPCell(new Phrase("", font3));
        docs10.setBorderWidth(0);
        docsTable.addCell(docs10);
        PdfPCell docs11 = new PdfPCell(new Phrase("", font3));
        docs11.setBorderWidth(0);
        docsTable.addCell(docs11);
        document.add(docsTable);

        float[] colsWidthOther = { .4f, .4f, 4f };
        PdfPTable otherDocTable = new PdfPTable(colsWidthOther);
        otherDocTable.setWidthPercentage(100);
        PdfPCell otherDoc1 = new PdfPCell(new Phrase(otherCheck, font3));
        otherDoc1.setHorizontalAlignment(Element.ALIGN_CENTER);
        otherDoc1.setBorderWidth(0);
        otherDoc1.setBorderWidthBottom(1);
        otherDocTable.addCell(otherDoc1);
        PdfPCell otherDoc2 = new PdfPCell(new Phrase("Other", font3));
        otherDoc2.setBorderWidth(0);
        otherDocTable.addCell(otherDoc2);
        PdfPCell otherDoc3 = new PdfPCell(new Phrase("", font3));
        otherDoc3.setBorderWidth(0);
        otherDocTable.addCell(otherDoc3);
        otherDocTable.setSpacingAfter(8);
        document.add(otherDocTable);

        if (!otherComments.equals("")) {
            float[] colsWidthOtherComments = { 1.1f, 5f };
            PdfPTable otherCommentsTable = new PdfPTable(colsWidthOtherComments);
            otherCommentsTable.setWidthPercentage(100);
            PdfPCell otherCommentLabel = new PdfPCell(new Phrase("Other Comments:", font3));
            otherCommentLabel.setBorderWidth(0);
            otherCommentsTable.addCell(otherCommentLabel);
            PdfPCell otherCommentsInput = new PdfPCell(new Phrase(otherComments, font3));
            otherCommentsInput.setBorderWidth(0);
            otherCommentsTable.addCell(otherCommentsInput);
            otherCommentsTable.setSpacingAfter(8);
            document.add(otherCommentsTable);
        }

        PdfPTable remarksTable = new PdfPTable(colsWidthRemarks);
        remarksTable.setWidthPercentage(100);
        PdfPCell remarkLabel = new PdfPCell(new Phrase("Remarks:", font3));
        remarkLabel.setBorderWidth(0);
        remarksTable.addCell(remarkLabel);
        PdfPCell remarksInput = new PdfPCell(new Phrase(remarks, font3));
        remarksInput.setBorderWidth(0);
        remarksTable.addCell(remarksInput);
        remarksTable.setSpacingAfter(8);
        document.add(remarksTable);

        Paragraph expediteOne = new Paragraph("-- PLEASE EXPEDITE --", font3);
        expediteOne.setSpacingBefore(5);
        expediteOne.setSpacingAfter(10);
        document.add(expediteOne);

        Paragraph disclosure = new Paragraph(
                "This fax is intended only for the use of the person or office to which it is addressed and may contain information that is privileged, confidential, or protected by law.  All others are hereby notified that the receipt of this fax does not waive any applicable privilege or exemption for disclosure and that any dissemination, distribution, or copying of this communication is prohibited.  If you have received this fax in error, please notify this office immediately at the telephone number listed above.",
                font2);
        disclosure.setAlignment(Element.ALIGN_JUSTIFIED);
        disclosure.setSpacingBefore(5);
        disclosure.setSpacingAfter(10);
        document.add(disclosure);

        float[] colsWidthPages = { 5f, .5f, 2f };
        PdfPTable pagesTable = new PdfPTable(colsWidthPages);
        pagesTable.setWidthPercentage(71);
        PdfPCell pageOneLabel = new PdfPCell(
                new Phrase("This fax sheet consists of the cover page and ", fontHeader));
        pageOneLabel.setBorderWidth(0);
        pageOneLabel.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pagesTable.addCell(pageOneLabel);
        PdfPCell pages = new PdfPCell(new Phrase(faxPages, fontHeader));
        pages.setBorderWidth(0);
        pages.setHorizontalAlignment(Element.ALIGN_CENTER);
        pages.setBorderWidthBottom(1);
        pagesTable.addCell(pages);
        PdfPCell pageTwoLabel = new PdfPCell(new Phrase(" additional pages", fontHeader));
        pageTwoLabel.setBorderWidth(0);
        pagesTable.addCell(pageTwoLabel);
        pagesTable.setSpacingAfter(8);
        document.add(pagesTable);

        Paragraph expediteTwo = new Paragraph("FAX:  816-268-8163  ***** BURIAL  PLEASE EXPEDITE   *****",
                fontBold);
        expediteTwo.setSpacingBefore(5);
        expediteTwo.setSpacingAfter(10);
        document.add(expediteTwo);

        document.close();
    } catch (Exception ex) {
        System.err.println(ex.getMessage());
    }
    return new ByteArrayInputStream(outputStream.toByteArray());

}

From source file:ihm.panneaux.GenererPdf.java

private void initComponement() throws FileNotFoundException, DocumentException, IOException {
    String DEST = "devis/devis-" + devis.getNumero() + ".pdf";
    OutputStream file = new FileOutputStream(new File(DEST));

    com.itextpdf.text.Document document = new com.itextpdf.text.Document();
    PdfWriter.getInstance((com.itextpdf.text.Document) document, file);
    // PAS TOUCHE
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST));

    Rectangle rect = new Rectangle(30, 30, 550, 800);
    writer.setBoxSize("art", rect);
    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    writer.setPageEvent(event);//www . jav a2  s . c o  m
    document.open();
    PdfContentByte canvas = writer.getDirectContent();

    Image logo = Image.getInstance("images/logo.png");
    logo.scaleAbsolute(200, 57);

    // INFO DEVIS
    Image devisImg = Image.getInstance("images/imgDevis.png");
    devisImg.scaleAbsolute(110, 34);
    devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150),
            (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2);
    Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    Phrase numeroInfo = new Phrase("Numro  " + devis.getNumero(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413,
            devisImg.getScaledHeight() + 710, 0);
    Phrase dateInfo = new Phrase("Le  " + devis.getDate(), fontImgDevis);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420,
            devisImg.getScaledHeight() + 695, 0);
    Image devisImgBordure = Image.getInstance("images/bordureDevis.png");
    devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660);
    devisImgBordure.scaleAbsolute(120, 122);

    // INFO ENTREPRISE
    Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD);
    Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210,
            devisImg.getScaledHeight() + 660, 0);
    Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149,
            devisImg.getScaledHeight() + 640, 0);
    Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113,
            devisImg.getScaledHeight() + 625, 0);
    Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png");
    bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610);

    // INFO CLIENT
    Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL);
    Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient);
    Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient);
    Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(),
            fontClient);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 595, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 580, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280,
            devisImg.getScaledHeight() + 565, 0);

    document.add(logo);
    document.add(devisImg);
    document.add(devisImgBordure);
    document.add(bordureEntreprise);

    // AJOUT DES DONNEES DU TABLEAUX 

    float[] columnWidths = { 14, 3, 4, 3, 4 };
    Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    fontCategorie.setColor(BaseColor.GREEN);

    PdfPTable table = new PdfPTable(columnWidths);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    table.setTotalWidth(PageSize.A4.getWidth() - 15);

    table.setSpacingBefore(150);

    table.setLockedWidth(true);

    Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD);
    Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE);

    PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier));
    cellChantier.setColspan(3);
    cellChantier.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellChantier);
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    table.addCell(new Phrase("Dsignation", Categorie));
    PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie));
    PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie));
    PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie));
    PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie));

    unite.setHorizontalAlignment(Element.ALIGN_CENTER);
    quantite.setHorizontalAlignment(Element.ALIGN_CENTER);
    prixht.setHorizontalAlignment(Element.ALIGN_CENTER);
    pvtht.setHorizontalAlignment(Element.ALIGN_CENTER);

    unite.setBorder(Rectangle.NO_BORDER);
    quantite.setBorder(Rectangle.NO_BORDER);
    prixht.setBorder(Rectangle.NO_BORDER);
    pvtht.setBorder(Rectangle.NO_BORDER);

    table.addCell(unite);
    table.addCell(quantite);
    table.addCell(prixht);
    table.addCell(pvtht);

    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");
    table.addCell(" ");

    double htTotalParcour = 0;
    double ttcTotalParcour = 0;

    if (this.EquipementDeChantier.isEmpty() == false) {
        table.addCell(new Phrase("Equipement De Chantier", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

        for (DevisContenu listeMaterielDevi : EquipementDeChantier) {

            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            /* BACKUP
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            table.addCell(listeMaterielDevi.getMateriel().getUnite());
            table.addCell(Double.toString(listeMaterielDevi.getQuantite()));
            table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+"");
            table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+"");
            */
            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Couverture.isEmpty() == false) {
        table.addCell(new Phrase("Couverture", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Couverture) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureArdoise.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Ardoise", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureArdoise) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (CouvertureTuile.isEmpty() == false) {
        table.addCell(new Phrase("Couverture Tuile", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : CouvertureTuile) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (this.Demoussage.isEmpty() == false) {
        table.addCell(new Phrase("Demoussage", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Demoussage) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Velux.isEmpty() == false) {
        table.addCell(new Phrase("Velux", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Velux) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");

    }
    if (this.Zinguerie.isEmpty() == false) {
        table.addCell(new Phrase("Zinguerie", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Zinguerie) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }
    if (Plancher.isEmpty() == false) {
        table.addCell(new Phrase("Plancher", fontCategorie));
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        for (DevisContenu listeMaterielDevi : Plancher) {
            table.addCell(listeMaterielDevi.getMateriel().getNom());
            PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite()));
            PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite())));
            PdfPCell cellprix = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + ""));
            PdfPCell cellpvtHT = new PdfPCell(
                    new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + ""));
            cellunite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellprix.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellunite.setBorder(Rectangle.NO_BORDER);
            cellQuantite.setBorder(Rectangle.NO_BORDER);
            cellprix.setBorder(Rectangle.NO_BORDER);
            cellpvtHT.setBorder(Rectangle.NO_BORDER);

            table.addCell(cellunite);
            table.addCell(cellQuantite);
            table.addCell(cellprix);
            table.addCell(cellpvtHT);

            ttcTotalParcour += listeMaterielDevi.getPvtHT();
            htTotalParcour += listeMaterielDevi.getPvtHT();
        }
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
        table.addCell(" ");
    }

    ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour;

    LineDash solid = new SolidLine();
    PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc;

    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));
    table.addCell(new Phrase(" "));

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setCellEvent(new CustomBorder(null, null, null, solid));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL"));
    cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER);
    table.addCell(cellSOUSTOTAL);
    table.addCell(new Phrase(""));
    double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2);
    String httotal = String.valueOf(prixHT_2Chiffre);
    cellhttotal = new PdfPCell(new Phrase(httotal + ""));
    cellhttotal.setBorder(Rectangle.NO_BORDER);
    cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cellhttotal);

    table.addCell(new Phrase(""));
    table.addCell(new Phrase(""));
    tva = new PdfPCell(new Phrase("TVA"));
    tva.setBorder(Rectangle.NO_BORDER);
    tva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(tva);

    getTva = new PdfPCell(new Phrase(devis.getTva() + "%"));
    getTva.setBorder(Rectangle.NO_BORDER);
    getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(getTva);

    String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100);
    double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2);
    cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + ""));
    cell2.setBorder(PdfPCell.NO_BORDER);
    cell2.setCellEvent(new CustomBorder(null, null, null, solid));
    cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell2);

    table.addCell("");
    table.addCell("");
    totalttc = new PdfPCell(new Phrase("Total TTC"));
    totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    totalttc.setBorder(PdfPCell.NO_BORDER);
    table.addCell(totalttc);
    table.addCell("");
    double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2);
    String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre));
    gettotalttc = new PdfPCell(new Phrase(ttctotal + ""));
    gettotalttc.setBorder(PdfPCell.NO_BORDER);
    gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(gettotalttc);

    table.setSpacingAfter(10);

    document.add(table);

    Pattern p = Pattern.compile("[.^\\.]+");
    String texte = devis.getInformationComplementaire();

    Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlue.setColor(BaseColor.BLUE);
    Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptRed.setColor(BaseColor.RED);
    Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL);
    infoComptBlack.setColor(BaseColor.BLACK);

    Paragraph infoComp = new Paragraph();
    Image BonPourAccord = null;
    BonPourAccord = Image.getInstance("images/BonPourAccord.png");
    infoComp.setAlignment(Element.ALIGN_LEFT);
    BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT);

    String[] phrase = p.split(texte);
    for (int i = 0; i < phrase.length; i++) {
        if (i == 0 || i == 1) {
            infoComp.add(new Paragraph(phrase[i], infoComptBlue));
        }
        if (i == 2 || i == 3 || i == 4 || i == 5) {
            infoComp.add(new Paragraph(phrase[i], infoComptRed));

        }
        if (i > 5 && i <= 11)
            infoComp.add(new Paragraph(phrase[i], infoComptBlack));
        if (i > 11)
            infoComp.add(new Paragraph(phrase[i], infoComptRed));
    }
    /* A OPTIMISER */

    float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex());

    if (taille_tableau > 386) {
        document.newPage();
    }
    document.add(BonPourAccord);
    document.add(infoComp);

    document.close();

    EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis);
    this.CouvertureArdoise.clear();
    this.CouvertureTuile.clear();
    this.Demoussage.clear();
    this.EquipementDeChantier.clear();
    this.Velux.clear();
    this.Zinguerie.clear();
    this.Couverture.clear();
    this.Plancher.clear();
}

From source file:info.toegepaste.controller.PdfController.java

public void CreatePdf(long studentId) {
    //Fonts//from ww w.ja  v a 2  s.  c om
    Font header = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
    Font normal = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL);

    //Declaration
    Student student = new Student();
    List<Course> courses;
    List<Exam> exams = null;
    Score score;
    int totaal = 0; //totaal van een vak berekenen
    int maxScore = 0; //max soore van een test
    int aantalVakken = 0; //aantal vakken waaraan student heeft deelgenomen
    int klasgemiddelde = 0; //hulpvariabele om klasgemiddelde op te vragen
    Double totaalGemiddelde = 0.0; //eindpercentage
    Double vermenigvuldigfactor = 0.0; //om score op 20 weer te geven
    ArrayList<Integer> gemiddeldes = new ArrayList<Integer>(); //gemiddeldes per vak
    ArrayList<Integer> gemiddeldesKlas = new ArrayList<Integer>(); //gemiddelde klas per vak

    PdfPCell cell;

    //Document
    Document document = new Document();

    //student opvullen
    student = pdfService.getStudent(studentId);

    //Tempfix
    //student.getClassgroup();

    //cursussen opvullen
    courses = courseService.getWithClassgroup(student.getClassgroup());

    for (int i = 0; i < courses.size(); i++) {
        //testen opvullen
        exams = pdfService.getExamsByCourse(courses.get(i));
        for (int j = 0; j < exams.size(); j++) {
            score = pdfService.getScoreByExamAndStudent(exams.get(j), student);
            //nagaan of de student heeft deelgenomen aan de test
            if (score != null) {
                // score op 20 weergeven
                vermenigvuldigfactor = 20 / (double) exams.get(j).getTotal();
                totaal += (int) (score.getScore() * vermenigvuldigfactor);
            }
            //klasgemiddelde voor een vak
            klasgemiddelde = pdfService.getAverageScoreByExam(exams.get(j));
            gemiddeldesKlas.add(klasgemiddelde);
        }
        if (exams.size() > 0) {
            gemiddeldes.add(totaal / exams.size());
            totaalGemiddelde += totaal / exams.size();
            aantalVakken++;
        }
        totaal = 0;
        exams.clear();
    }

    totaalGemiddelde = totaalGemiddelde / aantalVakken * 5;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        PdfWriter.getInstance(document, outputStream);

        document.open();
        //header
        document.add(new Paragraph("Studenten Rapport", header));
        document.add(new Paragraph("Student:" + student.getFirstname() + " " + student.getLastname(), normal));
        document.add(new Paragraph("Klas:" + student.getClassgroup(), normal));
        document.add(new Paragraph("Alle scores worden op 20 weergegeven", normal));

        //table
        PdfPTable table = new PdfPTable(3);

        //create tableheaders
        PdfPCell c1 = new PdfPCell(new Phrase("Vak"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Score"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase("Gemiddelde"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
        table.setHeaderRows(1);

        for (int i = 0; i < aantalVakken; i++) {
            cell = new PdfPCell(new Phrase(gemiddeldes.get(i).toString()));
            if (gemiddeldes.get(i) < 10) {
                cell.setBackgroundColor(BaseColor.RED);
            }

            table.addCell(courses.get(i).getName());
            table.addCell(cell);
            table.addCell(gemiddeldesKlas.get(i).toString());
        }

        document.add(table);

        //end
        document.add(new Paragraph("Totaal behaald percentage:" + totaalGemiddelde, normal));
        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
        //  } catch (FileNotFoundException e) {
        //   e.printStackTrace();
    }
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(587);
    email.setSSLOnConnect(true);
    email.setAuthenticator(new DefaultAuthenticator("bitmescoretracker@gmail.com", "bitmeScore"));
    try {

        email.addTo(student.getEmail());
        email.setFrom("bitmescoretracker@gmail.com");
        email.setSubject("Requested scores , scoretracker");
        email.setMsg("Here are the scores you requested!");

        //  EmailAttachment attachment = new EmailAttachment();
        //attachment.setDescription("PDF met uw punten");
        // attachment.setName(student.getFirstname() + " " + student.getLastname() + " scores");
        byte[] bytes = outputStream.toByteArray();

        DataSource source = new javax.mail.util.ByteArrayDataSource(bytes, "application/pdf");
        System.out.println("Stuff");

        /* try{
         source = outputStream.write(bytes);
         }catch(IOException e){
             e.printStackTrace();
         }*/
        email.attach(source, student.getFirstname() + " " + student.getLastname() + " scores", "stuff");

        email.send();
    } catch (EmailException ex) {
        ex.printStackTrace();
    }

}

From source file:IPDGES.ConcentForm.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*  ww  w.  j  a va2  s.  c  om*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "FORMULARIO DE CONSTANCIA DE INFORMACION AL PACIENTE GES", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(Artculo 24, Ley 19.966)", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 2
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DATOS DEL PRESTADOR", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "INSTITUCIN (Hospital, Clnica, Consultorio,etc): " + institution, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "DIRECCION: " + address, type);
        p2 = new Paragraph(space, "CIUDAD: " + city, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "NOMBRE PERSONA QUE NOTIFICA: " + personName, type);
        p2 = new Paragraph(space, "RUT: " + rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "FONASA: " + patientFonasa, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "REGION: " + region, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type);
        p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);

        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORMACIN MDICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "CONFIRMACIN DIAGNSTICA GES:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, ges, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(  ) Confirmacin Diagnstica", type);
        p2 = new Paragraph(space, "(  ) Paciente en Tratamiento", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 5
        document.add(new Paragraph(space, "CONSTANCIA", subTitle));
        Paragraph text1 = new Paragraph(space,
                "Declaro que, con esta fecha y hora, he tomado conocimiento que tengo derecho a acceder a las Garantas Explcitas en Salud, siempre que la atencin sea otorgada en la red de Prestadores que me corresponde segn Fonasa o Isapre, a la que me encuentro adscrito",
                type);
        text1.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text1);
        document.add(new Paragraph(space, "IMPORTANTE", subTitle));
        Paragraph text2 = new Paragraph(space,
                "Tenga presente que s no se cumplen las garantas usted puede reclamar ante Fonasa o la Isapre, segn corresponda. Si la respuesta no es satisfactoria, usted puede recurrir en segunda instancia a la Superintendencia de Salud.",
                type);
        text2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text2);
        document.add(new Paragraph(space, "FECHA Y HORA DE NOTIFICACIN: " + "-", subTitle));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        //row 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORM DIAGNSTICO GES", subTitle);
        p2 = new Paragraph(space, "TOM CONOCIMIENTO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "(Firma de persona que notifica)", subTitle2);
        p2 = new Paragraph(space, "(Firma o huella digital  representante)", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 7
        document.add(new Paragraph(space,
                "En caso que la persona que tom conocimiento no sea el paciente, identificar.", type));

        //row 8
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Nombre:", type);
        p2 = new Paragraph(space, "R.U.T:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N Telfono Celular:", type);
        p2 = new Paragraph(space, "Direccin correo electrnico (e-mail):", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:IPDGES.IPD.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from www.  j a  va 2s  .co  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("application/pdf");

    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Informe de Proceso Diagnstico", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 40);
        table.addCell(cellRow1);
        document.add(table);

        //row: 2         
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Fecha: " + dfDateInstance.format(date), type);
        p2 = new Paragraph(space, "Folio: " + numberFolio, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Servicio de Salud: " + healthService, type);
        p2 = new Paragraph(space, "Establecimiento: " + establishment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthTop(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Especialidad: " + speciality, type);
        p2 = new Paragraph(space, "Unidad: " + unit, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthBottom(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Paciente", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Historia clnica: " + clinicalHistory, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + patientName, type);
        p2 = new Paragraph(space, "Rut: " + Rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Sexo: " + sexo, type);
        p2 = new Paragraph(space, "Fecha de nacimiento: " + dfDateInstance.format(bornDate), type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "Edad: " + age, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 5
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos Clnicos", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "* Slo para caso AUGE", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Problema de salud AUGE:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Confirma que el diagnstico pertenece al sistema AUGE? " + "()SI ()NO",
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "SubProblema Auge:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, augeSubProblem, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosis, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Fundamentos de diagnstico:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, diagnosticBasics, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Tratamiento e Indicaciones:", typeBold);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, treatment, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space,
                "El tratamiento deber iniciarce a ms tardar el: " + dfDateInstance.format(treatmentInit),
                type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        //row: 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Datos del Profesional", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Nombre: " + professionalName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Rut: " + professionalRut, type);
        p2 = new Paragraph(space, "Firma del mdico", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));
        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:jeanderson.br.nota.Notas.java

public boolean gerarNotas(int desconto) {
    PdfPTable tabela = new PdfPTable(new float[] { 0.7f, 0.18f, 0.2f });
    Document doc = new Document(PageSize.A4, 72, 72, 72, 72);
    try {//ww  w.j a va  2  s . c o  m
        OutputStream os = new FileOutputStream("/Users/" + System.getProperty("user.name")
                + "/Google Drive/Notas Fiscais/PDF/" + nomeCliente + ".pdf");
        PdfWriter.getInstance(doc, os); // instancio o pdf que vou gravar
        doc.open(); // abro o pdf
        // seleciono a fonte, tamanho
        Font f = new Font(Font.FontFamily.COURIER, 20, Font.BOLD);
        //crio o paragrafo.
        Paragraph p1 = new Paragraph("Nota Eletrnica", f);
        Paragraph p2 = new Paragraph("Comprador(a): " + nomeCliente + "\nEndereo: " + endereco + "\nBairro: "
                + bairro + "  " + "Cidade: " + cidade + "\nVendedor: Jonatha Monteiro");
        PdfPCell celula = new PdfPCell(p1);
        celula.setColspan(3);
        celula.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(celula);
        PdfPCell celula2 = new PdfPCell(p2);
        celula2.setColspan(3);
        tabela.addCell(celula2);
        PdfPCell nProduto = new PdfPCell(new Paragraph("Produto"));
        PdfPCell nValor = new PdfPCell(new Paragraph("Valor(UN)"));
        nProduto.setHorizontalAlignment(Element.ALIGN_CENTER);
        nValor.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(nProduto);
        tabela.addCell("Quantidade");
        tabela.addCell(nValor);
        double valorTotal = 0;
        for (int i = 0; i < this.produtos.size(); i++) {
            tabela.addCell(produtos.get(i));
            tabela.addCell(quantidades.get(i));
            tabela.addCell(valor.get(i));
            valorTotal += Integer.parseInt(quantidades.get(i)) * Double.parseDouble(valor.get(i));
        }
        Paragraph p3 = null;
        if (desconto == 0) {
            p3 = new Paragraph("Data de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
        } else {
            p3 = new Paragraph(
                    "\n\nData de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
        }
        PdfPCell celula3 = new PdfPCell(p3);
        celula3.setColspan(1);
        tabela.addCell(celula3);
        DecimalFormat df = new DecimalFormat("###,##0.00");
        Paragraph p4 = new Paragraph("Valor Total: R$" + df.format(valorTotal));
        PdfPCell celula4 = null;
        double valorDesc = 0;
        double valorComDesc = 0;
        switch (desconto) {
        case 0:
            celula4 = new PdfPCell(p4);
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 1:
            valorDesc = (valorTotal * 7) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 7% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 2:
            valorDesc = (valorTotal * 10) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n - 10% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 3:
            valorDesc = (valorTotal * 12) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 12% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        case 4:
            valorDesc = (valorTotal * 15) / 100;
            valorComDesc = valorTotal - valorDesc;
            celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal)
                    + "\n- 15% Desconto\nValor a pagar: R$" + df.format(valorComDesc)));
            celula4.setColspan(2);
            tabela.addCell(celula4);
            break;
        }
        //tabela.addCell(celula4);
        tabela.setWidthPercentage(100.0f);
        doc.add(tabela); // adiciono a tabela
        doc.close();
        os.close();
        return false;
    } catch (FileNotFoundException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    } catch (DocumentException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    } catch (IOException ex) {
        Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage());
        Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex);
        return true;
    }
}

From source file:Logic.DocsCreation.java

public void createPdfDoc(JTable Table, GetPatientData data, StartDB con, boolean flag,
        ArrayList<String> arrPatient, String crb) {
    try {//from   ww  w.  jav  a2s .  c  om
        norm.getNorm(con.getConnection());
        int b = arrPatient.size();
        if (b == -1) {
            return;
        }
        String path = System.getProperty("user.home");
        path = path + "//Desktop//";
        File theDir = new File(path, "???");
        // if the directory does not exist, create it
        if (!theDir.exists()) {

            boolean result = false;

            try {
                theDir.mkdir();
                result = true;
            } catch (SecurityException se) {
                //handle it
            }
            if (result) {
                System.out.println("DIR created");
            }
        }
        for (int k = 0; k < b; k++) {
            String id = arrPatient.get(k);//Table.getModel().getValueAt(k, 0).toString(); 
            data = new GetPatientData();
            data.getMainData(con.getConnection(), id, crb);
            data.getPatientDocs(con.getConnection(), id);
            String[] arr = null;
            String fname = data.getName().replaceAll(" ", "") + data.getBirth();

            Document doc = new Document();
            String fileName = path + "\\???\\" + fname + ".pdf";
            String pdfName = "";
            FileOutputStream fos = new FileOutputStream(fileName);
            PdfWriter.getInstance(doc, fos);
            doc.open();

            BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\ARIAL.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            BaseFont bfn = BaseFont.createFont("C:\\Windows\\Fonts\\ARIALI.TTF", BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            // 
            Paragraph title = new Paragraph(data.getCrbName() + "\n", new Font(bf, 16, Font.BOLD));
            title.setAlignment(Element.ALIGN_CENTER);
            doc.add(title);
            // ? 
            Paragraph lpu = new Paragraph("?   " + data.getLpu(), new Font(bf, 12));
            lpu.setAlignment(Element.ALIGN_RIGHT);
            doc.add(lpu);
            doc.add(new Phrase(
                    "____________________________________________________________________________________\n",
                    new Font(bf, 11, Font.BOLD)));

            doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getName() + " (" + data.getSex() + ")\n", new Font(bf, 13)));
            doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getBirth() + "\n", new Font(bf, 13)));
            doc.add(new Phrase(" ? ??: ",
                    new Font(bf, 13, Font.BOLD)));
            doc.add(new Phrase(data.getDate() + "\n", new Font(bf, 13)));

            if (data.getSnils() != null) {
                doc.add(new Phrase("? : ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getSnils() + "\n", new Font(bf, 13)));
            }
            if (data.getDocs() != null) {
                doc.add(new Phrase(": ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getDocs() + " ", new Font(bf, 13)));
                ;
            }
            if (data.getPolicy() != null) {
                doc.add(new Phrase(" ?: ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPolicy() + "; ", new Font(bf, 13)));
            }

            if (data.getPhone() != null) {
                doc.add(new Phrase("?  ", new Font(bf, 13, Font.BOLD)));
                doc.add(new Phrase(data.getPhone() + "; ", new Font(bf, 13)));
            }
            //  ?

            data.getDoneServiceCount(con.getConnection(), id);
            data.getDoneServiceData(con.getConnection(), id);
            // data.getDoneServiceProp(con.getConnection(), id,data.getService_code().get(k));
            //  ?
            doc.add(new Paragraph("\n ?: \n", new Font(bf, 16, Font.BOLD)));

            for (int i = 0; i < data.getCount(); i++) {
                data.getDoneServiceProp(con.getConnection(), id, data.getService_code().get(i));
                doc.add(new Phrase(data.getService_name().get(i) + " : \n", new Font(bf, 12, Font.BOLD)));
                if (data.getService_result().get(i) != null) {
                    arr = data.getService_result().get(i).split(";");

                    for (int l = 0; l < norm.getCode().size(); l++) {
                        if (data.getService_code().get(i).equals(norm.getCode().get(l))) {
                            flagExistNorm = true;
                            if ("".equals(data.getSex()))
                                arrNorm = norm.getNormsWoman().get(l).split(";");
                            else if ("".equals(data.getSex())) {
                                arrNorm = norm.getNormsMan().get(l).split(";");
                            }

                            break;
                        } else
                            flagExistNorm = false;
                    }

                    //<editor-fold defaultstate="collapsed" desc="?? ?? ">
                    //                switch(data.getService_name().get(i)){            
                    //                    
                    //                    case "01.?()":
                    //                    doc.add(new Phrase("  ? - " +arr[0]+ " ;\n " ,new Font(bf, 12)));
                    //                    break;
                    //                    
                    //                    case "02.??":                 
                    //                        doc.add(new Phrase("? - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?  - " + arr[1] +" ;\n ",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                    case "03.  ?":                 
                    //                        doc.add(new Phrase("   - " + arr[0] +" ; ",new Font(bf, 12)));
                    //                        doc.add(new Phrase("?   - " + arr[1] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[2] +" ;\n ",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                     case "06.?  " :                 
                    //                            
                    //                     {   
                    //                            doc.add(new Phrase("  " +";\n ",new Font(bf, 12)));
                    //                            pdfName = "C:\\MDKTemp\\"+fname+"ECG.pdf";
                    //                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                    //                            targetFile.write(data.getPDFData(con.getConnection(), id));
                    //                            targetFile.close();
                    //                            log.info("pdf  ? "+id+ "?");
                    //                            } catch (Exception ex) {
                    //                                    log.error(ex, ex);                            
                    //                            }
                    //                        }
                    //                     break;         
                    //
                    //                     case "08.? ":                 
                    //                        doc.add(new Phrase(" ?? - " + arr[0] +" ;\n",new Font(bf, 12)));               
                    //                        break; 
                    //
                    //                     case "13.  ":                 
                    //                        doc.add(new Phrase("\n (), / - " + arr[0] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", /- " + arr[1] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[2] +" - \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (),-/ - " + arr[3] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), -/ - " + arr[4] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? ? - " + arr[5] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("pH - " + arr[6] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(", / - " + arr[7] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("??? ?, / - " + arr[8] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[9] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" (), / - " + arr[10] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[11] +" ; \n",new Font(bf, 12)));
                    //                        doc.add(new Phrase("? - " + arr[12] +" ;\n",new Font(bf, 12)));
                    //                        break; 
                    //
                    //                        case "16.  ?":                 
                    //                        doc.add(new Phrase(" - " + arr[0] +" ;",new Font(bf, 12)));
                    //                        doc.add(new Phrase(" - " + arr[1] +" ;",new Font(bf, 12)));                
                    //                        break;
                    //                    } 
                    //</editor-fold>    
                    //            
                    int arrSize = arr.length;
                    for (int j = 0; (j < arrSize); j++) {

                        if (data.getService_name().get(i).contains("?")
                                || data.getService_name().get(i).contains("")) {
                            doc.add(new Phrase("  " + ";\n ", new Font(bf, 12)));
                            pdfName = "C:\\MDKTemp\\" + fname + "ECG.pdf";
                            try (OutputStream targetFile = new FileOutputStream(pdfName)) {
                                targetFile.write(data.getPDFData(con.getConnection(), id));
                                targetFile.close();
                                log.info("pdf  ? " + id + "?");

                                break;
                            } catch (Exception ex) {
                                log.error(ex, ex);
                            }
                        }
                        if (flagExistNorm) {
                            String[] border;
                            border = new String[2];

                            border = arrNorm[j].split(" - ");
                            if (Float.parseFloat(arr[j]) >= Float.parseFloat(border[0])) {
                                if (Float.parseFloat(arr[j]) <= Float.parseFloat(border[1])) {
                                    //   ?

                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                            new Font(bf, 12)));
                                } else {
                                    //    
                                    doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                            new Font(bf, 12, Font.UNDERLINE)));
                                    if (border[0].equals(border[1])) {
                                        doc.add(new Phrase("! (? " + border[0] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                    } else
                                        doc.add(new Phrase(
                                                "! (? " + border[0] + " - " + border[1] + ");\n",
                                                new Font(bfn, 12, Font.UNDERLINE)));
                                }
                            } else {
                                //    
                                doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ; ",
                                        new Font(bf, 12, Font.UNDERLINE)));
                                if (border[0].equals(border[1])) {
                                    doc.add(new Phrase("! (? " + border[0] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                                } else
                                    doc.add(new Phrase(
                                            "! (? " + border[0] + " - " + border[1] + ");\n",
                                            new Font(bfn, 12, Font.UNDERLINE)));
                            }
                        } else
                            doc.add(new Phrase(data.getService_prop().get(j) + " - " + arr[j] + " ;\n",
                                    new Font(bf, 12)));

                    }

                }
            }
            //  ?
            data.getAppoitedServiceCount(con.getConnection(), id);
            data.getAppServiceData(con.getConnection(), id);
            doc.add(new Phrase("? ? :\n", new Font(bf, 16, Font.BOLD)));
            for (int j = 0; j < data.getCount(); j++) {
                if (data.getService_result().get(j) != null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_result().get(j) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(j) == null) {
                    doc.add(new Phrase(data.getService_name().get(j) + " ; ", new Font(bf, 12, Font.BOLD)));
                }
            }
            // 
            data.getRenServiceCount(con.getConnection(), id);
            data.getRenServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_name().get(i) == null) {
                    doc.add(new Phrase("? ", new Font(bf, 12)));
                }
                doc.add(new Phrase(data.getService_name().get(i) + " ; ", new Font(bf, 12, Font.BOLD)));
            }
            // 
            data.getEarlierServiceCount(con.getConnection(), id);
            data.getEarServiceData(con.getConnection(), id);
            doc.add(new Phrase("\n  : ", new Font(bf, 16, Font.BOLD)));
            for (int i = 0; i < data.getCount(); i++) {
                if (data.getService_result().get(i) != null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " - ", new Font(bf, 12, Font.BOLD)));
                    doc.add(new Phrase(data.getService_date().get(i) + " ; ", new Font(bf, 12)));
                }
                if (data.getService_result().get(i) == null) {
                    doc.add(new Phrase(data.getService_name().get(i) + " ;", new Font(bf, 12)));
                }

            }
            doc.close();
            if (!flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = path + "//???//" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                }
            }

            if (flag) {
                if (!pdfName.equals("")) {
                    AddCover1 cov = new AddCover1();
                    String tempFile = fileName;
                    String ECGFile = pdfName;
                    String res = "C:\\" + fname + "ECG.pdf";
                    File file = new File(res);
                    file.getParentFile().mkdirs();
                    cov.manipulatePdf(ECGFile, res, tempFile);
                    File dfile = new File(fileName);
                    if (dfile.delete()) {
                        System.out.println(dfile.getName() + " is deleted!");
                    } else {
                        System.out.println("Delete operation is failed.");
                    }

                    File pfile = new File(res);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                } else {
                    File pfile = new File(fileName);
                    try {
                        Desktop.getDesktop().print(pfile);
                        Thread.sleep(2000);
                    } catch (IOException ex) {
                        log.error(ex, ex);
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error(e, e);
    }

}

From source file:managedbeans.Doctor.ImprimirAnamnesis.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from w w w . j ava 2s. c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    String rut = request.getParameter("rut");
    String id = request.getParameter("id");
    Integer search = Integer.parseInt(rut);
    Integer idEp = Integer.parseInt(id);
    episodio = episodiosFacade.find(idEp);
    List<Persona> person = personaNegocio.busquedaPersonaRut(search);
    Persona personSelected;

    if (person.size() > 0) {
        System.out.println("La cantidad es:" + person.size());
        personSelected = person.get(0);
        System.out.println("La cantidad es:" + personSelected.getPersNombres());
        paciente = pacienteNegocio.busquedaPacienteIdPersona(personSelected.getIdPersona());
        signos = muestaFacade.searchByPatient(paciente);
        if (signos.size() > 0) {
            for (Muesta signo : signos) {
                if (signo.getIdSvitales().getIdSvitales() == 1)
                    peso = signo.getValor();
                if (signo.getIdSvitales().getIdSvitales() == 2)
                    altura = signo.getValor();
                if (signo.getIdSvitales().getIdSvitales() == 3)
                    temperatura = signo.getValor();
                if (signo.getIdSvitales().getIdSvitales() == 5)
                    presion = signo.getValor();
                if (signo.getIdSvitales().getIdSvitales() == 9)
                    pulso = signo.getValor();
                if (signo.getIdSvitales().getIdSvitales() == 17)
                    imc = signo.getValor();
            }
        }
        if (consultaFacade.searchByEpisodio(episodio).size() > 0)
            consulta = consultaFacade.searchByEpisodio(episodio).get(0);
        patientName = personSelected.getPersNombres() + " " + personSelected.getPersApepaterno() + " "
                + personSelected.getPersApematerno();
        patientRut = search;
        patientFonasa = "";
        patientIsapre = paciente.getPaciOtraprevision();
        home = personSelected.getPersDireccion();
        commune = paciente.getPersona().getIdComuna().getComuNombre();
        region = "";
        phoneNumber = personSelected.getPersTelefono();
        celularNumber = personSelected.getPersCelular();
        mail = personSelected.getPersEmail();
    }
    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANAMNESIS", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Hospital Barros Luco", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "PREVISION: " + paciente.getIdPrevision().getPreviNombre(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "TELFONO DE CONTACTO: " + paciente.getPersona().getPersTelcontacto(), type);
        p2 = new Paragraph(space, "CORREO: " + paciente.getPersona().getPersEmail(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANAMNESIS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, consulta.getMotivoConsulta(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "HISTORIA OBSTTRICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "F.U.R.: ", type);
        p2 = new Paragraph(space, "F.P.P.: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "PARTOS: ", type);
        p2 = new Paragraph(space, "ABORTOS: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "FECHA LTIMO PARTO: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "EX?MEN F?SICO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "PRESIN ARTERIAL: " + presion, type);
        p2 = new Paragraph(space, "TEMPERATURA: " + temperatura, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "PULSO: " + pulso, type);
        p2 = new Paragraph(space, "PESO: " + peso, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "TALLA: " + altura, type);
        p2 = new Paragraph(space, "I.M.C.: " + imc, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "EX?MEN OBSTTRICO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "A.U.: ", type);
        p2 = new Paragraph(space, "L.C.F.: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "D.U.: ", type);
        p2 = new Paragraph(space, "PRESENTACIN: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        if (1 == 0) {
            table.addCell(cellRow1);
            table.addCell(cellRow2);
            p1 = new Paragraph(space, "POSICIN: ", type);
            p2 = new Paragraph(space, "CONSISTENCIA: ", type);
            cellRow1 = new PdfPCell(p1);
            cellRow2 = new PdfPCell(p2);
            formatCellBorder(cellRow1, 20);
            formatCellBorder(cellRow2, 20);
            cellRow1.setBorderWidthLeft(1);
            cellRow2.setBorderWidthRight(1);
            table.addCell(cellRow1);
            table.addCell(cellRow2);
            p1 = new Paragraph(space, "BORRAMIENTO: ", type);
            p2 = new Paragraph(space, "DILATACION: ", type);
            cellRow1 = new PdfPCell(p1);
            cellRow2 = new PdfPCell(p2);
            formatCellBorder(cellRow1, 20);
            formatCellBorder(cellRow2, 20);
            cellRow1.setBorderWidthLeft(1);
            cellRow2.setBorderWidthRight(1);
            table.addCell(cellRow1);
            table.addCell(cellRow2);
            p1 = new Paragraph(space, "PLANO: ", type);
            p2 = new Paragraph(space, "MEMBRANAS: ", type);
            cellRow1 = new PdfPCell(p1);
            cellRow2 = new PdfPCell(p2);
            formatCellBorder(cellRow1, 20);
            formatCellBorder(cellRow2, 20);
            cellRow1.setBorderWidthLeft(1);
            cellRow2.setBorderWidthRight(1);
        }
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "RESUMEN PATOLOG?AS MATERNAS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "PATOLOG?AS: ", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DIAGNOSTICOS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Este es un diagnostico", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INDICACIONES", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Estas son indicaciones", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:managedbeans.ImprimirAnamnesis.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request//from   w w w. j  a  v  a  2  s  .co m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    String rut = request.getParameter("rut");
    String idAnam = request.getParameter("id");
    Integer search = Integer.parseInt(rut);
    Integer anam = Integer.parseInt(idAnam);
    anamnesis = anamnesisFacade.find(anam);
    List<Persona> person = personaNegocio.busquedaPersonaRut(search);
    Persona personSelected;

    if (person.size() > 0) {
        System.out.println("La cantidad es:" + person.size());
        personSelected = person.get(0);
        System.out.println("La cantidad es:" + personSelected.getPersNombres());
        paciente = pacienteNegocio.busquedaPacienteIdPersona(personSelected.getIdPersona());
        patientName = personSelected.getPersNombres() + " " + personSelected.getPersApepaterno() + " "
                + personSelected.getPersApematerno();
        patientRut = search;
        patientFonasa = "";
        patientIsapre = paciente.getPaciOtraprevision();
        home = personSelected.getPersDireccion();
        commune = "";
        region = "";
        phoneNumber = personSelected.getPersTelefono();
        celularNumber = personSelected.getPersCelular();
        mail = personSelected.getPersEmail();
    }
    try {
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANAMNESIS", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "Hospital Barros Luco", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "FONASA: " + patientFonasa, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "REGION: " + region, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type);
        p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);

        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANAMNESIS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "HISTORIA OBSTTRICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "EX?MEN F?SICO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "EX?MEN OBSTTRICO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "RESUMEN PATOLOG?AS MATERNAS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DIAGNOSTICOS", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INDICACIONES", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, anamnesis.getAnamDescripcion(), type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}

From source file:managedbeanTest.PruebaMartolo.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");

    try {//ww  w. j a v a2s . c  om
        //style
        Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1);
        Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1);
        Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1);
        Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1);
        float space = (float) 20;

        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();

        //General
        PdfPTable table;
        Paragraph p1;
        Paragraph p2;
        PdfPCell cellRow1;
        PdfPCell cellRow2;

        //row: 1
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "FORMULARIO DE CONSTANCIA DE INFORMACION AL PACIENTE GES", title);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(Artculo 24, Ley 19.966)", subTitle2);
        p1.setAlignment(Element.ALIGN_CENTER);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row: 2
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "DATOS DEL PRESTADOR", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "INSTITUCIN (Hospital, Clnica, Consultorio,etc): " + institution, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "DIRECCION: " + address, type);
        p2 = new Paragraph(space, "CIUDAD: " + city, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "NOMBRE PERSONA QUE NOTIFICA: " + personName, type);
        p2 = new Paragraph(space, "RUT: " + rut, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 3
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "NOMBRE: " + patientName, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "RUT: " + patientRut, type);
        p2 = new Paragraph(space, "FONASA: " + patientFonasa, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type);
        p2 = new Paragraph(space, "DOMICILIO: " + home, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "COMUNA: " + commune, type);
        p2 = new Paragraph(space, "REGION: " + region, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type);
        p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);

        table.addCell(cellRow1);
        document.add(table);
        document.add(new Paragraph("\n"));

        //row 4
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORMACIN MDICA", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthTop(1);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "CONFIRMACIN DIAGNSTICA GES:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, ges, type);
        cellRow1 = new PdfPCell(p1);
        cellRow1.setColspan(2);
        formatCellBorder(cellRow1, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow1.setBorderWidthRight(1);
        table.addCell(cellRow1);
        p1 = new Paragraph(space, "(  ) Confirmacin Diagnstica", type);
        p2 = new Paragraph(space, "(  ) Paciente en Tratamiento", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        cellRow1.setBorderWidthLeft(1);
        cellRow2.setBorderWidthRight(1);
        cellRow1.setBorderWidthBottom(1);
        cellRow2.setBorderWidthBottom(1);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 5
        document.add(new Paragraph(space, "CONSTANCIA", subTitle));
        Paragraph text1 = new Paragraph(space,
                "Declaro que, con esta fecha y hora, he tomado conocimiento que tengo derecho a acceder a las Garantas Explcitas en Salud, siempre que la atencin sea otorgada en la red de Prestadores que me corresponde segn Fonasa o Isapre, a la que me encuentro adscrito",
                type);
        text1.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text1);
        document.add(new Paragraph(space, "IMPORTANTE", subTitle));
        Paragraph text2 = new Paragraph(space,
                "Tenga presente que s no se cumplen las garantas usted puede reclamar ante Fonasa o la Isapre, segn corresponda. Si la respuesta no es satisfactoria, usted puede recurrir en segunda instancia a la Superintendencia de Salud.",
                type);
        text2.setAlignment(Element.ALIGN_JUSTIFIED);
        document.add(text2);
        document.add(new Paragraph(space, "FECHA Y HORA DE NOTIFICACIN: " + "-", subTitle));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        document.add(new Paragraph(space, "\n", type));
        //row 6
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "INFORM DIAGNSTICO GES", subTitle);
        p2 = new Paragraph(space, "TOM CONOCIMIENTO", subTitle);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "(Firma de persona que notifica)", subTitle2);
        p2 = new Paragraph(space, "(Firma o huella digital  representante)", subTitle2);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);
        //row 7
        document.add(new Paragraph(space,
                "En caso que la persona que tom conocimiento no sea el paciente, identificar.", type));

        //row 8
        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        p1 = new Paragraph(space, "Nombre:", type);
        p2 = new Paragraph(space, "R.U.T:", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        p1 = new Paragraph(space, "N Telfono Celular:", type);
        p2 = new Paragraph(space, "Direccin correo electrnico (e-mail):", type);
        cellRow1 = new PdfPCell(p1);
        cellRow2 = new PdfPCell(p2);
        formatCellBorder(cellRow1, 20);
        formatCellBorder(cellRow2, 20);
        table.addCell(cellRow1);
        table.addCell(cellRow2);
        document.add(table);

        document.close();
    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }

}