Package com.itextpdf.text

Examples of com.itextpdf.text.Phrase


     * Adds a cell element.
     *
     * @param text the text for the cell
     */
    public void addCell(String text) {
        addCell(new Phrase(text));
    }
View Full Code Here


      }
    }
    // a link should be added to the current paragraph as a phrase
    if (stack.isEmpty()) {
      // no paragraph to add too, 'a' tag is first element
      Paragraph tmp = new Paragraph(new Phrase(currentParagraph));
      currentParagraph = tmp;
    } else {
      Paragraph tmp = (Paragraph) stack.pop();
      tmp.add(new Phrase(currentParagraph));
      currentParagraph = tmp;
    }
  }
View Full Code Here

                Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN );
                float signedSize = ColumnText.fitText(font, signedBy, sr2, -1, runDirection);

                ColumnText ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT);

                ct2.go();
                break;
            case GRAPHIC_AND_DESCRIPTION:
                if (signatureGraphic == null) {
                    throw new IllegalStateException(MessageLocalization.getComposedMessage("a.signature.image.should.be.present.when.rendering.mode.is.graphic.and.description"));
                }
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                Image im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                Paragraph p = new Paragraph();
                // must calculate the point to draw from to make image appear in middle of column
                float x = 0;
                // experimentation found this magic number to counteract Adobe's signature graphic, which
                // offsets the y co-ordinate by 15 units
                float y = -im.getScaledHeight() + 15;

                x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false));
                ct2.addElement(p);
                ct2.go();
                break;
            case GRAPHIC:
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                p = new Paragraph(signatureRect.getHeight());
                // must calculate the point to draw from to make image appear in middle of column
                x = (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x, y, false));
                ct2.addElement(p);
                ct2.go();
                break;
            default:
            }

            if(renderingMode != RenderingMode.GRAPHIC) {
              if (size <= 0) {
                    Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight());
                    size = ColumnText.fitText(font, text, sr, 12, runDirection);
                }
                ColumnText ct = new ColumnText(t);
                ct.setRunDirection(runDirection);
                ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT);
                ct.go();
            }
        }
        if (app[3] == null && !acro6Layers) {
            PdfTemplate t = app[3] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(100, 100));
            writer.addDirectTemplateSimple(t, new PdfName("n3"));
            t.setLiteral("% DSBlank\n");
        }
        if (app[4] == null && !acro6Layers) {
            PdfTemplate t = app[4] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), rect.getRight(), rect.getTop()));
            writer.addDirectTemplateSimple(t, new PdfName("n4"));
            Font font;
            if (layer2Font == null)
                font = new Font();
            else
                font = new Font(layer2Font);
            //float size = font.getSize();
            String text = "Signature Not Verified";
            if (layer4Text != null)
                text = layer4Text;
            Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, rect.getHeight() * TOP_SECTION - 2 * MARGIN);
            float size = ColumnText.fitText(font, text, sr, 15, runDirection);
            ColumnText ct = new ColumnText(t);
            ct.setRunDirection(runDirection);
            ct.setSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.getWidth() - MARGIN, rect.getHeight() - MARGIN, size, Element.ALIGN_LEFT);
            ct.go();
        }
        int rotation = writer.reader.getPageRotation(page);
        Rectangle rotated = new Rectangle(rect);
        int n = rotation;
View Full Code Here

     * Adds a cell element.
     *
     * @param text the text for the cell
     */
    public void addCell(final String text) {
        addCell(new Phrase(text));
    }
View Full Code Here

        for (int k = 0; k < p.size(); ++k)
            ((Chunk)p.get(k)).getFont().setSize(size);
    }

    private Phrase composePhrase(String text, BaseFont ufont, BaseColor color, float fontSize) {
        Phrase phrase = null;
        if (extensionFont == null && (substitutionFonts == null || substitutionFonts.isEmpty()))
            phrase = new Phrase(new Chunk(text, new Font(ufont, fontSize, 0, color)));
        else {
            FontSelector fs = new FontSelector();
            fs.addFont(new Font(ufont, fontSize, 0, color));
            if (extensionFont != null)
                fs.addFont(new Font(extensionFont, fontSize, 0, color));
View Full Code Here

          ptext = text; //fixed by Kazuya Ujihara (ujihara.jp)
        BaseFont ufont = getRealFont();
        BaseColor fcolor = textColor == null ? GrayColor.GRAYBLACK : textColor;
        int rtl = checkRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
        float usize = fontSize;
        Phrase phrase = composePhrase(ptext, ufont, fcolor, usize);
        if ((options & MULTILINE) != 0) {
            float width = box.getWidth() - 4 * offsetX - extraMarginLeft;
            float factor = ufont.getFontDescriptor(BaseFont.BBOXURY, 1) - ufont.getFontDescriptor(BaseFont.BBOXLLY, 1);
            ColumnText ct = new ColumnText(null);
            if (usize == 0) {
                usize = h / factor;
                if (usize > 4) {
                    if (usize > 12)
                        usize = 12;
                    float step = Math.max((usize - 4) / 10, 0.2f);
                    ct.setSimpleColumn(0, -h, width, 0);
                    ct.setAlignment(alignment);
                    ct.setRunDirection(rtl);
                    for (; usize > 4; usize -= step) {
                        ct.setYLine(0);
                        changeFontSize(phrase, usize);
                        ct.setText(phrase);
                        ct.setLeading(factor * usize);
                        int status = ct.go(true);
                        if ((status & ColumnText.NO_MORE_COLUMN) == 0)
                            break;
                    }
                }
                if (usize < 4)
                    usize = 4;
            }
            changeFontSize(phrase, usize);
            ct.setCanvas(app);
            float leading = usize * factor;
            float offsetY = offsetX + h - ufont.getFontDescriptor(BaseFont.BBOXURY, usize);
            ct.setSimpleColumn(extraMarginLeft + 2 * offsetX, -20000, box.getWidth() - 2 * offsetX, offsetY + leading);
            ct.setLeading(leading);
            ct.setAlignment(alignment);
            ct.setRunDirection(rtl);
            ct.setText(phrase);
            ct.go();
        }
        else {
            if (usize == 0) {
                float maxCalculatedSize = h / (ufont.getFontDescriptor(BaseFont.BBOXURX, 1) - ufont.getFontDescriptor(BaseFont.BBOXLLY, 1));
                changeFontSize(phrase, 1);
                float wd = ColumnText.getWidth(phrase, rtl, 0);
                if (wd == 0)
                    usize = maxCalculatedSize;
                else
                  usize = Math.min(maxCalculatedSize, (box.getWidth() - extraMarginLeft - 4 * offsetX) / wd);
                if (usize < 4)
                    usize = 4;
            }
            changeFontSize(phrase, usize);
            float offsetY = offX + (box.getHeight() - 2*offX - ufont.getFontDescriptor(BaseFont.ASCENT, usize)) / 2;
            if (offsetY < offX)
                offsetY = offX;
            if (offsetY - offX < -ufont.getFontDescriptor(BaseFont.DESCENT, usize)) {
                float ny = -ufont.getFontDescriptor(BaseFont.DESCENT, usize) + offX;
                float dy = box.getHeight() - offX - ufont.getFontDescriptor(BaseFont.ASCENT, usize);
                offsetY = Math.min(ny, Math.max(offsetY, dy));
            }
            if ((options & COMB) != 0 && maxCharacterLength > 0) {
                int textLen = Math.min(maxCharacterLength, ptext.length());
                int position = 0;
                if (alignment == Element.ALIGN_RIGHT)
                    position = maxCharacterLength - textLen;
                else if (alignment == Element.ALIGN_CENTER)
                    position = (maxCharacterLength - textLen) / 2;
                float step = (box.getWidth() - extraMarginLeft) / maxCharacterLength;
                float start = step / 2 + position * step;
                if (textColor == null)
                    app.setGrayFill(0);
                else
                    app.setColorFill(textColor);
                app.beginText();
                for (int k = 0; k < phrase.size(); ++k) {
                    Chunk ck = (Chunk)phrase.get(k);
                    BaseFont bf = ck.getFont().getBaseFont();
                    app.setFontAndSize(bf, usize);
                    StringBuffer sb = ck.append("");
                    for (int j = 0; j < sb.length(); ++j) {
                        String c = sb.substring(j, j + 1);
View Full Code Here

            String ptext = choices[idx];
            int rtl = checkRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
            ptext = removeCRLF(ptext);
            // highlight selected values against their (presumably) darker background
            BaseColor textCol = choiceSelections.contains( Integer.valueOf( idx )) ? GrayColor.GRAYWHITE : fcolor;
            Phrase phrase = composePhrase(ptext, ufont, textCol, usize);
            ColumnText.showTextAligned(app, Element.ALIGN_LEFT, phrase, xp, yp, 0, rtl, 0);
        }
        app.restoreState();
        app.endVariableText();
        return app;
View Full Code Here

            System.out.println("File Generated");
        }
    }

    public void newLine(Document document) throws DocumentException {
        document.add(new Phrase(""));
    }
View Full Code Here

         * Personal Details
         */
        PdfPTable table = new PdfPTable(2); // 2 columns.

        ArrayList<PdfPCell> cellList = new ArrayList<PdfPCell>();
        cellList.add(new PdfPCell(new Phrase("Staff ID:")));
        cellList.add(new PdfPCell(new Phrase(this.profileRef.getStaffid())));
        cellList.add(new PdfPCell(new Phrase("Title:")));
        cellList.add(new PdfPCell(new Phrase(this.profileRef.getTitle())));
        cellList.add(new PdfPCell(new Phrase("Surname:")));
        cellList.add(new PdfPCell(new Phrase(this.profileRef.getFamilyname())));
        cellList.add(new PdfPCell(new Phrase("First Name:")));
        cellList.add(new PdfPCell(new Phrase(this.profileRef.getFirstname())));

        for (int i = 0; i < cellList.size(); i++) {
            if (i % 2 == 0) {
                cellList.get(i).setBorder(Rectangle.NO_BORDER);
            }
            table.addCell(cellList.get(i));
        }
        document.add(table);

        /**
         * Travel Details
         */
        table = new PdfPTable(2);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Travel", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Application Name:")));
        cellList.add(new PdfPCell(new Phrase(this.appRef.getDescription())));
        cellList.add(new PdfPCell(new Phrase("Date of Initial Departure:")));
        cellList.add(new PdfPCell(new Phrase(df.format(this.travelRef.getDatedeparture()))));

        cellList.add(new PdfPCell(new Phrase("Date of Final Return:")));
        cellList.add(new PdfPCell(new Phrase(df.format(this.travelRef.getDatereturn()))));

        cellList.add(new PdfPCell(new Phrase("Purpose of Travel:")));
        cellList.add(new PdfPCell(new Phrase(this.travelRef.getDescription())));

        for (int i = 0; i < cellList.size(); i++) {
            if (i % 2 == 0) {
                cellList.get(i).setBorder(Rectangle.NO_BORDER);
            }
            table.addCell(cellList.get(i));
        }

        document.add(table);

        /**
         * Itinerary Details
         */
        table = new PdfPTable(4);
        table.setWidthPercentage(90f);
        table.setHeaderRows(1);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Itinerary", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Date", bold)));
        cellList.add(new PdfPCell(new Phrase("Destination", bold)));
        cellList.add(new PdfPCell(new Phrase("Leave Type", bold)));
        cellList.add(new PdfPCell(new Phrase("Travel Day/ Work Day", bold)));


        for (Itinerary i : hops) {
            //cellList.add(new PdfPCell(new Phrase(df.format(i.getDate()))));
            cellList.add(new PdfPCell(new Phrase("BLANK")));
            cellList.add(new PdfPCell(new Phrase(i.getDestinationCity())));
            cellList.add(new PdfPCell(new Phrase(i.getLeavetype())));
            cellList.add(new PdfPCell(new Phrase(i.getTravelday())));
        }

        for (int i = 0; i < cellList.size(); i++) {
            table.addCell(cellList.get(i));
        }
        document.add(table);

        /**
         * Quote CostCenter
         */
        table = new PdfPTable(2);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Quotes", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Cost Center:")));
        cellList.add(new PdfPCell(new Phrase(this.quoteRef.getCostcenter())));

        for (int i = 0; i < cellList.size(); i++) {
            if (i % 2 == 0) {
                cellList.get(i).setBorder(Rectangle.NO_BORDER);
            }
            table.addCell(cellList.get(i));
        }

        document.add(table);

        /**
         * Flight Quotes
         */
        table = new PdfPTable(4);
        table.setWidthPercentage(90f);
        table.setHeaderRows(1);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Flight Quotes", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("From", bold)));
        cellList.add(new PdfPCell(new Phrase("To", bold)));
        cellList.add(new PdfPCell(new Phrase("Airline", bold)));
        cellList.add(new PdfPCell(new Phrase("Cost Quoted", bold)));


        Flightquotes f = selectedFlgQte;
        cellList.add(new PdfPCell(new Phrase(f.getFlightfromCity())));
        cellList.add(new PdfPCell(new Phrase(f.getFlighttoCity())));
        cellList.add(new PdfPCell(new Phrase(f.getQuotesource())));
        cellList.add(new PdfPCell(new Phrase(f.getCurrency() + " " + f.getQuotecost().toString())));

        for (int i = 0; i < cellList.size(); i++) {
            table.addCell(cellList.get(i));
        }
        document.add(table);

        /**
         * Car Quotes
         */
        table = new PdfPTable(4);
        table.setWidthPercentage(90f);
        table.setHeaderRows(1);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Flight Quotes", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Collect Date", bold)));
        cellList.add(new PdfPCell(new Phrase("Return Date", bold)));
        cellList.add(new PdfPCell(new Phrase("Rental Company", bold)));
        cellList.add(new PdfPCell(new Phrase("Cost Quoted", bold)));


        Carquotes c = selectedCarQte;
        cellList.add(new PdfPCell(new Phrase(df.format(c.getDatecollect()))));
        cellList.add(new PdfPCell(new Phrase(df.format(c.getDatereturn()))));
        cellList.add(new PdfPCell(new Phrase(c.getProvider())));
        cellList.add(new PdfPCell(new Phrase(c.getCurrency() + " " + c.getQuotecost().toString())));

        for (int i = 0; i < cellList.size(); i++) {
            table.addCell(cellList.get(i));
        }
        document.add(table);

        /**
         * Accommodation Quotes
         */
        table = new PdfPTable(5);
        table.setWidthPercentage(90f);
        table.setHeaderRows(1);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Accomodation Quotes", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Location", bold)));
        cellList.add(new PdfPCell(new Phrase("Checkin Date", bold)));
        cellList.add(new PdfPCell(new Phrase("Checkout Date", bold)));
        cellList.add(new PdfPCell(new Phrase("Hotel", bold)));
        cellList.add(new PdfPCell(new Phrase("Cost Quoted", bold)));


        Accomodationquotes a = selectedAccQte;
        cellList.add(new PdfPCell(new Phrase(a.getCity())));
        cellList.add(new PdfPCell(new Phrase(df.format(a.getDatecheckin()))));
        cellList.add(new PdfPCell(new Phrase(df.format(a.getDatecheckout()))));
        cellList.add(new PdfPCell(new Phrase(a.getAccomodationprovider())));
        cellList.add(new PdfPCell(new Phrase(a.getCurrency() + " " + a.getQuotecost().toString())));

        for (int i = 0; i < cellList.size(); i++) {
            table.addCell(cellList.get(i));
        }
        document.add(table);

        /**
         * Approval Section
         */
        newLine(document);
        table = new PdfPTable(2);
        cellList = new ArrayList<PdfPCell>();
        newLine(document);
        document.add(new Paragraph("Approval", mediumFont));
        newLine(document);
        cellList.add(new PdfPCell(new Phrase("Approved:")));
        cellList.add(new PdfPCell(new Phrase(this.getApproved() == 1 ? "YES" : "NO")));
        cellList.add(new PdfPCell(new Phrase("Authorizer Name:")));
        cellList.add(new PdfPCell(new Phrase(this.getApprovalName())));

        cellList.add(new PdfPCell(new Phrase("Authorizer Comments:")));
        cellList.add(new PdfPCell(new Phrase(this.getApprovalComment())));

        for (int i = 0; i < cellList.size(); i++) {
            if (i % 2 == 0) {
                cellList.get(i).setBorder(Rectangle.NO_BORDER);
            }
View Full Code Here

        FacesContext.getCurrentInstance().responseComplete();
        System.out.println("File Generated");
    }

    public void newLine(Document document) throws DocumentException {
        document.add(new Phrase(""));
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Phrase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.