Example usage for com.itextpdf.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(final float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorizationB1606.java

private static void generateDocumentPage1(TrackingRecordScreeningLetter screeningLetter, Document document,
        PdfWriter writer) throws BadElementException, DocumentException, Exception {
    PdfPTable table = null;
    int headerwidths[] = {};
    Paragraph paragraph = null;/*from   w  ww.  ja va 2 s .  c  om*/
    List blist = null;
    ListItem item = null;
    ListItem subItem = null;
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    StringBuilder sb;
    PdfContentByte over = writer.getDirectContent();

    // LS Authorization Letter Page 1
    addLetterIdentifier(document);

    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase("Office of Licensing Livescan Authorization", largefontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(30.0f);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase(df.format(screeningLetter.getLetterDate()), mediumfontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("Office of Licensing Information", mediumfontBU));
    paragraph.setSpacingBefore(20.0f);
    document.add(paragraph);

    /*
     * Start of Office of Licensing Information generation
     */
    table = new PdfPTable(2);
    // format the table
    headerwidths = new int[] { 60, 40 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);
    table.setSpacingBefore(pageSeparatorSpace);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase("TYPE OF TRANSACTION: FANC", largefontB));
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(new Phrase("REASON FINGERPRINTED: UCA 53-10-108", largefontB));
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(new Phrase("BILLING CODE: B1606", largefontB));
    table.addCell(paragraph);
    paragraph = new Paragraph(fixedLeadingSmall);
    Calendar cal = Calendar.getInstance();
    cal.setTime(screeningLetter.getLetterDate());
    cal.add(Calendar.DAY_OF_MONTH, 16);
    paragraph.add(new Phrase("This Authorization Expires: " + df.format(cal.getTime()), smallfont));
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(paragraph);
    document.add(table);

    // Add Fee information
    paragraph = new Paragraph(fixedLeadingSmall);
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null
            && screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getScanFee() != null) {
        paragraph.add(new Phrase("Scan Fee = ", smallfont));
        paragraph
                .add(new Phrase(
                        CommonUtils.fromDoubleToCurrency(
                                screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getScanFee()),
                        smallfontB));
    } else {
        paragraph.add(new Phrase("Search Fee = ", smallfont));
        if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null
                && screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getSearchFee() != null) {
            paragraph.add(new Phrase(
                    CommonUtils.fromDoubleToCurrency(
                            screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getSearchFee()),
                    smallfontB));
        } else {
            paragraph.add(SMALL_BLANK);
        }
    }
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add Authorized Signature line
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase(
            "Office of Licensing Authorized Signature ___________________________________________________  Date ________________",
            smallfont));
    paragraph.setSpacingBefore(18.0f);
    document.add(paragraph);

    // Stamp the document date over the Date line above
    // NOTE: Use showColumnBorders as a diagnostic to display borders of column where date will be placed on document.
    //showColumnBorders(over);
    ColumnText ct = new ColumnText(over);
    ct.setLeading(fixedLeadingSmall);
    ct.addText(new Phrase(df.format(screeningLetter.getLetterDate()), smallfont));
    // Write column to document
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.setSimpleColumn(COLUMNS[0][0], COLUMNS[0][1], COLUMNS[0][2], COLUMNS[0][3]);
    ct.go();

    over.setLineWidth(3.0f);
    over.setCMYKColorStroke(166, 92, 0, 145);
    over.moveTo(document.getPageSize().getLeft(65), BOTTOM_SEPARATOR_EDGE);
    over.lineTo(document.getPageSize().getRight(65), BOTTOM_SEPARATOR_EDGE);
    over.stroke();

    // Add Program & Applicatant header line
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("Program & Applicant Information and Instructions", smallfontBU));
    paragraph.setSpacingBefore((2 * pageSeparatorSpace) + fixedLeadingSmall);
    document.add(paragraph);

    /*
     * Start of Applicant information line generation
     */
    table = new PdfPTable(3);
    // format the table
    headerwidths = new int[] { 43, 20, 37 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);
    table.setSpacingBefore(pageSeparatorSpace);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_MIDDLE);

    // Add Applicant name
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("Applicant: ", smallfontB));
    if (screeningLetter.getTrackingRecordScreening().getPerson() != null
            && StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getFirstAndLastName())) {
        paragraph.add(
                new Phrase(screeningLetter.getTrackingRecordScreening().getFirstAndLastName(), smallfontB));
    }
    table.addCell(paragraph);

    // Add Applicant ID
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("ID: ", smallfontB));
    if (StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getPersonIdentifier())) {
        paragraph.add(
                new Phrase(screeningLetter.getTrackingRecordScreening().getPersonIdentifier(), smallfontB));
    }
    table.addCell(paragraph);

    // Add DOB information
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("DOB: ", smallfontB));
    try {
        paragraph.add(
                new Phrase(df.format(screeningLetter.getTrackingRecordScreening().getBirthday()), smallfontB));
    } catch (NullPointerException e) {

    }
    table.addCell(paragraph);
    // Add Applicant Information Line Table to document
    document.add(table);
    /*
     * End of Applicant information line generation
     */

    // Add Application program line
    paragraph = new Paragraph(fixedLeadingSmall);
    sb = new StringBuilder();
    sb.append("Applicant Program: ");
    if (screeningLetter.getTrackingRecordScreening().getFacility() != null
            && StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getFacility().getName())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getFacility().getName().toUpperCase());
    }
    paragraph.add(new Phrase(sb.toString(), smallfontB));
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add Payment information line
    paragraph = new Paragraph(fixedLeadingSmall);
    sb = new StringBuilder();
    sb.append("Payment issued by: ");
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null && StringUtils
            .isNotBlank(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getIssuedBy())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getIssuedBy().toUpperCase());
    }
    sb.append("    ");
    sb.append("Check Number: ");
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null && StringUtils
            .isNotBlank(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getMoNumber())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getMoNumber().toUpperCase());
    }
    paragraph.add(new Phrase(sb.toString(), smallfontB));
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add READ THIS CAREFULLY
    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("READ THIS CAREFULLY", largefontBU));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace + fixedLeadingLarge);
    document.add(paragraph);

    /*
     * Start of instructions list section
     */
    blist = new List(false, 20);
    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("1.", mediumfont));
    item.add(new Phrase(
            "The Office of Licensing authorizes the applicant to submit her/his fingerprints for an electronic applicant background check ",
            smallfont));
    item.add(new Phrase(
            "at various sites throughout Utah using the Live Scan system. Each site charges a fee for the electronic fingerprint scan. ",
            smallfont));
    item.add(new Phrase(
            "Scanning fees vary from site to site. This is a separate fee from the one submitted to the Department of Human Services for ",
            smallfont));
    item.add(new Phrase("the actual criminal background search.", smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("2.", mediumfont));
    item.add(new Phrase(
            "Complete electronic fingerprint submission within 15 days of the date of this authorization letter. If unused, ",
            smallfontB));
    item.add(new Phrase(
            "requests for refunds will not be considered after 30 days. Refund requests require a letter of explanation ",
            smallfontB));
    item.add(new Phrase(
            "from the licensed program accompanied by this original authorization letter. Failure to complete electronic ",
            smallfontB));
    item.add(new Phrase(
            "fingerprint submission within this time will result in the denial of the background screening clearance and ",
            smallfontB));
    item.add(new Phrase(
            "the applicant will not be permitted to have direct access to children or vulnerable adults, will not be eligible ",
            smallfontB));
    item.add(new Phrase(
            "to provide services to programs licensed by the Utah Department of Human Services, Office of Licensing, and will not be ",
            smallfontB));
    item.add(new Phrase("eligible to proceed with foster care or adoption.", smallfontB));
    item.setSpacingBefore(4.0f);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("3.", mediumfont));
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("You will need to take with you:", smallfont));
    item.add(paragraph);
    List subList = new List(false, 10);
    subList.setIndentationLeft(10);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(new Phrase("This original letter. Photocopies and facsimile (FAX) copies will not be accepted.",
            smallfont));
    subList.add(subItem);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(new Phrase(
            "Photo I.D. in the form of your driver license or state identification card issued by the Division of Motor Vehicles.",
            smallfont));
    subList.add(subItem);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(
            new Phrase("Cash or check as required (see site list for acceptable form of payment).", smallfont));
    subList.add(subItem);
    item.add(subList);
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("4.", mediumfont));
    item.add(new Phrase(
            "If the electronically submitted fingerprints are rejected, the Office of Licensing will notify the applicant/licensed program ",
            smallfont));
    item.add(new Phrase("of additional instructions for completing the nationwide background search.",
            smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("5.", mediumfont));
    item.add(new Phrase(
            "Applicant Signature ___________________________________________________  Date ________________",
            smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);
    document.add(blist);
    /*
     * End of instructions list section
     */

    paragraph = new Paragraph();
    paragraph.add(new Phrase(
            "A current list of Livescan sites is available at www.hslic.utah.gov/docs/livescan sites.pdf",
            smallfont));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("Live Scan Operator: Keep this original for auditing purposes.", mediumfontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);
}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.InspectionsConductedReport.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor)
        throws TemplateException {
    FindingCategoryType fCat = getFindingCategory(context);
    PickListValue insType = getInspectionType(context);

    List<Object[]> results = getResults(context);

    ReportTable<Integer> reportTable = new ReportTable<Integer>();

    for (Object[] res : results) {
        String row = (String) res[1];
        String column = (String) res[0];
        Integer val = ((BigDecimal) res[2]).intValue();

        reportTable.addRow(row);/* w  w w. java 2s .  c  o  m*/
        reportTable.addColumn(column);
        reportTable.addTableDataItem(row, column, val);
    }

    setFileName(context, fileDescriptor);

    Document document = new Document(PAGE_SIZE, 36, 36, 36, 36);
    try {
        PdfWriter.getInstance(document, outputStream);
        document.open();

        StringBuilder sb = new StringBuilder();
        if (insType != null) {
            sb.append(insType.getValue());
            sb.append(" ");
        }
        sb.append("Inspections Conducted");
        if (fCat != null) {
            sb.append(" With ");
            sb.append(fCat.getDisplayName());
            sb.append(" Findings");
        }

        Paragraph heading = new Paragraph(sb.toString());
        heading.setAlignment(Element.ALIGN_CENTER);
        document.add(heading);

        Date startDate = (Date) context.get(DATE_RANGE_START_KEY);
        Date endDate = (Date) context.get(DATE_RANGE_END_KEY);

        clearStringBuilder(sb);
        if (startDate.compareTo(endDate) == 0) {
            sb.append("On ");
            sb.append(DATE_FORMATTER.format(startDate));
        } else {
            sb.append(DATE_FORMATTER.format(startDate));
            sb.append(" - ");
            sb.append(DATE_FORMATTER.format(endDate));
        }
        Paragraph date = new Paragraph(sb.toString(), FONT);
        date.setAlignment(Element.ALIGN_RIGHT);
        document.add(date);

        PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2);
        table.setHeaderRows(1);
        table.setSpacingBefore(FONT_SIZE);
        table.setWidthPercentage(100f);
        setDefaultCellAttributes(table.getDefaultCell());

        table.addCell("");
        for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) {
            table.addCell(getHeaderCell(itr.next()));
        }
        table.addCell(getHeaderCell("Total"));
        int[] colTotals = new int[reportTable.getColumns().size() + 1];
        for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) {
            String row = rowItr.next();
            table.addCell(getHeaderCell(row));
            int total = 0;
            int idx = 0;
            for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) {
                String column = colItr.next();
                Integer value = reportTable.getTableDataItem(row, column);
                if (value == null) {
                    table.addCell(getNumberCell("0"));
                } else {
                    total += value;
                    colTotals[idx] = colTotals[idx] + value;
                    table.addCell(getNumberCell(value.toString()));
                }
                idx++;
            }
            table.addCell(getHeaderCell(Integer.toString(total)));
            colTotals[colTotals.length - 1] = colTotals[colTotals.length - 1] + total;
            idx++;
        }
        table.addCell(getHeaderCell("Total"));
        for (int i = 0; i < colTotals.length; i++) {
            table.addCell(getHeaderCell(Integer.toString(colTotals[i])));
        }

        document.add(table);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.TopFindingsReport.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor)
        throws TemplateException {
    List<Object[]> results = getResults(context);

    setFileName(context, fileDescriptor);

    Document document = new Document(PAGE_SIZE, 36, 36, 36, 36);
    try {//w  w  w .ja va 2 s.  com
        PdfWriter.getInstance(document, outputStream);
        document.open();

        StringBuilder sb = new StringBuilder((String) context.get(LICENSE_TYPE_KEY));
        sb.append(" Top Findings Report");
        Paragraph heading = new Paragraph(sb.toString(), HEADING_FONT);
        heading.setAlignment(Element.ALIGN_CENTER);
        document.add(heading);

        Date startDate = (Date) context.get(DATE_RANGE_START_KEY);
        Date endDate = (Date) context.get(DATE_RANGE_END_KEY);
        ReportType reportType = ReportType.valueOf((String) context.get(REPORT_TYPE_KEY));

        clearStringBuilder(sb);
        sb.append(DATE_FORMATTER.format(startDate));
        sb.append(" - ");
        sb.append(DATE_FORMATTER.format(endDate));

        Paragraph date = new Paragraph(sb.toString(), FONT);
        date.setAlignment(Element.ALIGN_RIGHT);
        document.add(date);

        PdfPTable table = new PdfPTable(2);
        table.setHeaderRows(1);
        table.setSpacingBefore(FONT_SIZE);
        table.setWidthPercentage(100f);
        table.setWidths(new float[] { 80f, 20f });
        setDefaultCellAttributes(table.getDefaultCell());

        table.addCell(getHeaderCell("Rule Number"));
        table.addCell(getHeaderCell(reportType.getLabel()));

        double total = 0;
        for (Iterator<Object[]> itr = results.iterator(); itr.hasNext();) {
            Object[] row = itr.next();
            Paragraph p = new Paragraph();
            p.add(new Paragraph((String) row[0], TABLE_HEADER_FONT));
            p.add(new Paragraph((String) row[1], FONT));
            table.addCell(p);
            double rowTotal = ((BigDecimal) row[2]).doubleValue();
            total += rowTotal;
            if (reportType == ReportType.CMP_AMOUNT) {
                PdfPCell cell = getCurrencyCell(CURRENCY_FORMATTER.format(rowTotal));
                table.addCell(cell);
            } else {
                table.addCell(getNumberCell(Integer.toString((int) rowTotal)));
            }
        }

        PdfPCell totCell = getHeaderCell("Total");
        totCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(totCell);

        if (reportType == ReportType.CMP_AMOUNT) {
            PdfPCell cell = getHeaderCell(CURRENCY_FORMATTER.format(total));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        } else {
            PdfPCell cell = getHeaderCell(Integer.toString((int) total));
            table.addCell(cell);
        }

        document.add(table);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

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 {//from  w  w  w. ja  v  a 2 s .c  o m
        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:GUI.Framenewventa.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {/*from w  w w.  ja v  a2 s  . com*/

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);
            ;
            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:GUI.frameNewVentaKit.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    if (jLabel17.getText().toString().equals("-")) {
        JOptionPane.showMessageDialog(rootPane, "DEBE SELECCIONAR UN CLIENTE");
    } else {/*from  w w w. jav a 2 s . com*/

        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

            funciones f = new funciones();
            String dia = (Calendar.getInstance().getTime().getDate() < 10)
                    ? "0" + Calendar.getInstance().getTime().getDate()
                    : Calendar.getInstance().getTime().getDate() + "";
            String mes = f.get_mesMay((Calendar.getInstance().getTime().getMonth() + 1));
            String anio = (Calendar.getInstance().getTime().getYear() + 1900) + "";

            String nombre = "COTIZACION TIENDA ULTIMO ROUND";
            String rut_socio = "";
            int mon = 0;
            String arch = Calendar.getInstance().getTimeInMillis() + "_" + nombre + ".pdf";
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
            Date date = new Date();
            String stringToEncrypt = nombre.trim() + dateFormat.format(date);

            int encryptedString = stringToEncrypt.trim().hashCode();
            String aRemplazar = Integer.toString(encryptedString);
            String remplazado = aRemplazar.replace("-", "");

            String url = f.getRutaCotizacion() + arch;
            FileOutputStream archivo = new FileOutputStream(url);

            int deuda = Integer.parseInt("1");

            String palabra = f.Convertir(deuda + "", false);

            palabra = palabra.substring(0, palabra.length() - 2);
            if (palabra.split(" ")[palabra.split(" ").length - 1].equals("millones")
                    | palabra.split(" ")[palabra.split(" ").length - 1].equals("milln")) {
                palabra = palabra + "de pesos";
            } else {
                palabra = palabra + "pesos";
            }

            Document documento = new Document(PageSize.LETTER);
            PdfWriter.getInstance(documento, archivo);
            documento.open();
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "headerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 400);
                documento.add(im);
            } catch (Exception e) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null, "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL ENCABEZADO.",
                        "ERROR", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }

            int linea = 0;
            Font fuente = new Font();
            fuente.setStyle(Font.UNDERLINE | Font.BOLD);
            fuente.setSize(11);
            fuente.setColor(BaseColor.BLACK);
            documento.add(new Paragraph(" "));
            Paragraph fecha = new Paragraph(dia + " de " + mes.toLowerCase() + " de " + anio + "\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            fecha.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(fecha);
            Paragraph obp = new Paragraph("ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            obp.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(obp);
            Paragraph codigo = new Paragraph("COD." + remplazado,
                    FontFactory.getFont("times new roman", 8, Font.NORMAL, BaseColor.BLACK));
            codigo.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(codigo);
            Paragraph space = new Paragraph("\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            space.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(space);
            Paragraph origen = new Paragraph("ESTIMADO CLIENTE: " + jLabel13.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen);
            Paragraph origen2 = new Paragraph("EMAIL: " + jLabel15.getText() + "\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            origen2.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(origen2);
            Paragraph a = new Paragraph(nombre,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            a.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(a);
            Paragraph rut = new Paragraph(rut_socio,
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            rut.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(rut);
            Paragraph ref = new Paragraph("REF:COTIZACION POR PRODUCTOS TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.BOLD, BaseColor.BLACK));
            ref.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(ref);

            documento.add(space);
            int numerocheque = 0;
            int montofinal = 0;
            String montostring = "";
            String detalle = "";
            String monto = jLabel22.getText();

            String montoaux = monto.replace(".", "");

            deuda = Integer.parseInt(montoaux);

            palabra = f.Convertir(deuda + "", false);
            System.out.println(palabra);
            palabra = palabra.replaceAll("0", "");
            System.out.println(palabra);
            Paragraph e = new Paragraph(
                    "Junto con saludarlo, adjunto la cotizacin detallada de los siguientes productos"
                            + " por el monto de $" + monto + ".- ( " + palabra
                            + "pesos IVA INCLUIDO) ,segn detalle:\n\n",
                    FontFactory.getFont("times new roman", 11, Font.NORMAL, BaseColor.BLACK));
            e.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(e);
            documento.add(new Paragraph(" "));
            // ACA DEBE IR LA TABLA
            //special font sizes
            Font bfBold10 = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
            //specify column widths

            //create PDF table with the given widths

            documento.add(new Paragraph(" "));
            float[] colsWidth = { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f };
            PdfPTable tabla = new PdfPTable(5);
            tabla.setWidths(colsWidth);
            String[] titulos = { "PRODUCTO", "VALOR PRODUCTO", "TIPO", "MARCA", "TALLA" };

            tabla.setWidthPercentage(100);
            PdfPCell celda;
            for (int k = 0; k < titulos.length; k++) {
                celda = new PdfPCell(new Paragraph(titulos[k],
                        FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
            }
            int var = 0;
            int w = 0;
            for (w = 0; w < jTable1.getRowCount(); w++) {
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 1).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 7).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 4).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 3).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);
                celda = new PdfPCell(new Paragraph(jTable1.getValueAt(w, 2).toString(), FontFactory
                        .getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
                celda.setHorizontalAlignment(Element.ALIGN_CENTER);
                tabla.addCell(celda);

            }
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("MONTO NETO",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph(monto,
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("IVA TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            double iva2 = Float.parseFloat(monto) * (0.19);
            iva2 = Math.round(iva2);

            celda = new PdfPCell(new Paragraph(Double.toString(iva2),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            celda = new PdfPCell(new Paragraph("",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);

            celda = new PdfPCell(new Paragraph("VALOR TOTAL",
                    FontFactory.getFont("times new roman", 10, java.awt.Font.BOLD, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            int valortotal = Integer.parseInt(monto);

            celda = new PdfPCell(new Paragraph(Integer.toString(valortotal),
                    FontFactory.getFont("times new roman", 10, java.awt.Font.ROMAN_BASELINE, BaseColor.BLACK)));
            celda.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabla.addCell(celda);
            documento.add(tabla);
            //FOOOTER
            documento.add(space);
            Paragraph despido = new Paragraph("Quedando a vuestra disposicin, saluda atentamente a Ud.,\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            despido.setAlignment(Paragraph.ALIGN_LEFT);
            documento.add(despido);
            documento.add(space);

            Paragraph firma2 = new Paragraph("TIENDA ULTIMO ROUND\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma2.setAlignment(Paragraph.ALIGN_RIGHT);
            documento.add(firma2);
            documento.add(space);
            documento.add(space);
            documento.add(space);
            Paragraph firma3 = new Paragraph("Cotizacin vlida por siete das\n",
                    FontFactory.getFont("times new roman", 10, Font.NORMAL, BaseColor.BLACK));
            firma3.setAlignment(Paragraph.ALIGN_CENTER);
            documento.add(firma3);
            documento.add(space);
            documento.add(space);
            try {
                Image im = Image.getInstance(f.getRutaCotizacion() + "footerword.png");
                im.setAlignment(Image.ALIGN_CENTER);
                im.scaleToFit(600, 500);
                documento.add(im);
            } catch (Exception ex) {
                setCursor(Cursor.getDefaultCursor());

                JOptionPane.showConfirmDialog(null,
                        "HA OCURRIDO UN ERROR AL INTENTAR AGREGAR EL PIE DE PAGINA.", "ERROR",
                        JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);

            }
            documento.close();

            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "REALIZADO CORRECTAMENTE", "INFORMACIN",
                    JOptionPane.PLAIN_MESSAGE, JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            setCursor(Cursor.getDefaultCursor());

            JOptionPane.showConfirmDialog(null, "ERROR" + ex.getMessage(), "ERROR", JOptionPane.PLAIN_MESSAGE,
                    JOptionPane.ERROR_MESSAGE);
        }

    }

}

From source file:ics4u.ics4u_final_project.Recipe.java

License:Open Source License

private void addData(Document doc) {
    //create the format for the % Daily Value
    DecimalFormat onePer = new DecimalFormat("#,##0%");
    try {/*from   w w w  .ja  v  a 2 s  .  c o m*/
        //add the title of the recipe
        doc.add(new Paragraph(title, TITLE_FONT));
        //add each of the ingredients
        for (int i = 0; i < ingredients.size(); i++) {
            doc.add(new Paragraph(ingredients.get(i).getFormattedName(), LABEL_NORMAL));
        }
        //add the instructions
        Paragraph p = new Paragraph();
        if (!instructions.equals("")) {
            p = new Paragraph(new Phrase("Instructions:\n", LABEL_FONT));
            doc.add(p);
            p = new Paragraph();
            p.add(new Phrase(instructions + "\n", LABEL_NORMAL));
        } else {
            p.add(new Phrase("\n"));
        }
        //create the nutrient value table
        PdfPTable label = new PdfPTable(10);
        label.setWidthPercentage(30);
        //Top
        PdfPCell c = new PdfPCell(new Phrase("Nutrition Facts", LABEL_FONT));
        c.setColspan(10);
        c.setBorderWidthBottom(0);
        label.addCell(c);
        c = new PdfPCell(new Phrase("Per " + servingName, LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(0);
        label.addCell(c);
        //Amount
        PdfPCell c2a = new PdfPCell(new Phrase("Amount", LABEL_SMALL));
        c2a.setColspan(3);
        c2a.setBorderWidthRight(0);
        PdfPCell c2b = new PdfPCell(new Phrase("% Daily Value", LABEL_SMALL));
        c2b.setColspan(10);
        c2b.setHorizontalAlignment(Element.ALIGN_RIGHT);
        c2b.setBorderWidthLeft(0);
        label.addCell(c2a);
        label.addCell(c2b);
        //Calories
        c = new PdfPCell(new Phrase("Calories " + (int) (nutrients[208] / servings), LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(2);
        label.addCell(c);
        //Fat
        PdfPCell ca = new PdfPCell(new Phrase("Fat " + (int) (nutrients[204] / servings) + "g", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        PdfPCell cb = new PdfPCell(new Phrase(onePer.format((nutrients[204] / servings) / 60.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //fat 2
        ca = new PdfPCell(new Phrase("Saturated " + ((int) (nutrients[606] / servings)) + "g\n\t+ Trans "
                + ((int) (nutrients[605] / servings)) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[606] / servings) / 20.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Cholesterol
        c = new PdfPCell(new Phrase("Cholesterol " + ((int) (nutrients[601] / servings)) + "mg", LABEL_BOLD));
        c.setColspan(10);
        label.addCell(c);
        //Sodium
        ca = new PdfPCell(new Phrase("Sodium " + (int) (nutrients[307] / servings) + "mg", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[307] / servings) / 2400.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Carbs
        ca = new PdfPCell(new Phrase("Carbohydrate " + (int) (nutrients[205] / servings) + "g", LABEL_BOLD));
        ca.setColspan(7);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[205] / servings) / 300.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Fibre
        ca = new PdfPCell(new Phrase("Fibre " + (int) (nutrients[291] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[291] / servings) / 25.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Sugar
        ca = new PdfPCell(new Phrase("Sugars " + (int) (nutrients[269] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(10);
        ca.setIndent(16);
        label.addCell(ca);
        //Protein
        ca = new PdfPCell(new Phrase("Protein " + (int) (nutrients[203] / servings) + "g", LABEL_BOLD));
        ca.setColspan(10);
        label.addCell(ca);
        //Vit A
        ca = new PdfPCell(new Phrase("Vitamin A", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        ca.setBorderWidthTop(2);
        cb = new PdfPCell(cb = new PdfPCell(new Phrase(
                onePer.format(
                        ((nutrients[319] + (nutrients[321] / 12) + (nutrients[834] / 24)) / servings) / 1000),
                LABEL_NORMAL)));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        cb.setBorderWidthTop(2);
        label.addCell(ca);
        label.addCell(cb);
        //Vit C
        ca = new PdfPCell(new Phrase("Vitamin C", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[401] / servings) / 60.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Calcium
        ca = new PdfPCell(new Phrase("Calcium", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[301] / servings) / 1100.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Iron
        ca = new PdfPCell(new Phrase("Iron", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[303] / servings) / 14.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Add to the table
        label.setHorizontalAlignment(Element.ALIGN_LEFT);
        p.add(label);
        //add to the document
        doc.add(p);

    } catch (DocumentException ex) {
        System.out.println("Error: " + ex.toString());
    }
}

From source file:informes.InformeActividad.java

public void generarInforme() {
    try {//from ww  w .j a v a 2  s.  c  o m
        Document document = new Document();
        Paragraph ParrafoHoja = new Paragraph();
        String parrafo = this.getDescripsion();
        String ruta = ec.getRealPath("img");
        PdfWriter.getInstance(document, new FileOutputStream(ruta + "\\" + "actividades.pdf"));

        Font fuente = new Font();
        fuente.setColor(255, 0, 0);
        fuente.setSize(30);

        Font fuente3 = new Font();
        fuente3.setColor(255, 255, 255);
        fuente3.setSize(30);

        PdfPTable tabla2 = new PdfPTable(1);
        tabla2.getDefaultCell().setBackgroundColor(BaseColor.BLUE);
        tabla2.setWidthPercentage(110f);
        tabla2.addCell(new Paragraph("UNIDAD EDUCATIVA", fuente3));
        tabla2.addCell(new Paragraph("'MISIONEROS OBLATOS'", fuente3));

        Paragraph p = new Paragraph(parrafo, fuente);

        agregarLineasEnBlanco(ParrafoHoja, 3);

        document.open();
        document.add(tabla2);
        document.add(p);
        document.add(ParrafoHoja);
        Font fuente1 = new Font();
        fuente1.setColor(0, 0, 0);
        fuente1.setSize(5);

        Font fuente2 = new Font();
        fuente2.setColor(255, 0, 0);
        fuente2.setSize(5);
        PdfPTable tabla = new PdfPTable(5);
        tabla.setWidthPercentage(107f);

        Font fuente4 = new Font();
        fuente4.setColor(0, 0, 0);
        fuente4.setSize(8);

        // Paragraph p4 = new Paragraph(parrafo, fuente4);

        //tabla.addCell(new Paragraph("OBJESTRATEGICO",fuente2));
        tabla.addCell(new Paragraph("RESPONSABLE", fuente2));
        tabla.addCell(new Paragraph("CONTROL", fuente2));
        tabla.addCell(new Paragraph("FECHA INICIO", fuente2));
        tabla.addCell(new Paragraph("FECHA FIN", fuente2));
        tabla.addCell(new Paragraph("AVANCE", fuente2));
        int cont = 0;
        tabla.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
        for (int i = 0; i < this.getItems().size(); i++) {
            // Paragraph p1 =new Paragraph(parrafo,fuente);
            String num = String.valueOf(i);
            Paragraph p4 = new Paragraph("Objetivo: " + num + " --> " + this.getItems().get(i).getNombre(),
                    fuente4);
            document.add(p4);
            Paragraph p8 = new Paragraph();
            agregarLineasEnBlanco(p8, 1);
            document.add(p8);

            for (Actividad a : this.getItems().get(i).getActividadCollection()) {
                System.out.println("");
                if (a.getIdObjetivoEstrategico()
                        .getIdObjetivoEstrategico() == (this.getItems().get(i).getIdObjetivoEstrategico())) {
                    cont = 1;
                    tabla.addCell(new Paragraph(a.getIdObjetivoEstrategico().getNombre(), fuente1));

                    tabla.addCell(new Paragraph(a.getIdPersonaResponsable().getNombre(), fuente1));
                    tabla.addCell(new Paragraph(a.getControl(), fuente1));
                    tabla.addCell(new Paragraph(a.getFechaInicio().toString(), fuente1));
                    tabla.addCell(new Paragraph(a.getFechaFin().toString(), fuente1));
                    tabla.addCell(new Paragraph(a.getAvance().toString(), fuente1));

                }
            }
            Paragraph p7 = new Paragraph();
            if (cont == 1) {
                document.add(tabla);
                cont = 0;
                agregarLineasEnBlanco(p7, 2);
                document.add(p7);
            } else {
                Font fuente5 = new Font();
                fuente5.setColor(0, 0, 255);
                fuente5.setSize(10);

                document.add(new Paragraph("No contiene actividades registradas", fuente5));
                agregarLineasEnBlanco(p7, 2);
                document.add(p7);
            }
        }

        document.add(new Paragraph(new Date().toString()));

        document.close();
        System.out.println("aquiiiiii");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformeActividad.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:informes.InformeObjEs.java

public void generarInforme() {
    try {/*from   w  ww .  j  a  v  a2s.  c  o  m*/
        Document document = new Document();
        Paragraph ParrafoHoja = new Paragraph();
        String parrafo = this.getDescripsion();
        String ruta = ec.getRealPath("img");
        PdfWriter.getInstance(document, new FileOutputStream(ruta + "\\" + "objEstra.pdf"));

        Font fuente = new Font();
        fuente.setColor(255, 0, 0);
        fuente.setSize(30);

        Font fuente3 = new Font();
        fuente3.setColor(255, 255, 255);
        fuente3.setSize(30);
        PdfPTable tabla2 = new PdfPTable(1);
        tabla2.getDefaultCell().setBackgroundColor(BaseColor.BLUE);
        tabla2.setWidthPercentage(110f);
        tabla2.addCell(new Paragraph("UNIDAD EDUCATIVA", fuente3));
        tabla2.addCell(new Paragraph("'MISIONEROS OBLATOS'", fuente3));

        Paragraph p = new Paragraph(parrafo, fuente);

        agregarLineasEnBlanco(ParrafoHoja, 3);

        document.open();
        document.add(tabla2);
        document.add(p);
        document.add(ParrafoHoja);
        Font fuente1 = new Font();
        fuente1.setColor(0, 0, 0);
        fuente1.setSize(5);

        Font fuente2 = new Font();
        fuente2.setColor(255, 0, 0);
        fuente2.setSize(5);
        PdfPTable tabla = new PdfPTable(8);
        tabla.setWidthPercentage(107f);

        tabla.addCell(new Paragraph("OBJETIVO", fuente2));
        tabla.addCell(new Paragraph("META", fuente2));
        tabla.addCell(new Paragraph("DEFINICION", fuente2));
        tabla.addCell(new Paragraph("ACLARACION", fuente2));
        tabla.addCell(new Paragraph("CONCEPTUALIZACION", fuente2));
        tabla.addCell(new Paragraph("INDICADOR", fuente2));
        tabla.addCell(new Paragraph("FORMULA", fuente2));
        tabla.addCell(new Paragraph("UNIDADES", fuente2));

        tabla.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
        for (int i = 0; i < this.getItems().size(); i++) {
            // Paragraph p1 =new Paragraph(parrafo,fuente);

            System.out.println("aquiiiiiiiiiiii" + this.getItems().get(i).getSemaforo());

            tabla.addCell(new Paragraph(this.getItems().get(i).getObjetivoestrategico().getNombre(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getMeta(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getDefinicion(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getAclaracion(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getConceptualizacion(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getIndicador().getNombre(), fuente1));
            tabla.addCell(new Paragraph(this.getItems().get(i).getIndicador().getFormula(), fuente1));
            tabla.addCell(new Paragraph(String.valueOf(this.getItems().get(i).getIndicador().getUnidades()),
                    fuente1));
        }
        document.add(tabla);
        document.add(new Paragraph(new Date().toString()));

        document.close();
        System.out.println("aquiiiiii");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(InformeObjEs.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Integral.PDF.java

/**
 * Crea una objeto de tipo tabla/*from  w  ww  .j a va 2 s  .  c om*/
 * @param columnas numero de columnas
 * @param tamanio Tamao de las columnas
 * @param porcentaje proporcion de la tabla deacuerdo a la hoja.
 * @param alineacion alineacion de la tabla respecto a la hoja
 * @return 
 */
public PdfPTable crearTabla(int columnas, float tamanio[], int porcentaje, int alineacion) {
    try {
        PdfPTable table = new PdfPTable(columnas);
        table.setWidths(tamanio);
        table.setWidthPercentage(porcentaje);
        table.setHorizontalAlignment(alineacion);
        return table;
    } catch (DocumentException e) {
        System.out.println(e);
        return null;
    }
}