Package com.lowagie.text

Examples of com.lowagie.text.Section


                }
                case Element.SECTION:
                case Element.CHAPTER: {
                    // Chapters and Sections only differ in their constructor
                    // so we cast both to a Section
                    Section section = (Section) element;
                    PdfPageEvent pageEvent = writer.getPageEvent();
                   
                    boolean hasTitle = section.isNotAddedYet()
                      && section.getTitle() != null;
                   
                    // if the section is a chapter, we begin a new page
                    if (section.isTriggerNewPage()) {
                        newPage();
                    }

                    if (hasTitle) {
                      float fith = indentTop() - currentHeight;
                      int rotation = pageSize.getRotation();
                      if (rotation == 90 || rotation == 180)
                        fith = pageSize.getHeight() - fith;
                      PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith);
                      while (currentOutline.level() >= section.getDepth()) {
                        currentOutline = currentOutline.parent();
                      }
                      PdfOutline outline = new PdfOutline(currentOutline, destination, section.getBookmarkTitle(), section.isBookmarkOpen());
                      currentOutline = outline;
                    }
                   
                    // some values are set
                    carriageReturn();
                    indentation.sectionIndentLeft += section.getIndentationLeft();
                    indentation.sectionIndentRight += section.getIndentationRight();
     
                    if (section.isNotAddedYet() && pageEvent != null)
                        if (element.type() == Element.CHAPTER)
                            pageEvent.onChapter(writer, this, indentTop() - currentHeight, section.getTitle());
                        else
                            pageEvent.onSection(writer, this, indentTop() - currentHeight, section.getDepth(), section.getTitle());
                   
                    // the title of the section (if any has to be printed)
                    if (hasTitle) {
                        isSectionTitle = true;
                        add(section.getTitle());
                        isSectionTitle = false;
                    }
                    indentation.sectionIndentLeft += section.getIndentation();
                    // we process the section
                    element.process(this);
                    flushLines();
                    // some parameters are set back to normal again
                    indentation.sectionIndentLeft -= (section.getIndentationLeft() + section.getIndentation());
                    indentation.sectionIndentRight -= section.getIndentationRight();

                    if (section.isComplete() && pageEvent != null)
                        if (element.type() == Element.CHAPTER)
                            pageEvent.onChapterEnd(writer, this, indentTop() - currentHeight);
                        else
                            pageEvent.onSectionEnd(writer, this, indentTop() - currentHeight);
View Full Code Here


        }

        // sections
        if (ElementTags.SECTION.equals(name)) {
            LwgElement previous = (LwgElement) stack.pop();
            Section section;
            try {
                section = ElementFactory.getSection((Section) previous, attributes);
            } catch (ClassCastException cce) {
                throw new ExceptionConverter(cce);
            }
View Full Code Here

                Paragraph current = (Paragraph) stack.pop();
                if (currentChunk != null) {
                    current.add(currentChunk);
                    currentChunk = null;
                }
                Section previous = (Section) stack.pop();
                previous.setTitle(current);
                stack.push(previous);
                return;
            }

            // all other endtags
            if (currentChunk != null) {
                TextElementArray current;
                try {
                    current = (TextElementArray) stack.pop();
                } catch (EmptyStackException ese) {
                    current = new Paragraph();
                }
                current.add(currentChunk);
                stack.push(current);
                currentChunk = null;
            }

            // chunks
            if (ElementTags.CHUNK.equals(name)) {
                return;
            }

            // phrases, anchors, lists, tables
            if (ElementTags.PHRASE.equals(name) || ElementTags.ANCHOR.equals(name) || ElementTags.LIST.equals(name)
                    || ElementTags.PARAGRAPH.equals(name)) {
                LwgElement current = (LwgElement) stack.pop();
                try {
                    TextElementArray previous = (TextElementArray) stack.pop();
                    previous.add(current);
                    stack.push(previous);
                } catch (EmptyStackException ese) {
                    document.add(current);
                }
                return;
            }

            // listitems
            if (ElementTags.LISTITEM.equals(name)) {
                ListItem listItem = (ListItem) stack.pop();
                List list = (List) stack.pop();
                list.add(listItem);
                stack.push(list);
            }

            // tables
            if (ElementTags.TABLE.equals(name)) {
                Table table = (Table) stack.pop();
                try {
                    TextElementArray previous = (TextElementArray) stack.pop();
                    previous.add(table);
                    stack.push(previous);
                } catch (EmptyStackException ese) {
                    document.add(table);
                }
                return;
            }

            // rows
            if (ElementTags.ROW.equals(name)) {
                ArrayList cells = new ArrayList();
                int columns = 0;
                Table table;
                LwgCell cell;
                while (true) {
                    LwgElement element = (LwgElement) stack.pop();
                    if (element.type() == LwgElement.CELL) {
                        cell = (LwgCell) element;
                        columns += cell.getColspan();
                        cells.add(cell);
                    } else {
                        table = (Table) element;
                        break;
                    }
                }
                if (table.getColumns() < columns) {
                    table.addColumns(columns - table.getColumns());
                }
                Collections.reverse(cells);
                String width;
                float[] cellWidths = new float[columns];
                boolean[] cellNulls = new boolean[columns];
                for (int i = 0; i < columns; i++) {
                    cellWidths[i] = 0;
                    cellNulls[i] = true;
                }
                float total = 0;
                int j = 0;
                for (Iterator i = cells.iterator(); i.hasNext();) {
                    cell = (LwgCell) i.next();
                    width = cell.getWidthAsString();
                    if (cell.getWidth() == 0) {
                        if (cell.getColspan() == 1 && cellWidths[j] == 0) {
                            try {
                                cellWidths[j] = 100f / columns;
                                total += cellWidths[j];
                            } catch (Exception e) {
                                // empty on purpose
                            }
                        } else if (cell.getColspan() == 1) {
                            cellNulls[j] = false;
                        }
                    } else if (cell.getColspan() == 1 && width.endsWith("%")) {
                        try {
                            cellWidths[j] = Float.parseFloat(
                                    width.substring(0, width.length() - 1)
                                            + "f");
                            total += cellWidths[j];
                            cellNulls[j] = false;
                        } catch (Exception e) {
                            // empty on purpose
                        }
                    }
                    j += cell.getColspan();
                    table.addCell(cell);
                }
                float widths[] = table.getProportionalWidths();
                if (widths.length == columns) {
                    float left = 0.0f;
                    for (int i = 0; i < columns; i++) {
                        if (cellNulls[i] && widths[i] != 0) {
                            left += widths[i];
                            cellWidths[i] = widths[i];
                        }
                    }
                    if (100.0 >= total) {
                        for (int i = 0; i < widths.length; i++) {
                            if (cellWidths[i] == 0 && widths[i] != 0) {
                                cellWidths[i] = (widths[i] / left)
                                        * (100.0f - total);
                            }
                        }
                    }
                    table.setWidths(cellWidths);
                }
                stack.push(table);
            }

            // cells
            if (ElementTags.CELL.equals(name)) {
                return;
            }

            // sections
            if (ElementTags.SECTION.equals(name)) {
                stack.pop();
                return;
            }

            // chapters
            if (ElementTags.CHAPTER.equals(name)) {
                document.add((LwgElement) stack.pop());
                return;
            }

            // the documentroot
            if (isDocumentRoot(name)) {
                try {
                    while (true) {
                        LwgElement element = (LwgElement) stack.pop();
                        try {
                            TextElementArray previous = (TextElementArray) stack
                                    .pop();
                            previous.add(element);
                            stack.push(previous);
                        } catch (EmptyStackException es) {
                            document.add(element);
                        }
                    }
View Full Code Here

   * @param pdf the path to the PDF file
   * @param section the section to which the bookmarks should be added
   * @param bookmark a HashMap containing a Bookmark (and possible kids)
   */
  private static void addBookmark(String pdf, Section section, HashMap<String, Object> bookmark) {
    Section s = createBookmark(pdf, section, bookmark);
    List<HashMap<String, Object>> kids = (List<HashMap<String, Object>>) bookmark.get("Kids");
    if (kids == null) return;
    for (HashMap<String, Object> m: kids) {
      addBookmark(pdf, s, m);
    }
View Full Code Here

   * @param section the section that gets the line
   * @param bookmark the bookmark that has the data for the line
   * @return a subsection of section
   */
  private static Section createBookmark(String pdf, Section section, HashMap<String, Object> bookmark) {
    Section s;
    Paragraph title = new Paragraph((String)bookmark.get("Title"));
    System.out.println((String)bookmark.get("Title"));
    String action = (String)bookmark.get("Action");
    if ("GoTo".equals(action)) {
      if (bookmark.get("Page") != null) {
        String page = (String)bookmark.get("Page");
        StringTokenizer tokens = new StringTokenizer(page);
        String token = tokens.nextToken();
        Anchor anchor = new Anchor(" page" + token);
        anchor.setReference(pdf + "#page=" + token);
        title.add(anchor);
      }
    }
    else if ("URI".equals(action)) {
      String url = (String)bookmark.get("URI");
      Anchor anchor = new Anchor(" Goto URL");
      anchor.setReference(url);
      title.add(anchor);
    }
    else if ("GoToR".equals(action)) {
      String remote = (String)bookmark.get("File");
      Anchor anchor = new Anchor(" goto " + remote);
      if (bookmark.get("Named") != null) {
        String named = (String)bookmark.get("Named");
        remote = remote + "#nameddest=" + named;
      }
      else if (bookmark.get("Page") != null) {
        String page = (String)bookmark.get("Page");
        StringTokenizer tokens = new StringTokenizer(page);
        String token = tokens.nextToken();
        anchor.add(new Chunk(" page " + token));
        remote = remote + "#page=" + token;
      }
      anchor.setReference(remote);
      title.add(anchor);
    }
    if (section == null) {
      s = new Chapter(title, 0);
    }
    else {
      s = section.addSection(title);
    }
    s.setNumberDepth(0);
    return s;
  }
View Full Code Here

            Chapter chapter = new Chapter(new Paragraph("This is a Chapter"), 1);
            chapter.add(new Paragraph(
                    "This is some text that belongs to this chapter."));
            chapter.add(new Paragraph("A second paragraph. What a surprise."));

            Section section = chapter.addSection(new Paragraph(
                    "This is a subsection"));
            section.add(new Paragraph("Text in the subsection."));

            doc.add(chapter);

            com.lowagie.text.rtf.field.RtfTOCEntry rtfTOC = new com.lowagie.text.rtf.field.RtfTOCEntry(
                    "Table Test");
View Full Code Here

                    blahblah.setAlignment(LwgElement.ALIGN_JUSTIFIED);
                }
                // in every chapter 3 sections will be added
                for (int j = 1; j < 4; j++) {
                    Paragraph sTitle = new Paragraph("This is section " + j + " in chapter " + i, sectionFont);
                    Section section = chapter.addSection(sTitle, 1);
                    // for chapters > 2, the outine isn't open by default
                    if (i > 2) section.setBookmarkOpen(false);
                    // in all chapters except the 1st one, some extra text is added to section 3
                    if (j == 3 && i > 1) {
                      section.setIndentationLeft(72);
                        section.add(blahblah);
                      section.add(new Paragraph("test"));
                    }
                    // in every section 3 subsections are added
                    for (int k = 1; k < 4; k++) {
                        Paragraph subTitle = new Paragraph("This is subsection " + k + " of section " + j, subsectionFont);
                        Section subsection = section.addSection(subTitle, 3);
                        // in the first subsection of section 3, extra text is added
                        if (k == 1 && j == 3) {
                            subsection.add(blahblahblah);
                        }
                        subsection.add(blahblah);
                    }
                    // in the section section of every chapter > 2 extra text is added
                    if (j == 2 && i > 2) {
                        section.add(blahblahblah);
                    }
View Full Code Here

   * Creates a Section object based on a list of properties.
   * @param attributes
   * @return a Section
   */
  public static Section getSection(Section parent, Properties attributes) {
    Section section = parent.addSection("");
    setSectionParameters(section, attributes);
    return section;
  }
View Full Code Here

                }
                case LwgElement.SECTION:
                case LwgElement.CHAPTER: {
                    // Chapters and Sections only differ in their constructor
                    // so we cast both to a Section
                    Section section = (Section) element;
                    PdfPageEvent pageEvent = writer.getPageEvent();

                    boolean hasTitle = section.isNotAddedYet()
                      && section.getTitle() != null;

                    // if the section is a chapter, we begin a new page
                    if (section.isTriggerNewPage()) {
                        newPage();
                    }

                    if (hasTitle) {
                      float fith = indentTop() - currentHeight;
                      int rotation = pageSize.getRotation();
                      if (rotation == 90 || rotation == 180)
                        fith = pageSize.getHeight() - fith;
                      PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith);
                      while (currentOutline.level() >= section.getDepth()) {
                        currentOutline = currentOutline.parent();
                      }
                      PdfOutline outline = new PdfOutline(currentOutline, destination, section.getBookmarkTitle(), section.isBookmarkOpen());
                      currentOutline = outline;
                    }

                    // some values are set
                    carriageReturn();
                    indentation.sectionIndentLeft += section.getIndentationLeft();
                    indentation.sectionIndentRight += section.getIndentationRight();

                    if (section.isNotAddedYet() && pageEvent != null)
                        if (element.type() == LwgElement.CHAPTER)
                            pageEvent.onChapter(writer, this, indentTop() - currentHeight, section.getTitle());
                        else
                            pageEvent.onSection(writer, this, indentTop() - currentHeight, section.getDepth(), section.getTitle());

                    // the title of the section (if any has to be printed)
                    if (hasTitle) {
                        isSectionTitle = true;
                        add(section.getTitle());
                        isSectionTitle = false;
                    }
                    indentation.sectionIndentLeft += section.getIndentation();
                    // we process the section
                    element.process(this);
                    flushLines();
                    // some parameters are set back to normal again
                    indentation.sectionIndentLeft -= (section.getIndentationLeft() + section.getIndentation());
                    indentation.sectionIndentRight -= section.getIndentationRight();

                    if (section.isComplete() && pageEvent != null)
                        if (element.type() == LwgElement.CHAPTER)
                            pageEvent.onChapterEnd(writer, this, indentTop() - currentHeight);
                        else
                            pageEvent.onSectionEnd(writer, this, indentTop() - currentHeight);
View Full Code Here

   * @param pdf the path to the PDF file
   * @param section the section to which the bookmarks should be added
   * @param bookmark a HashMap containing a Bookmark (and possible kids)
   */
  private static void addBookmark(String pdf, Section section, HashMap bookmark) {
    Section s = createBookmark(pdf, section, bookmark);
    ArrayList kids = (ArrayList) bookmark.get("Kids");
    if (kids == null) return;
    for (Iterator i = kids.iterator(); i.hasNext(); ) {
      addBookmark(pdf, s, (HashMap)i.next());
    }
View Full Code Here

TOP

Related Classes of com.lowagie.text.Section

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.