Package com.lowagie.text

Examples of com.lowagie.text.Paragraph


                    break;
                }
                case Element.PARAGRAPH: {
                  leadingCount++;
                    // we cast the element to a paragraph
                    Paragraph paragraph = (Paragraph) element;
                    addSpacing(paragraph.spacingBefore(), leading, paragraph.getFont());
                   
                    // we adjust the parameters of the document
                    alignment = paragraph.getAlignment();
                    leading = paragraph.getTotalLeading();
                    carriageReturn();
                   
                    // we don't want to make orphans/widows
                    if (currentHeight + line.height() + leading > indentTop() - indentBottom()) {
                        newPage();
                    }
                    indentation.indentLeft += paragraph.getIndentationLeft();
                    indentation.indentRight += paragraph.getIndentationRight();
                    carriageReturn();
    
                    PdfPageEvent pageEvent = writer.getPageEvent();
                    if (pageEvent != null && !isSectionTitle)
                        pageEvent.onParagraph(writer, this, indentTop() - currentHeight);
                   
                    // if a paragraph has to be kept together, we wrap it in a table object
                    if (paragraph.getKeepTogether()) {
                      carriageReturn();
                        PdfPTable table = new PdfPTable(1);
                        table.setWidthPercentage(100f);
                        PdfPCell cell = new PdfPCell();
                        cell.addElement(paragraph);
                        cell.setBorder(Table.NO_BORDER);
                        cell.setPadding(0);
                        table.addCell(cell);
                        indentation.indentLeft -= paragraph.getIndentationLeft();
                        indentation.indentRight -= paragraph.getIndentationRight();
                        this.add(table);
                        indentation.indentLeft += paragraph.getIndentationLeft();
                        indentation.indentRight += paragraph.getIndentationRight();
                    }
                    else {
                      line.setExtraIndent(paragraph.getFirstLineIndent());
                      element.process(this);
                        carriageReturn();
                        addSpacing(paragraph.spacingAfter(), paragraph.getTotalLeading(), paragraph.getFont());
                    }

                    if (pageEvent != null && !isSectionTitle)
                        pageEvent.onParagraphEnd(writer, this, indentTop() - currentHeight);
                   
                    alignment = Element.ALIGN_LEFT;
                    indentation.indentLeft -= paragraph.getIndentationLeft();
                    indentation.indentRight -= paragraph.getIndentationRight();
                    carriageReturn();
                    leadingCount--;
                    break;
                }
                case Element.SECTION:
View Full Code Here


     * @throws DocumentException on error
     */
    void addPTable(PdfPTable ptable) throws DocumentException {
        ColumnText ct = new ColumnText(writer.getDirectContent());
        if (currentHeight > 0) {
            Paragraph p = new Paragraph();
            p.setLeading(0);
            ct.addElement(p);
            // if the table prefers to be on a single page, and it wouldn't
          //fit on the current page, start a new page.
          if (ptable.getKeepTogether() && !fitsPage(ptable, 0f))  {
            newPage();
          }
        }
        ct.addElement(ptable);
        boolean he = ptable.isHeadersInEvent();
        ptable.setHeadersInEvent(true);
        int loop = 0;
        while (true) {
            ct.setSimpleColumn(indentLeft(), indentBottom(), indentRight(), indentTop() - currentHeight);
            int status = ct.go();
            if ((status & ColumnText.NO_MORE_TEXT) != 0) {
                text.moveText(0, ct.getYLine() - indentTop() + currentHeight);
                currentHeight = indentTop() - ct.getYLine();
                break;
            }
            if (indentTop() - currentHeight == ct.getYLine())
                ++loop;
            else
                loop = 0;
            if (loop == 3) {
                add(new Paragraph("ERROR: Infinite table loop"));
                break;
            }
            newPage();
        }
        ptable.setHeadersInEvent(he);
View Full Code Here

                    float currentRight = right;
                    if (element instanceof Phrase) {
                        currentLineLeading = ((Phrase) element).getLeading();
                    }
                    if (element instanceof Paragraph) {
                        Paragraph p = (Paragraph) element;
                        currentLeft += p.getIndentationLeft();
                        currentRight -= p.getIndentationRight();
                    }
                    if (line == null) {
                        line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
                    }
                    // we loop over the chunks
View Full Code Here

                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();
            }
           
            if (size <= 0) {
View Full Code Here

      p.setLeading(0, 1.5f);
    }
  }

  public static Paragraph createParagraph(HashMap props) {
    Paragraph p = new Paragraph();
    String value = (String) props.get("align");
    if (value != null) {
      if (value.equalsIgnoreCase("center"))
        p.setAlignment(Element.ALIGN_CENTER);
      else if (value.equalsIgnoreCase("right"))
        p.setAlignment(Element.ALIGN_RIGHT);
      else if (value.equalsIgnoreCase("justify"))
        p.setAlignment(Element.ALIGN_JUSTIFIED);
    }
    p.setHyphenation(getHyphenation(props));
    setParagraphLeading(p, (String) props.get("leading"));
    return p;
  }
View Full Code Here

      }
    }
  }

  public static Paragraph createParagraph(ChainedProperties props) {
    Paragraph p = new Paragraph();
    createParagraph(p, props);
    return p;
  }
View Full Code Here

      }
      FactoryProperties.insertStyle(h, cprops);
      if (tag.equals(HtmlTags.ANCHOR)) {
        cprops.addToChain(tag, h);
        if (currentParagraph == null) {
          currentParagraph = new Paragraph();
        }
        stack.push(currentParagraph);
        currentParagraph = new Paragraph();
        return;
      }
      if (tag.equals(HtmlTags.NEWLINE)) {
        if (currentParagraph == null) {
          currentParagraph = new Paragraph();
        }
        currentParagraph.add(factoryProperties
            .createChunk("\n", cprops));
        return;
      }
View Full Code Here

        cprops.removeChain(tag);
        return;
      }
      if (tag.equals("a")) {
        if (currentParagraph == null) {
          currentParagraph = new Paragraph();
        }
        boolean skip = false;
        if (interfaceProps != null) {
          ALink i = (ALink) interfaceProps.get("alink_interface");
          if (i != null)
            skip = i.process(currentParagraph, cprops);
        }
        if (!skip) {
          String href = cprops.getProperty("href");
          if (href != null) {
            ArrayList chunks = currentParagraph.getChunks();
            int size = chunks.size();
            for (int k = 0; k < size; ++k) {
              Chunk ck = (Chunk) chunks.get(k);
              ck.setAnchor(href);
            }
          }
        }
        Paragraph tmp = (Paragraph) stack.pop();
        Phrase tmp2 = new Phrase();
        tmp2.add(currentParagraph);
        tmp.add(tmp2);
        currentParagraph = tmp;
        cprops.removeChain("a");
        return;
      }
      if (tag.equals("br")) {
View Full Code Here

            c.setBackgroundColor(img.getBackgroundColor());
            t.addCell(c);
            element = t;
        }
        if (element.type() == Element.CHUNK) {
          element = new Paragraph((Chunk)element);
        }
        else if (element.type() == Element.PHRASE) {
          element = new Paragraph((Phrase)element);
        }
        if (element instanceof SimpleTable) {
          try {
        element = ((SimpleTable)element).createPdfPTable();
      } catch (DocumentException e) {
View Full Code Here

        while (true) {
            if (compositeElements.isEmpty())
                return NO_MORE_TEXT;
            Element element = (Element)compositeElements.getFirst();
            if (element.type() == Element.PARAGRAPH) {
                Paragraph para = (Paragraph)element;
                int status = 0;
                for (int keep = 0; keep < 2; ++keep) {
                    float lastY = yLine;
                    boolean createHere = false;
                    if (compositeColumn == null) {
                        compositeColumn = new ColumnText(canvas);
                        compositeColumn.setUseAscender(firstPass ? useAscender : false);
                        compositeColumn.setAlignment(para.getAlignment());
                        compositeColumn.setIndent(para.getIndentationLeft() + para.getFirstLineIndent());
                        compositeColumn.setExtraParagraphSpace(para.getExtraParagraphSpace());
                        compositeColumn.setFollowingIndent(para.getIndentationLeft());
                        compositeColumn.setRightIndent(para.getIndentationRight());
                        compositeColumn.setLeading(para.getLeading(), para.getMultipliedLeading());
                        compositeColumn.setRunDirection(runDirection);
                        compositeColumn.setArabicOptions(arabicOptions);
                        compositeColumn.setSpaceCharRatio(spaceCharRatio);
                        compositeColumn.addText(para);
                        if (!firstPass) {
                            yLine -= para.spacingBefore();
                        }
                        createHere = true;
                    }
                    compositeColumn.leftX = leftX;
                    compositeColumn.rightX = rightX;
                    compositeColumn.yLine = yLine;
                    compositeColumn.rectangularWidth = rectangularWidth;
                    compositeColumn.rectangularMode = rectangularMode;
                    compositeColumn.minY = minY;
                    compositeColumn.maxY = maxY;
                    boolean keepCandidate = (para.getKeepTogether() && createHere && !firstPass);
                    status = compositeColumn.go(simulate || (keepCandidate && keep == 0));
                    updateFilledWidth(compositeColumn.filledWidth);
                    if ((status & NO_MORE_TEXT) == 0 && keepCandidate) {
                        compositeColumn = null;
                        yLine = lastY;
                        return NO_MORE_COLUMN;
                    }
                    if (simulate || !keepCandidate)
                        break;
                    if (keep == 0) {
                        compositeColumn = null;
                        yLine = lastY;
                    }
                }
                firstPass = false;
                yLine = compositeColumn.yLine;
                linesWritten += compositeColumn.linesWritten;
                descender = compositeColumn.descender;
                if ((status & NO_MORE_TEXT) != 0) {
                    compositeColumn = null;
                    compositeElements.removeFirst();
                    yLine -= para.spacingAfter();
                }
                if ((status & NO_MORE_COLUMN) != 0) {
                    return NO_MORE_COLUMN;
                }
            }
View Full Code Here

TOP

Related Classes of com.lowagie.text.Paragraph

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.