Search in sources :

Example 1 with Phrase

use of com.lowagie.text.Phrase in project adempiere by adempiere.

the class SmjPdfReport method reportTable.

// generar
/**
	 * coloca la tabla en el reporte ** Put table in report
	 */
public void reportTable() {
    PdfPCell tableCell;
    Iterator<ReportTO> itRep = data.iterator();
    while (itRep.hasNext()) {
        ReportTO rpt = itRep.next();
        if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("T")) {
            // Coloca titulo - put title
            PdfPCell title = new PdfPCell(new Paragraph(dataNull(rpt.getDescription()), titleTableFont));
            title.setColspan(cols);
            title.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
            title.setBorder(0);
            table.addCell(title);
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("L")) {
            // coloca linea en el reporte - Put under line in the report
            PdfPCell line = new PdfPCell(new Paragraph("", subFont));
            line.setColspan(cols);
            line.setBorderWidthLeft(0);
            line.setBorderWidthRight(0);
            line.setBorderWidthTop(0);
            line.setBorderColorBottom(Color.BLACK);
            table.addCell(line);
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("X")) {
            // coloca linea de total - Put total line
            simpleLine();
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("Z")) {
            // coloca linea doble de total - Put total line doble
            for (int j = 0; j < 2; j++) {
                simpleLine();
            }
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("D")) {
            // coloca liena de descripcion - put description line
            tableCell = new PdfPCell(new Phrase(""));
            tableCell.setBorder(0);
            table.addCell(tableCell);
            tableCell = new PdfPCell(new Phrase(""));
            tableCell.setBorderWidthLeft(0);
            tableCell.setBorderWidthRight(0);
            tableCell.setBorderWidthTop(0);
            tableCell.setBorderColorBottom(Color.BLACK);
            table.addCell(tableCell);
            for (int i = 0; i < (cols - 2); i++) {
                tableCell = new PdfPCell(new Phrase(""));
                tableCell.setBorder(0);
                table.addCell(tableCell);
            }
        // for
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("S")) {
            // coloca linea en blanco - put empty line
            PdfPCell line = new PdfPCell(new Paragraph("         "));
            line.setColspan(cols);
            line.setBorder(0);
            table.addCell(line);
        } else if (rpt.getTablevel() != null && rpt.getTablevel() > 0) {
            // coloca espacios a la izquierda para simular jeraquia - put
            // left spaces to simulate hierarchy
            String jerarchy = "";
            for (int i = 1; i <= rpt.getTablevel(); i++) {
                jerarchy = jerarchy + "   ";
            }
            PdfPCell line = new PdfPCell(new Paragraph(jerarchy + dataNull(rpt.getDescription()), catFont));
            line.setColspan(cols);
            line.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
            line.setBorder(0);
            table.addCell(line);
        } else {
            if (rpt.getDescription() != null) {
                // nombre - name
                tableCell = new PdfPCell(new Phrase(dataNull(rpt.getName()), subFont));
                tableCell.setBorder(0);
                tableCell.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
                table.addCell(tableCell);
                // descripcion - description
                tableCell = new PdfPCell(new Phrase(dataNull(rpt.getDescription()), subFont));
                tableCell.setBorder(0);
                table.addCell(tableCell);
                // columnas 0 a 20 - cols 0 to 20
                if (cols >= 3) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_0()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 4) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_1()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 5) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_2()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 6) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_3()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 7) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_4()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 8) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_5()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 9) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_6()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 10) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_7()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 11) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_8()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 12) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_9()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 13) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_10()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 14) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_11()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 15) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_12()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 16) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_13()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 17) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_14()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 18) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_15()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 19) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_16()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 20) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_17()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 21) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_18()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 22) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_19()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
                if (cols >= 23) {
                    tableCell = new PdfPCell(new Phrase(formatValue(rpt.getCol_20()), subFont));
                    tableCell.setBorder(0);
                    tableCell.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
                    table.addCell(tableCell);
                }
            }
        // if description NO null
        }
    // final else
    }
// while
}
Also used : PdfPCell(com.lowagie.text.pdf.PdfPCell) ReportTO(org.compiere.model.ReportTO) Phrase(com.lowagie.text.Phrase) Paragraph(com.lowagie.text.Paragraph)

Example 2 with Phrase

use of com.lowagie.text.Phrase in project vcell by virtualcell.

the class RTFWriter method writeHeaderFooter.

protected void writeHeaderFooter(String headerStr) throws DocumentException {
    if (headerStr.trim().length() > 0) {
        HeaderFooter headerFooter = new HeaderFooter(new Phrase(headerStr), false);
        document.setHeader(headerFooter);
    }
    HeaderFooter headerFooter = new HeaderFooter(new Phrase("Page "), true);
    document.setFooter(headerFooter);
}
Also used : HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase)

Example 3 with Phrase

use of com.lowagie.text.Phrase in project drools by kiegroup.

the class EndPage method newHeaderCell.

private static Cell newHeaderCell(String text, Font font) throws BadElementException {
    Cell c = new Cell(new Phrase(text, font));
    c.setBackgroundColor(Color.decode("#CCCCFF"));
    c.setLeading(10);
    c.setBorder(1);
    return c;
}
Also used : Phrase(com.lowagie.text.Phrase) Cell(com.lowagie.text.Cell) PdfPCell(com.lowagie.text.pdf.PdfPCell)

Example 4 with Phrase

use of com.lowagie.text.Phrase in project drools by kiegroup.

the class EndPage method createFooter.

public static HeaderFooter createFooter(String packageName) {
    HeaderFooter footer = new HeaderFooter(new Phrase(packageName + "-", HEADER_FOOTER_TEXT), true);
    footer.setBorder(1);
    footer.setAlignment(Element.ALIGN_RIGHT);
    return footer;
}
Also used : HeaderFooter(com.lowagie.text.HeaderFooter) Phrase(com.lowagie.text.Phrase)

Example 5 with Phrase

use of com.lowagie.text.Phrase in project jaffa-framework by jaffa-projects.

the class FormPrintEngineIText method fillPageFields.

/**
 * This will fill in the page with data,
 * m_currentPageData contains the details of the current page being printed
 * @throws FormPrintException Thrown if there is any form processing problems
 */
protected void fillPageFields() throws FormPrintException {
    log.debug("fillPageFields: Page=" + getCurrentPage());
    try {
        PdfContentByte cb = m_writer.getDirectContent();
        PageDetailsExtended page = (PageDetailsExtended) getCurrentPageData();
        // Loop through each field to be inserted
        for (Iterator i = page.fieldList.iterator(); i.hasNext(); ) {
            String fieldname = (String) i.next();
            // Get the properties for displaying this field
            FieldProperties props = (FieldProperties) page.fieldProperties.get(fieldname);
            // Get the data to display
            FormPrintEngine.DomValue data = new FormPrintEngine.DomValue(fieldname, props.sampleData);
            // Caluclate Clipping Region
            float x1 = Math.min(props.x1, props.x2);
            float x2 = Math.max(props.x1, props.x2);
            float y1 = Math.min(props.y1, props.y2);
            float y2 = Math.max(props.y1, props.y2);
            float w = Math.abs(props.x1 - props.x2) + 1;
            float h = Math.abs(props.y1 - props.y2) + 1;
            if (log.isDebugEnabled())
                log.debug("Print Field " + fieldname + "=" + data.getObject() + " @ [(" + x1 + "," + y1 + ")->(" + x2 + "," + y2 + ")]");
            // Default the font if not specified
            String font = BaseFont.HELVETICA;
            if (props.fontFace != null)
                font = props.fontFace;
            // Handle Barcodes diffently withing iText, don't just use fonts
            if (font.startsWith("Barcode")) {
                String bcClassName = "com.lowagie.text.pdf." + font;
                Object bcode = null;
                String dataStr = data.getValue();
                if (dataStr != null) {
                    log.debug("Barcode Data String = " + dataStr);
                    // Try and create the correct Barcode Object
                    try {
                        Class bcClass = Class.forName(bcClassName);
                        bcode = bcClass.newInstance();
                    } catch (Exception e) {
                        String err = "Can't Create Barcode Object for barcode type '" + font + "' on field " + fieldname;
                        log.error(err, e);
                    }
                    // Only continue if the barcode object was created
                    if (bcode != null) {
                        // Generate and Print barcode, based on common interface
                        if (bcode instanceof Barcode) {
                            Barcode b = (Barcode) bcode;
                            // Set some default output a barcode
                            b.setCode(dataStr);
                            if (props.fontSize <= 0) {
                                // Hide text if font size is 0, and make the barcode height the size of the box
                                b.setBarHeight(h);
                                b.setFont(null);
                            } else {
                                // size of text under barcode
                                b.setSize(props.fontSize);
                                // Adjust Bar Height to allow for font size
                                b.setBarHeight(h - props.fontSize - 5);
                            }
                            // Wide Bars
                            b.setN(2);
                            // Set custom parameters
                            setBarcodeParams(fieldname, bcode, props.style);
                            // Print out barcode
                            Image image = ((Barcode) bcode).createImageWithBarcode(cb, null, null);
                            printImage(image, cb, x1, y1, x2, y2, props.align, props.fitMethod, props.rotate);
                        } else // Print PDF417 barcode, not based on common interface
                        if (bcode instanceof BarcodePDF417) {
                            BarcodePDF417 b = (BarcodePDF417) bcode;
                            // Set some default output a barcode
                            b.setText(dataStr);
                            b.setErrorLevel(5);
                            // Set custom parameters
                            setBarcodeParams(fieldname, bcode, props.style);
                            log.debug("PDF417 Settings\n" + "BitColumns=" + b.getBitColumns() + "\n" + "CodeColumns=" + b.getCodeColumns() + "\n" + "CodeRows=" + b.getCodeRows() + "\n" + "ErrorLevel=" + b.getErrorLevel() + "\n" + "YHeight=" + b.getYHeight() + "\n" + "AspectRatio=" + b.getAspectRatio() + "\n" + "Options=" + b.getOptions() + "\n" + "LenCodewords=" + b.getLenCodewords());
                            // Print out barcode
                            // image = b.getImage();
                            printImage(b.getImage(), cb, x1, y1, x2, y2, props.align, props.fitMethod, props.rotate);
                        } else {
                            // Error, unknown barcode
                            String err = "Error, No print handler for barcode object " + bcode.getClass().getName();
                            log.error(err);
                        // throw new EngineProcessingException(err);
                        }
                    }
                } else
                    log.debug("SKIPPED BARCODE : No data for " + fieldname);
            // Handle Images differently within iText, native support for JFreeChart
            } else if ("image".equalsIgnoreCase(font)) {
                try {
                    java.awt.Image image = data.getDomImage();
                    // Add an image to the page
                    if (image != null) {
                        if (fieldname.startsWith("watermark")) {
                            // Add an image-based watermark to the under content layer
                            PdfContentByte contentUnder = m_writer.getDirectContentUnder();
                            if (props.opacity != 1f) {
                                PdfGState gs = new PdfGState();
                                gs.setFillOpacity(props.opacity);
                                contentUnder.setGState(gs);
                            }
                            printImage(image, contentUnder, x1, y1, x2, y2, props.align, props.fitMethod, props.rotate);
                        } else {
                            // Add an image to main page layer
                            printImage(image, cb, x1, y1, x2, y2, props.align, props.fitMethod, props.rotate);
                        }
                    }
                } catch (IOException e) {
                    // Add Error on page.
                    Phrase text = new Phrase("Image Error", FontFactory.getFont(FontFactory.HELVETICA_BOLDOBLIQUE, 8f, 0, ColorHelper.getColor("red")));
                    ColumnText ct = new ColumnText(cb);
                    ct.setSimpleColumn(text, x1, y1, x2, y2, 8f, Element.ALIGN_LEFT);
                }
            } else if (fieldname.startsWith("watermark")) {
                // Add a text-based watermark
                String text = data.getValue();
                PdfContentByte contentUnder = m_writer.getDirectContentUnder();
                if (props.opacity != 1f) {
                    PdfGState gs = new PdfGState();
                    gs.setFillOpacity(props.opacity);
                    contentUnder.setGState(gs);
                }
                // The text aligns (left, center, right) on the pivot point.
                // Default to align left.
                float pivotX = x1;
                float pivotY = y1;
                if (Element.ALIGN_CENTER == props.align) {
                    pivotX = (x1 / 2) + (x2 / 2);
                    pivotY = y1;
                } else if (Element.ALIGN_RIGHT == props.align) {
                    pivotX = x2;
                    pivotY = y1;
                }
                Phrase watermark = new Phrase(text, FontFactory.getFont(props.fontFace, props.fontSize, decodeFontStyle(props.style), ColorHelper.getColor(defaultWatermarkColor)));
                ColumnText.showTextAligned(contentUnder, props.align, watermark, pivotX, pivotY, props.rotate);
            } else {
                // Handle printing of basic Text
                float lineHeight = props.fontSize;
                String str = data.getValue();
                if (str != null) {
                    // Add a bounded column to add text to.
                    Phrase text = new Phrase(str, FontFactory.getFont(props.fontFace, props.fontSize, decodeFontStyle(props.style), ColorHelper.getColor(props.color)));
                    ColumnText ct = new ColumnText(cb);
                    if (props.fitMethod == FIT_METHOD_CLIP)
                        // set up column with height/width restrictions
                        ct.setSimpleColumn(text, x1, y1, x2, y2, lineHeight, props.align);
                    else
                        // set up column without (i.e. large) height/width restrictions
                        ct.setSimpleColumn(text, x1, y1, 1000, 0, lineHeight, props.align);
                    ct.go();
                }
            }
            // Draw outline boxes arround fields
            if (isTemplateMode()) {
                cb.setLineWidth(0.5f);
                cb.setLineDash(4f, 2f);
                cb.setColorStroke(new Color(0xA0, 0xA0, 0xA0));
                cb.moveTo(x1, y1);
                cb.lineTo(x1, y2);
                cb.lineTo(x2, y2);
                cb.lineTo(x2, y1);
                cb.lineTo(x1, y1);
                cb.stroke();
            }
        }
    // end for-loop
    } catch (DocumentException e) {
        String err = "Error printing data - " + e.getMessage();
        log.error(err, e);
        throw new EngineProcessingException(err);
    // } catch (IOException e) {
    // String err = "Error printing data - " + e.getMessage();
    // log.error(err ,e);
    // throw new EngineProcessingException(err);
    }
}
Also used : BarcodePDF417(com.lowagie.text.pdf.BarcodePDF417) Color(java.awt.Color) IOException(java.io.IOException) Phrase(com.lowagie.text.Phrase) Image(com.lowagie.text.Image) BadElementException(com.lowagie.text.BadElementException) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException) IOException(java.io.IOException) DocumentException(com.lowagie.text.DocumentException) FileNotFoundException(java.io.FileNotFoundException) FormPrintException(org.jaffa.modules.printing.services.exceptions.FormPrintException) EngineProcessingException(org.jaffa.modules.printing.services.exceptions.EngineProcessingException) ColumnText(com.lowagie.text.pdf.ColumnText) Barcode(com.lowagie.text.pdf.Barcode) DocumentException(com.lowagie.text.DocumentException) Iterator(java.util.Iterator) PdfContentByte(com.lowagie.text.pdf.PdfContentByte) PdfGState(com.lowagie.text.pdf.PdfGState)

Aggregations

Phrase (com.lowagie.text.Phrase)20 DocumentException (com.lowagie.text.DocumentException)8 HeaderFooter (com.lowagie.text.HeaderFooter)7 Paragraph (com.lowagie.text.Paragraph)7 PdfPCell (com.lowagie.text.pdf.PdfPCell)7 Document (com.lowagie.text.Document)4 Color (java.awt.Color)4 Chunk (com.lowagie.text.Chunk)3 Image (com.lowagie.text.Image)3 Section (com.lowagie.text.Section)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BadElementException (com.lowagie.text.BadElementException)2 Cell (com.lowagie.text.Cell)2 Font (com.lowagie.text.Font)2 ListItem (com.lowagie.text.ListItem)2 Rectangle (com.lowagie.text.Rectangle)2 PdfContentByte (com.lowagie.text.pdf.PdfContentByte)2 PdfPTable (com.lowagie.text.pdf.PdfPTable)2