Package com.lowagie.text

Examples of com.lowagie.text.LwgPhrase


            writer.setViewerPreferences(PdfWriter.PageModeUseOC);
            // step 3: opening the document
            document.open();
            // step 4: content
            PdfContentByte cb = writer.getDirectContent();
            LwgPhrase explanation = new LwgPhrase("Automatic layers, form fields, images, templates and actions", new LwgFont(LwgFont.HELVETICA, 18, LwgFont.BOLD, Color.red));
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
            PdfLayer l1 = new PdfLayer("Layer 1", writer);
            PdfLayer l2 = new PdfLayer("Layer 2", writer);
            PdfLayer l3 = new PdfLayer("Layer 3", writer);
            PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
            PdfLayerMembership m1 = new PdfLayerMembership(writer);
            m1.addMember(l2);
            m1.addMember(l3);
            LwgPhrase p1 = new LwgPhrase("Text in layer 1");
            LwgPhrase p2 = new LwgPhrase("Text in layer 2 or layer 3");
            LwgPhrase p3 = new LwgPhrase("Text in layer 3");
            cb.beginLayer(l1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0f);
            cb.endLayer();
            cb.beginLayer(m1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p2, 50, 550, 0);
            cb.endLayer();
            cb.beginLayer(l3);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p3, 50, 500, 0);
            cb.endLayer();
            TextField ff = new TextField(writer, new LwgRectangle(200, 600, 300, 620), "field1");
            ff.setBorderColor(Color.blue);
            ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
            ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
            ff.setText("I'm a form field");
            PdfFormField form = ff.getTextField();
            form.setLayer(l4);
            writer.addAnnotation(form);
            LwgImage img = LwgImage.getInstance("pngnow.png");
            img.setLayer(l4);
            img.setAbsolutePosition(200, 550);
            cb.addImage(img);
            PdfTemplate tp = cb.createTemplate(100, 20);
            LwgPhrase pt = new LwgPhrase("I'm a template", new LwgFont(LwgFont.HELVETICA, 12, LwgFont.NORMAL, Color.magenta));
            ColumnText.showTextAligned(tp, LwgElement.ALIGN_LEFT, pt, 0, 0, 0);
            tp.setLayer(l4);
            tp.setBoundingBox(new LwgRectangle(0, -10, 100, 20));
            cb.addTemplate(tp, 200, 500);
            ArrayList state = new ArrayList();
            state.add("toggle");
            state.add(l1);
            state.add(l2);
            state.add(l3);
            state.add(l4);
            PdfAction action = PdfAction.setOCGstate(state, true);
            Chunk ck = new Chunk("Click here to toggle the layers", new LwgFont(LwgFont.HELVETICA, 18, LwgFont.NORMAL, Color.yellow)).setBackground(Color.blue).setAction(action);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_CENTER, new LwgPhrase(ck), 250, 400, 0);
            cb.sanityCheck();
           
            // step 5: closing the document
            document.close();
        }
View Full Code Here


        for (int k = 0; k < p.size(); ++k)
            ((Chunk)p.get(k)).getFont().setSize(size);
    }
   
    private LwgPhrase composePhrase(String text, BaseFont ufont, Color color, float fontSize) {
        LwgPhrase phrase = null;
        if (extensionFont == null && (substitutionFonts == null || substitutionFonts.isEmpty()))
            phrase = new LwgPhrase(new Chunk(text, new LwgFont(ufont, fontSize, 0, color)));
        else {
            FontSelector fs = new FontSelector();
            fs.addFont(new LwgFont(ufont, fontSize, 0, color));
            if (extensionFont != null)
                fs.addFont(new LwgFont(extensionFont, fontSize, 0, color));
View Full Code Here

          ptext = text; //fixed by Kazuya Ujihara (ujihara.jp)
        BaseFont ufont = getRealFont();
        Color fcolor = (textColor == null) ? GrayColor.GRAYBLACK : textColor;
        int rtl = checkRTL(ptext) ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_NO_BIDI;
        float usize = fontSize;
        LwgPhrase 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 == LwgElement.ALIGN_RIGHT)
                    position = maxCharacterLength - textLen;
                else if (alignment == LwgElement.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
            Color textCol = (choiceSelections.contains( new Integer( idx ))) ? GrayColor.GRAYWHITE : fcolor;
            LwgPhrase phrase = composePhrase(ptext, ufont, textCol, usize);
            ColumnText.showTextAligned(app, LwgElement.ALIGN_LEFT, phrase, xp, yp, 0, rtl, 0);
        }
        app.restoreState();
        app.endVariableText();
        return app;
View Full Code Here

            float moveTextX = l.indentLeft() - indentLeft() + indentation.indentLeft + indentation.listIndentLeft + indentation.sectionIndentLeft;
            text.moveText(moveTextX, -l.height());
            // is the line preceded by a symbol?
            if (l.listSymbol() != null) {
                ColumnText.showTextAligned(graphics, LwgElement.ALIGN_LEFT, new LwgPhrase(l.listSymbol()), text.getXTLM() - l.listIndent(), text.getYTLM(), 0);
            }

            currentValues[0] = currentFont;

            writeLineToContent(l, text, graphics, currentValues, writer.getSpaceCharRatio());
View Full Code Here

         column.setLeading(0, 1);
         setPadding(borderWidth / 2);
      }
      else
      {
         column.addText(this.phrase = new LwgPhrase(new Chunk(image, 0, 0)));
         column.setLeading(0, 1);
         setPadding(0);
      }
   }
View Full Code Here

        char cc[] = text.toCharArray();
        int len = cc.length;
        StringBuffer sb = new StringBuffer();
        LwgFont font = null;
        int lastidx = -1;
        LwgPhrase ret = new LwgPhrase();
        for (int k = 0; k < len; ++k) {
            char c = cc[k];
            if (c == '\n' || c == '\r') {
                sb.append(c);
                continue;
            }
            if (Utilities.isSurrogatePair(cc, k)) {
                int u = Utilities.convertToUtf32(cc, k);
                for (int f = 0; f < fsize; ++f) {
                    font = (LwgFont)fonts.get(f);
                    if (font.getBaseFont().charExists(u)) {
                        if (lastidx != f) {
                            if (sb.length() > 0 && lastidx != -1) {
                                Chunk ck = new Chunk(sb.toString(), (LwgFont)fonts.get(lastidx));
                                ret.add(ck);
                                sb.setLength(0);
                            }
                            lastidx = f;
                        }
                        sb.append(c);
                        sb.append(cc[++k]);
                        break;
                    }
                }
            }
            else {
                for (int f = 0; f < fsize; ++f) {
                    font = (LwgFont)fonts.get(f);
                    if (font.getBaseFont().charExists(c)) {
                        if (lastidx != f) {
                            if (sb.length() > 0 && lastidx != -1) {
                                Chunk ck = new Chunk(sb.toString(), (LwgFont)fonts.get(lastidx));
                                ret.add(ck);
                                sb.setLength(0);
                            }
                            lastidx = f;
                        }
                        sb.append(c);
                        break;
                    }
                }
            }
        }
        if (sb.length() > 0) {
            Chunk ck = new Chunk(sb.toString(), (LwgFont)fonts.get(lastidx == -1 ? 0 : lastidx));
            ret.add(ck);
        }
        return ret;
    }
View Full Code Here

            table.add(cell);
            table.add("I see an image\non my right");
            table.add(cell);
            table.add("I see an image\non my left");
           
            LwgPhrase p1 = new LwgPhrase("This is an image ");
            p1.add(ck);
            p1.add(" just here.");
            document.add(p1);
            document.add(p1);
            document.add(p1);
            document.add(p1);
            document.add(p1);
View Full Code Here

           
            LwgPdfPTable cell = new LwgPdfPTable(1);
            cell.getDefaultCell().setBorder(LwgRectangle.NO_BORDER);
            cell.getDefaultCell().setPadding(0f);
           
            LwgPdfPCell info = new LwgPdfPCell(new LwgPhrase("Barcode EAN 128"));
            info.setBorder(LwgRectangle.NO_BORDER);
            pageTot.add(info);
           
            Barcode128 shipBarCode = new Barcode128();
            shipBarCode.setX(0.75f);
            shipBarCode.setN(1.5f);
            shipBarCode.setChecksumText(true);
            shipBarCode.setGenerateChecksum(true);
            shipBarCode.setSize(10f);
            shipBarCode.setTextAlignment(LwgElement.ALIGN_CENTER);
            shipBarCode.setBaseline(10f);
            shipBarCode.setCode(data);
            shipBarCode.setBarHeight(50f);
           
            LwgImage imgShipBarCode = shipBarCode.createImageWithBarcode(cb, Color.black, Color.blue);
            LwgPdfPCell shipment = new LwgPdfPCell(new LwgPhrase(
            new Chunk(imgShipBarCode, 0, 0)));
            shipment.setFixedHeight(shipBarCode.getBarcodeSize().getHeight() + 16f);
            shipment.setPaddingTop(5f);
            shipment.setPaddingBottom(10f);
            shipment.setBorder(LwgRectangle.BOX);
View Full Code Here

            table.getDefaultCell().setBorder(LwgRectangle.NO_BORDER);
            table.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
            table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
            table.getDefaultCell().setFixedHeight(70);
            table.add("CODE 39");
            table.add(new LwgPhrase(new Chunk(image39, 0, 0)));
            table.add("CODE 39 EXTENDED");
            table.add(new LwgPhrase(new Chunk(image39ext, 0, 0)));
            table.add("CODE 128");
            table.add(new LwgPhrase(new Chunk(image128, 0, 0)));
            table.add("CODE EAN");
            table.add(new LwgPhrase(new Chunk(imageEAN, 0, 0)));
            table.add("CODE EAN\nWITH\nSUPPLEMENTAL 5");
            table.add(new LwgPhrase(new Chunk(imageEANSUPP, 0, 0)));
            table.add("CODE INTERLEAVED");
            table.add(new LwgPhrase(new Chunk(image25, 0, 0)));
            table.add("CODE POSTNET");
            table.add(new LwgPhrase(new Chunk(imagePost, 0, 0)));
            table.add("CODE PLANET");
            table.add(new LwgPhrase(new Chunk(imagePlanet, 0, 0)));
            document.add(table);
        }
        catch (Exception de) {
            de.printStackTrace();
        }
View Full Code Here

TOP

Related Classes of com.lowagie.text.LwgPhrase

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.