Example usage for com.itextpdf.text Paragraph setAlignment

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

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

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

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

    ColumnType columnType = ColumnType.valueOf((String) context.get(COLUMN_TYPE_KEY));
    RoleType roleType = RoleType.valueOf((String) context.get(SPECIALIST_TYPE_KEY));

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

    for (Object[] res : results) {
        String column = null;/*from   ww w. j av a2 s .  c  o  m*/
        switch (columnType) {
        case LICENSE_TYPE:
            column = (String) res[3];
            break;
        case CITY:
            column = (String) res[3];
            break;
        case COUNTY:
            column = locationService.getCounty((String) res[3], (String) res[4], (String) res[5]);
            break;
        case ZIP_CODE:
            String zip = (String) res[5];
            if (zip.length() > 5) {
                zip = zip.substring(0, 5);
            }
            column = zip;
            break;
        }

        if (StringUtils.isBlank(column)) {
            column = "Unknown";
        }

        reportTable.addColumn(column);

        String specRow = null;
        String specFnm = (String) res[1];
        String specLnm = (String) res[2];
        if (StringUtils.isNotBlank(specFnm) || StringUtils.isNotBlank(specLnm)) {
            PersonalName name = new PersonalName(specFnm, specLnm);
            specRow = name.getFirstAndLastName();
        } else {
            specRow = "Unknown";
        }

        reportTable.addRow(specRow);

        Integer val = reportTable.getTableDataItem(specRow, column);
        if (val == null) {
            val = new Integer(1);
        } else {
            val = new Integer(val.intValue() + 1);
        }
        reportTable.addTableDataItem(specRow, column, val);
    }

    setFileName(context, descriptor);

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

        ColumnText text = new ColumnText(canvas.getDirectContent());
        text.setSimpleColumn(document.getPageSize().getLeft(MARGIN), document.getPageSize().getBottom(MARGIN),
                document.getPageSize().getRight(MARGIN), document.getPageSize().getTop(MARGIN));

        StringBuilder sb = new StringBuilder(roleType.getDisplayName());
        sb.append(" Caseloads");
        Paragraph heading = new Paragraph(sb.toString(), REPORT_HEADING_FONT);
        heading.setAlignment(Element.ALIGN_CENTER);
        text.addElement(heading);
        text.go();
        float yLine = text.getYLine();
        yLine -= FONT_SIZE;

        int columns = reportTable.getColumns().size() + 2;

        String[][] totTab = new String[reportTable.getRows().size()][columns];
        float maxLicWidth = 0f;
        float maxTotWidth = FONT_SIZE;
        int rowIdx = 0;
        for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) {
            String row = rowItr.next();
            totTab[rowIdx][0] = row;
            float licWidth = getTextWidth(row, FONT);
            if (licWidth > maxLicWidth) {
                maxLicWidth = licWidth;
            }

            int rowTotal = 0;
            int colIdx = 1;
            for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) {
                String col = colItr.next();
                Integer val = reportTable.getTableDataItem(row, col);
                if (val != null) {
                    totTab[rowIdx][colIdx] = val.toString();
                    rowTotal += val.intValue();
                }
                colIdx++;
            }
            String rowTotalStr = Integer.toString(rowTotal);
            float totWidth = getTextWidth(rowTotalStr, TABLE_HEADER_FONT);
            if (totWidth > maxTotWidth) {
                maxTotWidth = totWidth;
            }
            totTab[rowIdx][columns - 1] = rowTotalStr;
            rowIdx++;
        }

        //add border and cell padding to licensor width
        maxLicWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2);
        maxTotWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2);

        float width = PAGE_SIZE.getWidth() - (2 * MARGIN);
        width -= maxLicWidth;

        float[] colWidths = new float[columns];
        colWidths[0] = maxLicWidth;
        for (int i = 1; i < columns; i++) {
            colWidths[i] = maxTotWidth;
        }

        PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2);
        table.setHeaderRows(1);
        table.setLockedWidth(true);
        table.setTotalWidth(colWidths);
        table.setSpacingBefore(FONT_SIZE);
        setDefaultCellAttributes(table.getDefaultCell());

        PdfPCell cell = null;

        cell = new PdfPCell(new Phrase(""));
        cell.setBorderWidthTop(0);
        cell.setBorderWidthLeft(0);
        table.addCell(cell);
        for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) {
            cell = getRotatedHeaderCell(itr.next());
            table.addCell(cell);
        }
        cell = getRotatedHeaderCell("Total");
        table.addCell(cell);

        for (String[] row : totTab) {
            for (int i = 0; i < row.length; i++) {
                if (row[i] == null) {
                    table.addCell(getNumberCell(""));
                } else {
                    table.addCell(getCell(new Phrase(row[i], i == row.length - 1 ? TABLE_HEADER_FONT : FONT),
                            i == 0 ? Element.ALIGN_LEFT : Element.ALIGN_CENTER));
                }

            }
        }

        writeTable(table, document, canvas.getDirectContent(), colWidths, yLine, true);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

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);//from   w  ww .j  a  v a  2 s .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  ww.  java 2s  . c  om*/
        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 ww  w. jav a2 s .  co  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. j  a v a 2s .  co m

        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  ww . ja  v  a 2 s.co  m

        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.GestionProjects.java

private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
    String IMAGE1 = lblPathImage.getText();
    Font red = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.RED);
    Chunk redText = new Chunk("Les information relatif au Projet : ", red);
    Font blue = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.BLUE);

    Document document = new Document();
    java.util.Date utilStartDate = jdateDeadLine.getDate();
    java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
    try {/*from   www  .j  av  a2s. c  om*/
        PdfWriter.getInstance(document, new FileOutputStream("Report.pdf"));
        document.open();

        Paragraph p1 = new Paragraph();
        p1.add(redText);
        p1.add(txtTitreProjet.getText());

        Chunk txtdesc = new Chunk("Decription du Projet: ", red);
        Paragraph p2 = new Paragraph();
        p2.add(txtdesc);
        p2.add(txtDescriptionProjet.getText());

        Chunk txtcat = new Chunk("Catgorie du Projet: ", red);
        Paragraph p3 = new Paragraph();
        p3.add(txtcat);
        p3.add(combo_Cat.getSelectedItem().toString());

        Chunk txtfin = new Chunk("Mode de finnancement du Projet: ", red);
        Paragraph p4 = new Paragraph();
        p4.add(txtfin);
        p4.add(ComboFinnancementProjet.getSelectedItem().toString());

        Chunk txtdate = new Chunk("Date DeadLine Projet: ", red);
        Paragraph p5 = new Paragraph();
        p5.add(txtdate);
        p5.add(sqlStartDate.toString());

        p1.setSpacingAfter(25);
        p1.setSpacingBefore(25);
        p1.setAlignment(Element.ALIGN_CENTER);
        p1.setIndentationLeft(50);
        p1.setIndentationRight(50);

        document.add(p1);
        document.add(p2);
        document.add(p3);
        document.add(p4);
        document.add(p5);

        if (Desktop.isDesktopSupported()) {
            try {
                File myFile = new File("Report.pdf");
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    document.close();
    // TODO add your handling code here:
}

From source file:GUI_Apoteker.Panel_Detil_PO.java

private Paragraph getPreface(String status) {
    Paragraph preface = new Paragraph();
    Calendar cal = new GregorianCalendar();
    String tanggal = "0";
    if (cal.get(Calendar.DATE) < 0) {
        tanggal = "0" + cal.get(Calendar.DATE);
    } else {/*from   www . ja  va  2 s.  c  om*/
        tanggal = "" + cal.get(Calendar.DATE);
    }
    int bulan = (cal.get(Calendar.MONTH)) + 1;
    ;
    int tahun = cal.get(Calendar.YEAR);
    preface.setAlignment(Element.ALIGN_CENTER);

    Chunk chunk = new Chunk("Laporan Pemesanan Obat dengan ID - PO" + po.getId_Pemesanan_obat(), font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Apotek 'SI-KLINIK'", font2);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Tanggal : " + po.getTgl_Pemesanan(), font3);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Nama Supplier : " + po.getNama_supplier(), font5);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    return preface;
}

From source file:GUI_StafKlinik.Panel_Laporan_Keuangan.java

private Paragraph getPreface(String status) {
    Paragraph preface = new Paragraph();
    Calendar cal = new GregorianCalendar();
    String tanggal = "0";
    if (cal.get(Calendar.DATE) < 0) {
        tanggal = "0" + cal.get(Calendar.DATE);
    } else {//from w w  w .  j a  va 2 s.c o m
        tanggal = "" + cal.get(Calendar.DATE);
    }
    int bulan = (cal.get(Calendar.MONTH)) + 1;
    ;
    int tahun = cal.get(Calendar.YEAR);
    preface.setAlignment(Element.ALIGN_CENTER);
    Chunk chunk = new Chunk("Laporan Keuangan", font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("SI Klinik", font2);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Periode : " + tanggal1 + " s/d " + tanggal2, font3);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Diambil pada tanggal " + tanggal + "/" + bulan + "/" + tahun, font5);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    return preface;
}

From source file:GUI_StafKlinik.Panel_Penggajian.java

private Paragraph getPreface(String status) {
    lk = new Laporan_Keuangan();
    Paragraph preface = new Paragraph();
    Calendar cal = new GregorianCalendar();
    String tanggal = "0";

    if (cal.get(Calendar.DATE) < 0) {
        tanggal = "0" + cal.get(Calendar.DATE);
    } else {//  w  ww.j a v  a 2  s.co m
        tanggal = "" + cal.get(Calendar.DATE);
    }

    int bulan = (cal.get(Calendar.MONTH)) + 1;
    ;
    int tahun = cal.get(Calendar.YEAR);
    String id1 = lk.getId();
    String id2 = p.getIdPegawai();
    String id = id = id1 + id2;

    preface.setAlignment(Element.ALIGN_CENTER);
    Chunk chunk = new Chunk("Slip Gaji", font2);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("SI Klinik", font2);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Jalan Pahlawan 45 Surabaya", font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("Telepon : 031 7564231", font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    preface.add(Chunk.NEWLINE);
    preface.add(Chunk.NEWLINE);
    preface.setAlignment(Element.ALIGN_RIGHT);
    chunk = new Chunk("Tanggal " + tanggal + "/" + bulan + "/" + tahun, font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    chunk = new Chunk("No. Referensi :" + id, font1);
    preface.add(Chunk.NEWLINE);
    preface.add(chunk);
    return preface;
}