Example usage for com.itextpdf.text BaseColor LIGHT_GRAY

List of usage examples for com.itextpdf.text BaseColor LIGHT_GRAY

Introduction

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

Prototype

BaseColor LIGHT_GRAY

To view the source code for com.itextpdf.text BaseColor LIGHT_GRAY.

Click Source Link

Usage

From source file:de.jost_net.JVerein.io.MitgliedAuswertungPDF.java

License:Open Source License

@Override
public void go(ArrayList<Mitglied> list, final File file) throws ApplicationException {
    try {/*from  ww w . j  ava2s.c  o m*/
        FileOutputStream fos = new FileOutputStream(file);

        Reporter report = new Reporter(fos, adresstyp.getBezeichnungPlural(), subtitle, list.size(), 50, 10, 20,
                25);

        report.addHeaderColumn("Name", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY);
        report.addHeaderColumn("Anschrift\nKommunikation", Element.ALIGN_CENTER, 130, BaseColor.LIGHT_GRAY);
        report.addHeaderColumn("Geburts- datum", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        if (adresstyp.getJVereinid() == 1) {
            report.addHeaderColumn(
                    "Eintritt / \nAustritt / \nKndigung"
                            + (Einstellungen.getEinstellung().getSterbedatum() ? ("/\n" + "Sterbedatum") : ""),
                    Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        }
        report.addHeaderColumn(

                "Beitragsgruppe /\nEigenschaften"
                        + (Einstellungen.getEinstellung().getExterneMitgliedsnummer() ? "\nMitgliedsnummer"
                                : ""),
                Element.ALIGN_CENTER, 60, BaseColor.LIGHT_GRAY);
        report.createHeader(100, Element.ALIGN_CENTER);

        for (int i = 0; i < list.size(); i++) {
            Mitglied m = list.get(i);
            report.addColumn(Adressaufbereitung.getNameVorname(m), Element.ALIGN_LEFT);
            String anschriftkommunikation = Adressaufbereitung.getAnschrift(m);
            if (m.getTelefonprivat() != null && m.getTelefonprivat().length() > 0) {
                anschriftkommunikation += "\n" + "Tel. priv: " + m.getTelefonprivat();
            }
            if (m.getTelefondienstlich() != null && m.getTelefondienstlich().length() > 0) {
                anschriftkommunikation += "\n" + "Tel. dienstl: " + m.getTelefondienstlich();
            }
            if (m.getHandy() != null && m.getHandy().length() > 0) {
                anschriftkommunikation += "\n" + "Handy: " + m.getHandy();
            }
            if (m.getEmail() != null && m.getEmail().length() > 0) {
                anschriftkommunikation += "\n" + "EMail: " + m.getEmail();
            }
            report.addColumn(anschriftkommunikation, Element.ALIGN_LEFT);
            report.addColumn(m.getGeburtsdatum(), Element.ALIGN_LEFT);

            Date d = m.getEintritt();
            if (d.equals(Einstellungen.NODATE)) {
                d = null;
            }
            String zelle = "";
            if (d != null) {
                zelle = new JVDateFormatTTMMJJJJ().format(d);
            }

            if (m.getAustritt() != null) {
                zelle += "\n" + new JVDateFormatTTMMJJJJ().format(m.getAustritt());
            }
            if (m.getKuendigung() != null) {
                zelle += "\n" + new JVDateFormatTTMMJJJJ().format(m.getKuendigung());
            }
            if (m.getSterbetag() != null) {
                zelle += "\n" + new JVDateFormatTTMMJJJJ().format(m.getSterbetag());
            }
            if (adresstyp.getJVereinid() == 1) {
                report.addColumn(zelle, Element.ALIGN_LEFT);
            }
            StringBuilder beitragsgruppebemerkung = new StringBuilder();
            if (m.getBeitragsgruppe() != null) {
                beitragsgruppebemerkung.append(m.getBeitragsgruppe().getBezeichnung());
            }
            StringBuilder eigenschaften = new StringBuilder();
            ArrayList<String> eig = new EigenschaftenTool().getEigenschaften(m.getID());
            for (int i2 = 0; i2 < eig.size(); i2 = i2 + 2) {
                if (i2 == 0) {
                    beitragsgruppebemerkung.append("\n");
                }
                eigenschaften.append(eig.get(i2));
                eigenschaften.append(": ");
                eigenschaften.append(eig.get(i2 + 1));
                eigenschaften.append("\n");
            }

            zelle = "";
            if (Einstellungen.getEinstellung().getExterneMitgliedsnummer()) {
                zelle += (m.getExterneMitgliedsnummer() != null ? m.getExterneMitgliedsnummer() : "");
            }

            report.addColumn(beitragsgruppebemerkung.toString() + " " + eigenschaften.toString() + " " + zelle,
                    Element.ALIGN_LEFT);
        }
        report.closeTable();

        report.add(new Paragraph(String.format("Anzahl %d: %s", list.size(), adresstyp.getBezeichnungPlural()),
                Reporter.getFreeSans(8)));

        report.add(new Paragraph("Parameter", Reporter.getFreeSans(12)));

        report.addHeaderColumn("Parameter", Element.ALIGN_RIGHT, 100, BaseColor.LIGHT_GRAY);
        report.addHeaderColumn("Wert", Element.ALIGN_LEFT, 200, BaseColor.LIGHT_GRAY);
        report.createHeader(75f, Element.ALIGN_LEFT);
        for (String key : params.keySet()) {
            report.addColumn(key, Element.ALIGN_RIGHT);
            report.addColumn(params.get(key), Element.ALIGN_LEFT);
        }
        report.closeTable();
        report.close();
        GUI.getStatusBar().setSuccessText(String.format("Auswertung fertig. %d Stze.", list.size()));
    } catch (Exception e) {
        Logger.error("error while creating report", e);
        throw new ApplicationException("Fehler", e);
    }
}

From source file:de.jost_net.JVerein.io.MitgliederStatistik.java

License:Open Source License

public MitgliederStatistik(final File file, Date stichtag) throws ApplicationException {
    try {// www.  j a  v  a 2  s. c o m
        if (stichtag == null) {
            throw new ApplicationException("Stichtag ist leer");
        }
        FileOutputStream fos = new FileOutputStream(file);
        String subtitle = "";
        if (stichtag != null) {
            subtitle = "Stichtag: " + new JVDateFormatTTMMJJJJ().format(stichtag);
        }
        Reporter reporter = new Reporter(fos, "Mitgliederstatistik", subtitle, 3);

        Paragraph pAltersgruppen = new Paragraph("\n" + "Altersgruppen", Reporter.getFreeSans(11));
        reporter.add(pAltersgruppen);

        reporter.addHeaderColumn("Altersgruppe", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.createHeader(70f, Element.ALIGN_LEFT);

        AltersgruppenParser ap = new AltersgruppenParser(Einstellungen.getEinstellung().getAltersgruppen());
        while (ap.hasNext()) {
            VonBis vb = ap.getNext();
            addAltersgruppe(reporter, vb, stichtag);
        }
        addAltersgruppe(reporter, new VonBis(-1, -1), stichtag);
        addAltersgruppe(reporter, new VonBis(0, 199), stichtag);
        reporter.closeTable();

        Paragraph pBeitragsgruppen = new Paragraph("\n" + "Beitragsgruppen", Reporter.getFreeSans(11));
        reporter.add(pBeitragsgruppen);

        reporter.addHeaderColumn("Beitragsgruppe", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
        reporter.createHeader(70f, Element.ALIGN_LEFT);

        DBIterator<Beitragsgruppe> beitragsgruppen = Einstellungen.getDBService()
                .createList(Beitragsgruppe.class);
        beitragsgruppen.setOrder("order by bezeichnung");
        while (beitragsgruppen.hasNext()) {
            Beitragsgruppe bg = (Beitragsgruppe) beitragsgruppen.next();
            addBeitragsgruppe(reporter, bg, stichtag);
        }
        addBeitragsgruppe(reporter, null, stichtag);
        reporter.closeTable();

        try {
            JVDateFormatTTMMJJJJ ttmmjj = new JVDateFormatTTMMJJJJ();
            Geschaeftsjahr gj = new Geschaeftsjahr(stichtag);
            Paragraph pGuV = new Paragraph("\n" + String.format("Anmeldungen/Abmeldungen (%s - %s)",
                    ttmmjj.format(gj.getBeginnGeschaeftsjahr()), ttmmjj.format(gj.getEndeGeschaeftsjahr())),
                    Reporter.getFreeSans(11));
            reporter.add(pGuV);
            reporter.addHeaderColumn("Text", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY);
            reporter.addHeaderColumn("Anzahl", Element.ALIGN_CENTER, 30, BaseColor.LIGHT_GRAY);
            reporter.createHeader(70f, Element.ALIGN_LEFT);
            reporter.addColumn("Anmeldungen", Element.ALIGN_LEFT);
            reporter.addColumn(getAnmeldungen(gj) + "", Element.ALIGN_RIGHT);
            reporter.addColumn("Abmeldungen", Element.ALIGN_LEFT);
            reporter.addColumn(getAbmeldungen(gj) + "", Element.ALIGN_RIGHT);
            reporter.closeTable();
        } catch (ParseException e) {
            Logger.error("Fehler", e);
            throw new ApplicationException(e);
        }
        reporter.close();
        fos.close();
        FileViewer.show(file);
    } catch (Exception e) {
        Logger.error("Fehler", e);
        throw new ApplicationException("Fehler", e);
    }
}

From source file:de.jost_net.JVerein.io.MitgliedschaftsjubilaeumExportPDF.java

License:Open Source License

@Override
protected void startJahrgang(int jahrgang) throws DocumentException {
    Paragraph pHeader = new Paragraph("\n" + String.format("%d-jhriges Jubilum", jahrgang),
            Reporter.getFreeSans(11));//from   w  w  w .ja v  a2s  . c  o m
    reporter.add(pHeader);
    reporter.addHeaderColumn("Eintrittsdatum", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);

    reporter.addHeaderColumn("Name, Vorname", Element.ALIGN_CENTER, 100, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("Anschrift", Element.ALIGN_CENTER, 120, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("Kommunikation", Element.ALIGN_CENTER, 80, BaseColor.LIGHT_GRAY);
    reporter.createHeader();
    anz = 0;
}

From source file:de.jost_net.JVerein.io.StatistikJahrgaengeExportPDF.java

License:Open Source License

@Override
protected void open() throws DocumentException, FileNotFoundException {
    fos = new FileOutputStream(file);
    reporter = new Reporter(fos,
            "Statistik Jahrgnge, Stichtag: " + new JVDateFormatTTMMJJJJ().format(stichtag) + "", "", 3);
    reporter.addHeaderColumn("Jahrgang", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("Insgesamt", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("mnnlich", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("weiblich", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);
    reporter.addHeaderColumn("ohne Angabe", Element.ALIGN_CENTER, 50, BaseColor.LIGHT_GRAY);
    reporter.createHeader(50, Element.ALIGN_LEFT);
    int summegesamt = 0;
    int summemaennlich = 0;
    int summeweiblich = 0;
    int summeohne = 0;
    for (String key : statistik.keySet()) {
        reporter.addColumn(key, Element.ALIGN_CENTER);
        StatistikJahrgang dsbj = statistik.get(key);
        reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlgesamt()), Element.ALIGN_RIGHT);
        reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlmaennlich()), Element.ALIGN_RIGHT);
        reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlweiblich()), Element.ALIGN_RIGHT);
        reporter.addColumn(Einstellungen.INTFORMAT.format(dsbj.getAnzahlOhne()), Element.ALIGN_RIGHT);
        summegesamt += dsbj.getAnzahlgesamt();
        summemaennlich += dsbj.getAnzahlmaennlich();
        summeweiblich += dsbj.getAnzahlweiblich();
        summeohne += dsbj.getAnzahlOhne();
    }// w w w .j a v  a2 s  . c o m
    reporter.addColumn("Summe", Element.ALIGN_CENTER);
    reporter.addColumn(Einstellungen.INTFORMAT.format(summegesamt), Element.ALIGN_RIGHT);
    reporter.addColumn(Einstellungen.INTFORMAT.format(summemaennlich), Element.ALIGN_RIGHT);
    reporter.addColumn(Einstellungen.INTFORMAT.format(summeweiblich), Element.ALIGN_RIGHT);
    reporter.addColumn(Einstellungen.INTFORMAT.format(summeohne), Element.ALIGN_RIGHT);
    reporter.closeTable();

}

From source file:edu.harvard.mcz.precapture.encoder.LabelEncoder.java

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(ArrayList<ContainerLabel> containers) throws PrintFailedException {
    log.debug("Invoked printList ");
    boolean result = false;
    ContainerLabel label = new ContainerLabel();
    if (containers.isEmpty()) {
        log.debug("No labels to print.");
    } else {//from ww  w  .  j  a v a 2s  . c o  m
        LabelDefinitionType printDefinition = null;
        LabelDefinitionListType printDefs = PreCaptureSingleton.getInstance().getPrintFormatDefinitionList();
        List<LabelDefinitionType> printDefList = printDefs.getLabelDefinition();
        Iterator<LabelDefinitionType> il = printDefList.iterator();
        while (il.hasNext()) {
            LabelDefinitionType def = il.next();
            if (def.getTitle().equals(PreCaptureSingleton.getInstance().getProperties().getProperties()
                    .getProperty(PreCaptureProperties.KEY_SELECTED_PRINT_DEFINITION))) {
                printDefinition = def;
            }
        }
        if (printDefinition == null) {
            log.error("No selected print format defintion found.");
            //TODO change from message to error handling dialog that allows picking a print format.
            JOptionPane.showMessageDialog(null, "Unable to print.  No print format is selected.");
        } else {

            log.debug(printDefinition.getTitle());
            log.debug(printDefinition.getTextOrentation().toString());

            LabelEncoder encoder = new LabelEncoder(containers.get(0));
            try {
                Image image = encoder.getImage();
                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(PreCaptureSingleton.getInstance()
                        .getProperties().getProperties().getProperty(PreCaptureProperties.KEY_LABELPRINTFILE)));
                // Convert units in print definition to points (72 points/inch, 28.346456 points/cm)

                int paperWidthPoints = 612; // 8.5"
                int paperHeightPoints = 792; // 11"
                int marginsPoints = 36; // 0.5"
                int labelWidthPoints = 540; // 7.5" 
                int labelHeightPoints = 720; // 10"
                int numColumns = 1; // goes with above

                numColumns = printDefinition.getColumns();
                float relWidthTextCell = printDefinition.getRelWidthTextCell();
                float relWidthBarcodeCell = printDefinition.getRelWidthBarcodeCell();
                log.debug("relWidthTextCell = " + relWidthTextCell);
                log.debug("relWidthBarcodeCell = " + relWidthBarcodeCell);

                if (printDefinition.getUnits().toString().toLowerCase().equals("inches")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 72f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 72f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 72f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 72f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 72f);
                }
                if (printDefinition.getUnits().toString().toLowerCase().equals("cm")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 28.346456f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 28.346456f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 28.346456f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 28.346456f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 28.346456f);
                }
                if (printDefinition.getUnits().toString().toLowerCase().equals("points")) {
                    paperWidthPoints = (int) Math.floor(printDefinition.getPaperWidth() * 1f);
                    paperHeightPoints = (int) Math.floor(printDefinition.getPaperHeight() * 1f);
                    marginsPoints = (int) Math.floor(printDefinition.getMargins() * 1f);
                    labelWidthPoints = (int) Math.floor(printDefinition.getLabelWidth() * 1f);
                    labelHeightPoints = (int) Math.floor(printDefinition.getLabelHeight() * 1f);
                }

                if (paperWidthPoints == 612 && paperHeightPoints == 792) {
                    document.setPageSize(PageSize.LETTER);
                } else {
                    document.setPageSize(new Rectangle(paperWidthPoints, paperHeightPoints));
                }
                document.setMargins(marginsPoints, marginsPoints, marginsPoints, marginsPoints);
                document.open();

                // Sanity check
                if (paperWidthPoints <= 0) {
                    paperWidthPoints = 612;
                }
                if (paperHeightPoints <= 0) {
                    paperHeightPoints = 792;
                }
                if (marginsPoints < 0) {
                    marginsPoints = 0;
                }
                if (labelWidthPoints <= 0) {
                    labelWidthPoints = 540;
                }
                if (labelHeightPoints <= 0) {
                    labelHeightPoints = 720;
                }
                if (paperWidthPoints + (marginsPoints * 2) < labelWidthPoints) {
                    labelWidthPoints = paperWidthPoints + (marginsPoints * 2);
                    log.debug("Adjusting label width to fit printable page width");
                }
                if (paperHeightPoints + (marginsPoints * 2) < labelHeightPoints) {
                    labelHeightPoints = paperHeightPoints + (marginsPoints * 2);
                    log.debug("Adjusting label height to fit printable page height");
                }

                // calculate how many columns will fit on the paper.
                int columns = (int) Math.floor((paperWidthPoints - (marginsPoints * 2)) / labelWidthPoints);
                // if specified column count is smaller, use the specified.
                if (numColumns < columns) {
                    columns = numColumns;
                    log.debug(
                            "Fewer columns specified in definition than will fit on page, using specified column count of "
                                    + numColumns);
                }

                // define two table cells per column, one for text one for barcode.
                int subCellColumnCount = columns * 2;

                // set the table, with an absolute width and relative widths of the cells in the table;
                PdfPTable table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns,
                        subCellColumnCount, relWidthTextCell, relWidthBarcodeCell);
                // figure out the width of the cells containing the barcodes.
                float ratio = ((float) relWidthBarcodeCell)
                        / (((float) relWidthBarcodeCell) + ((float) relWidthTextCell));
                float barcodeCellWidthPoints = (float) Math.floor(labelWidthPoints * ratio);
                log.debug("Width of barcode cell in points: " + barcodeCellWidthPoints);

                //Rectangle pageSizeRectangle = new Rectangle(paperWidthPoints, paperHeightPoints);
                //table.setWidthPercentage(cellWidthsPoints, pageSizeRectangle);
                //table.setTotalWidth(cellWidthsPoints);

                // Calculate how many cells fit on a page (two cells per label).
                int labelsPerColumn = (int) Math
                        .floor((paperHeightPoints - (marginsPoints * 2)) / labelHeightPoints);
                int cellsPerPage = subCellColumnCount * labelsPerColumn;
                log.debug("Labels per column = " + labelsPerColumn);
                log.debug("Cells per page = " + cellsPerPage);

                Iterator<ContainerLabel> iterLabels = containers.iterator();

                int cellCounter = 0; // counts number of cells filled on a page.
                int counter = 0; // counts number of pre capture label data rows to print (each of which may request more than one copy).

                // TODO: Doesn't fit on page.

                while (iterLabels.hasNext()) {
                    // Loop through all of the container labels found to print 
                    label = iterLabels.next();
                    if (label != null) {
                        log.debug(label);
                        log.debug("Label: " + counter + " " + label.toString());
                        for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                            // For each container label, loop through the number of requested copies 
                            // Generate a text and a barcode cell for each, and add to array for page
                            int toPrintPlus = toPrint + 1; // for pretty counter in log.
                            log.debug("Copy " + toPrintPlus + " of " + label.getNumberToPrint());

                            PdfPCell cell = label.toPDFCell(printDefinition);
                            cell.setFixedHeight(labelHeightPoints);
                            // Colors to illustrate where the cells are on the layout
                            if (PreCaptureSingleton.getInstance().getProperties().getProperties()
                                    .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) {
                                cell.setBackgroundColor(new BaseColor(255, 255, 30));
                            }

                            PdfPCell cell_barcode = new PdfPCell();
                            cell_barcode.setBorderColor(BaseColor.LIGHT_GRAY);
                            cell_barcode.disableBorderSide(PdfPCell.LEFT);
                            cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                            cell_barcode.setHorizontalAlignment(Element.ALIGN_RIGHT);
                            cell_barcode.setFixedHeight(labelHeightPoints);
                            if (PreCaptureSingleton.getInstance().getProperties().getProperties()
                                    .getProperty(PreCaptureProperties.KEY_DEBUGLABEL).equals("true")) {
                                cell_barcode.setBackgroundColor(new BaseColor(255, 30, 255));
                            }

                            encoder = new LabelEncoder(label);
                            image = encoder.getImage();
                            image.setAlignment(Image.ALIGN_TOP);
                            //image.setAlignment(Image.ALIGN_LEFT);
                            image.setAlignment(Image.ALIGN_RIGHT);
                            image.scaleToFit(barcodeCellWidthPoints, labelHeightPoints);
                            cell_barcode.addElement(image);

                            table.addCell(cell);
                            table.addCell(cell_barcode);

                            cellCounter = cellCounter + 2; // we've added two cells to the page (two cells per label).
                            log.debug("Cells " + cellCounter + " of " + cellsPerPage + " cells per page.");

                            // If we have hit a full set of labels for the page, add them to the document
                            // in each column, filling left to right
                            if (cellCounter >= cellsPerPage - 1) {
                                log.debug("Page is full");
                                log.debug("Table has " + table.getNumberOfColumns() + " columns and "
                                        + table.getRows().size() + " rows ");
                                // Reset to begin next page
                                cellCounter = 0;
                                table.setLockedWidth(true);
                                document.add(table);
                                log.debug("Adding new page");
                                document.newPage();
                                table = setupTable(paperWidthPoints, marginsPoints, labelWidthPoints, columns,
                                        subCellColumnCount, relWidthTextCell, relWidthBarcodeCell);
                                log.debug("Setup new table");
                            }
                        } // end loop through toPrint (for a taxon/precapture label data row)
                        counter++; // Increment number of pre capture label data rows.
                    } // end if not null label
                } // end while results has next (for all taxa requested)
                  // get any remaining cells in pairs
                if (cellCounter > 0) {
                    log.debug("Adding remaining cells in partial page");
                    if (cellCounter <= cellsPerPage) {
                        for (int i = cellCounter; i <= cellsPerPage; i++) {
                            PdfPCell emptyCell = new PdfPCell();
                            emptyCell.setBorder(PdfPCell.NO_BORDER);
                            table.addCell(emptyCell);
                        }
                    }
                    log.debug("Table has " + table.getNumberOfColumns() + " columns and "
                            + table.getRows().size() + " rows ");
                    table.setLockedWidth(true);
                    document.add(table);
                }
                document.close();

                // send to printer
                PrintingUtility.sendPDFToPrinter(printDefinition, paperWidthPoints, paperHeightPoints);

                // Check to see if there was content in the document.
                if (counter == 0) {
                    result = false;
                } else {
                    // Printed to pdf ok.
                    result = true;
                }
            } catch (FileNotFoundException e) {
                log.debug(e.getMessage(), e);
                throw new PrintFailedException("File not found.");
            } catch (DocumentException e) {
                log.error(e.getMessage(), e);
                throw new PrintFailedException("Error building/printing PDF document. " + e.getMessage());
            } catch (OutOfMemoryError e) {
                System.out.println("Out of memory error. " + e.getMessage());
                System.out.println("Failed.  Too many labels.");
                throw new PrintFailedException("Ran out of memory, too many labels at once.");
            } catch (BarcodeCreationException e) {
                System.out.println("BarcodeCreationException. " + e.getMessage());
                System.out.println("Failed.  Couldn't create barcode.");
                throw new PrintFailedException(
                        "Unable to create barcode.  Probably too many characters to encode. " + e.getMessage());
            }
        }
        log.debug("printList Done. Success = " + result);
    }
    return result;
}

From source file:edu.harvard.mcz.precapture.ui.ContainerLabel.java

License:Open Source License

/**
 * // w  w w .  j  a  va  2  s.  c  om
 * @return a PDF paragraph cell containing a text encoding of the fields in this set.
 */
public PdfPCell toPDFCell(LabelDefinitionType printDefinition) {
    PdfPCell cell = new PdfPCell();
    ;
    if (printDefinition.getTextOrentation().toString().toLowerCase()
            .equals(TextOrentationType.VERTICAL.toString().toLowerCase())) {
        log.debug("Print orientation of text is Vertical");
        cell.setRotation(90);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    }
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.setPaddingLeft(3);
    cell.setNoWrap(false);

    int leading = (int) (fields.get(0).getField().getFontSize() + printDefinition.getFontDelta()) - 1;
    Paragraph higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN,
            fields.get(0).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
    higher.setSpacingBefore(0);
    higher.setSpacingAfter(0);
    boolean added = false;
    boolean hasContent = false;
    for (int i = 0; i < fields.size(); i++) {
        log.debug(i);
        if (fields.get(i).getField().isNewLine() || (i == fields.size() - 1)) {
            if (!higher.isEmpty()) {
                log.debug(higher.getContent());
                cell.addElement(higher);
            }
            leading = (int) (fields.get(i).getField().getFontSize() + printDefinition.getFontDelta()) - 1;
            higher = new Paragraph(leading, "", new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
            higher.setSpacingBefore(0);
            higher.setSpacingAfter(0);
            added = false;
            hasContent = false;
        }
        log.debug(fields.get(i).getTextField().getText().trim());
        Chunk chunk = new Chunk(fields.get(i).getTextField().getText().trim());
        if (fields.get(i).getField().isUseItalic()) {
            chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.ITALIC));
        } else {
            chunk.setFont(new Font(Font.FontFamily.TIMES_ROMAN,
                    fields.get(i).getField().getFontSize() + printDefinition.getFontDelta(), Font.NORMAL));
        }
        if (!chunk.isEmpty()) {
            hasContent = true;
            higher.add(chunk);
            log.debug(fields.get(i).getField().getSuffix());
            if (fields.get(i).getField().getSuffix() != null
                    && fields.get(i).getField().getSuffix().length() > 0) {
                higher.add(new Chunk(fields.get(i).getField().getSuffix()));
            }
            if (fields.get(i).getTextField().getText().trim().length() > 0) {
                // add a trailing space as a separator if there was something to separate.
                higher.add(new Chunk(" "));
            }
        }
    }
    if (!added) {
        log.debug(higher.getContent());
        cell.addElement(higher);
    }
    String extraText = PreCaptureSingleton.getInstance().getProperties().getProperties()
            .getProperty(PreCaptureProperties.KEY_EXTRAHUMANTEXT);
    if (extraText != null && extraText.length() > 0) {
        log.debug(extraText);
        cell.addElement(new Chunk(extraText));
    }

    return cell;
}

From source file:es.clinica.veterinaria.albaranes.AlbaranPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(5);
    table.setTotalWidth(new float[] { 55, 150, 200, 70, 70 });
    table.setLockedWidth(true);//  w  w w. j a v  a 2 s  . c om

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<VentaLinea> listVenta = getVenta().getVenta_lineas();

    for (VentaLinea vlinea : listVenta) {
        if (vlinea.getTipo() == 1) {
            if (vlinea.getProducto().getIva() != null) {
                iva2 = vlinea.getProducto().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        } else if (vlinea.getTipo() == 2) {
            if (vlinea.getServicio().getIva() != null) {
                iva2 = vlinea.getServicio().getIva().getValor();
                //                    System.out.println("IVA: " +iva2);
            }
        }

        //Para hacer el calculo nos vamos a quedar con el IVA mayor
        if (iva < iva2) {
            iva = iva2;
        }

        cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

        String descripcion = vlinea.getDescripcion();
        if (descripcion == null || "null".equals(descripcion)) {
            table.addCell(new PdfPCell(new Phrase(" ", small)));
            //                System.out.println("null:" + descripcion);
        } else {
            table.addCell(new PdfPCell(new Phrase(descripcion, small)));
            //                System.out.println("!null:" + descripcion);
        }

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCostesinIva()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    //        float costetotal = (float) (venta.getCoste() * (1+(iva*0.01)));

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getIvas()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(venta.getCoste()) + " "));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:es.clinica.veterinaria.facturas.FacturaPdf.java

public PdfPTable createTable() throws DocumentException {
    // a table with three columns
    int iva = 0, iva2 = 0;
    DecimalFormat df = new DecimalFormat("0.00");
    PdfPTable table = new PdfPTable(6);
    table.setTotalWidth(new float[] { 50, 65, 150, 150, 65, 70 });
    table.setLockedWidth(true);//from  w ww .j a va 2s.c o m

    // the cell object
    // we add a cell with colspan 3
    PdfPCell cell = new PdfPCell(new Phrase("CANT."));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("FECHA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CONCEPTO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DESCRIPCIN"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("IMPORTE"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingTop(5);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    HashSet<Venta> ventas = this.getFactura().getVentas();
    for (Venta venta : ventas) {
        HashSet<VentaLinea> listVenta = venta.getVenta_lineas();

        for (VentaLinea vlinea : listVenta) {
            if (vlinea.getTipo() == 1) {
                if (vlinea.getProducto().getIva() != null) {
                    iva2 = vlinea.getProducto().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            } else if (vlinea.getTipo() == 2) {
                if (vlinea.getServicio().getIva() != null) {
                    iva2 = vlinea.getServicio().getIva().getValor();
                    //                    System.out.println("IVA: " +iva2);
                }
            }

            //Para hacer el calculo nos vamos a quedar con el IVA mayor
            if (iva < iva2) {
                iva = iva2;
            }

            cell = new PdfPCell(new Phrase(vlinea.getCantidad() + "", small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(
                    new Phrase(new SimpleDateFormat("dd-MM-yyyy").format(vlinea.getFecha()), small));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            if (vlinea.getTipo() == 2) { //Servicio
                table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                String descripcion = vlinea.getDescripcion();
                if (descripcion == null || "null".equals(descripcion)) {
                    table.addCell(new PdfPCell(new Phrase(" ", small)));
                    //                System.out.println("null:" + descripcion);
                } else {
                    table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                    //                System.out.println("!null:" + descripcion);
                }
            } else if (vlinea.getTipo() == 1) { //Producto
                //Si el producto es Tratamiento
                if (vlinea.getProducto().getFamilia().isTratamiento()) {
                    table.addCell(new PdfPCell(new Phrase("Tratamiento", small)));
                    table.addCell(new PdfPCell(new Phrase("", small)));
                } else {

                    table.addCell(new PdfPCell(new Phrase(vlinea.getNombre(), small)));

                    String descripcion = vlinea.getDescripcion();
                    if (descripcion == null || "null".equals(descripcion)) {
                        table.addCell(new PdfPCell(new Phrase(" ", small)));
                        //                System.out.println("null:" + descripcion);
                    } else {
                        table.addCell(new PdfPCell(new Phrase(descripcion, small)));
                        //                System.out.println("!null:" + descripcion);
                    }
                }
            }
            cell = new PdfPCell(new Phrase(df.format(vlinea.getPvp()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);

            cell = new PdfPCell(new Phrase(df.format(vlinea.getPreciototalNoIVA()) + " ", small));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            cell.setPaddingBottom(5);
            table.addCell(cell);
        }
    }

    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUMA"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getCoste()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* IVA */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    float costetotal = (float) (factura.getCostetotal());

    cell = new PdfPCell(new Phrase("IVA " + iva + "%"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(factura.getIvas()) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    /* COSTE TOTAL */
    cell = new PdfPCell(new Phrase(" "));
    cell.setColspan(1);
    cell.setBorderWidthBottom(0);
    cell.setBorderWidthLeft(0);
    cell.setBorder(0);
    cell.setBorderColorLeft(BaseColor.WHITE);
    cell.setBorderColorBottom(BaseColor.WHITE);
    cell.setPaddingBottom(5);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("TOTAL"));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(df.format(costetotal) + " ", smallBold));
    cell.setColspan(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}

From source file:ExternalNonFormClasses.PDFEnator.java

public PdfPTable writeHeaders(Font font) {
    PdfPTable pdftable = new PdfPTable(setTableDimensions());
    pdftable.setTotalWidth(480);/* w  w w . j a  v  a2s . c  om*/
    for (int a = 0; a < this.tableHeaderData.size(); a++) {
        System.out.println("Header #" + a);
        PdfPCell cell1 = new PdfPCell(new Paragraph(this.tableHeaderData.get(a), font));
        cell1.setPaddingBottom(5);
        cell1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        pdftable.addCell(cell1);
    }
    return pdftable;
}

From source file:ManagementPackage.ServiceEnd.java

private void txtDoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoneActionPerformed
    // TODO add your handling code here:
    Document doc = new Document();
    try {//from w w  w .  j ava2  s.c o m
        long time = new Date().getTime();
        TransNo = "" + time;
        PdfWriter.getInstance(doc, new FileOutputStream("Invoices\\Invoices" + time + ".pdf"));
        doc.open();

        PdfPTable table = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Shop Management System \n\n",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 20, Font.BOLD, BaseColor.WHITE)));
        cell1.setColspan(10);
        cell1.setPadding(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setBackgroundColor(BaseColor.BLACK);
        table.addCell(cell1);

        PdfPCell cell21 = new PdfPCell(new Paragraph("\n\n"));
        cell21.setColspan(10);
        cell21.setBorder(2);
        cell21.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell21);

        PdfPCell cell2 = new PdfPCell(new Paragraph("Invoice/Money Receipt\n"));
        cell2.setColspan(10);
        cell2.setPadding(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell2);

        PdfPCell cell3 = new PdfPCell(new Paragraph("Transaction No: " + time, FontFactory.getFont(null, 10)));
        cell3.setColspan(2);
        cell3.setPaddingBottom(10);
        cell3.setPaddingTop(10);
        cell3.setBorder(2);
        cell3.setBorderColorLeft(BaseColor.WHITE);
        table.addCell(cell3);

        PdfPCell cell4 = new PdfPCell(
                new Paragraph("Date: " + formatedDateTime, FontFactory.getFont(null, 10)));
        cell4.setColspan(3);
        cell4.setPaddingBottom(10);
        cell4.setPaddingTop(10);
        cell4.setBorder(2);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell4.setBorderColorRight(BaseColor.WHITE);
        table.addCell(cell4);

        //table.addCell("Sl No");
        table.addCell("Product Name");
        table.addCell("Rate");
        table.addCell("Qty");
        table.addCell("Amount (TK)");

        String query = "select product_name, rate, qty, amount from temp_trans WHERE trans_by = '" + user + "'";
        try {
            pst = con.prepareStatement(query);
            rs = pst.executeQuery();
            while (rs.next()) {
                //String sl_no = rs.getString("sl_no");
                String product_name = rs.getString("product_name");
                String rate = rs.getString("rate");
                String qty = rs.getString("qty");
                String amount = rs.getString("amount");

                //table.addCell(sl_no);
                table.addCell(product_name);
                table.addCell(rate);
                table.addCell(qty);

                PdfPCell cellAmount = new PdfPCell(new Paragraph(amount));
                cellAmount.setHorizontalAlignment(Element.ALIGN_RIGHT);
                table.addCell(cellAmount);
            }
            rs.close();
            pst.close();

        } catch (SQLException ex) {
            Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfPCell cellb = new PdfPCell(new Paragraph(" "));
        cellb.setColspan(10);
        cellb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cellb);

        //
        PdfPCell celltxtTotal = new PdfPCell(new Paragraph("Total"));
        celltxtTotal.setColspan(3);
        celltxtTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal);

        PdfPCell celltxtTotal1 = new PdfPCell(new Paragraph(txtTotal.getText()));
        celltxtTotal1.setColspan(2);
        celltxtTotal1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotal1);

        PdfPCell celltxtAdjust = new PdfPCell(new Paragraph("Adjustment"));
        celltxtAdjust.setColspan(3);
        celltxtAdjust.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust);

        PdfPCell celltxtAdjust1 = new PdfPCell(new Paragraph(txtAdjust.getText()));
        celltxtAdjust1.setColspan(2);
        celltxtAdjust1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtAdjust1);

        PdfPCell celltxtTotalPaid = new PdfPCell(new Paragraph("Billed By: " + user));
        celltxtTotalPaid.setColspan(2);
        //celltxtTotalPaid.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid);

        PdfPCell celltxtTotalPaid0 = new PdfPCell(new Paragraph("Total Paid"));
        celltxtTotalPaid0.setColspan(1);
        celltxtTotalPaid0.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid0);

        PdfPCell celltxtTotalPaid1 = new PdfPCell(new Paragraph(txtTotalPaid.getText()));
        celltxtTotalPaid1.setColspan(2);
        celltxtTotalPaid1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(celltxtTotalPaid1);

        doc.add(table);

        doc.close();

        savePermanently();
        clearTempTable();
        //JOptionPane.showMessageDialog(null, "Report Created!");

        // open PDF file
        File file = new File("Invoices\\Invoices" + time + ".pdf");
        if (file.toString().endsWith(".pdf"))
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
        else {
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        }

    } catch (DocumentException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ServiceEnd.class.getName()).log(Level.SEVERE, null, ex);
    }
}