public ColumnText generateTableOfContent(ITextContext context) {
    ColumnText ct = new ColumnText(null);

    Styles styles = context.styles();
    Chunk CONNECT = connectChunk(styles);
    Paragraph paragraph = new Paragraph();
    paragraph.setSpacingBefore(20.0f); // first paragraph only

    ct.addElement(new Paragraph("Table of content", styles.sectionTitleFontForLevel(1)));
    ct.addElement(new Paragraph(""));

    Font entryFont = styles.getFontOrDefault(TOC_ENTRY_FONT);
    TableOfContents tableOfContents = context.tableOfContents();
    for (TableOfContents.Entry entry : tableOfContents.getEntries()) {
      // if (entry.isExtra())
      //    continue;

      Chunk chunk = new Chunk(entry.getText(), entryFont);
      paragraph.add(chunk);
      paragraph.add(CONNECT);
      paragraph.add(new Chunk("" + entry.getFormattedPageNumber(), entryFont));

      float indent = 10.0f * entry.getLevel();
      paragraph.setIndentationLeft(indent);

      ct.addElement(paragraph);
      paragraph = new Paragraph();
    }
    return ct;
  }
예제 #2
0
  public static void main(String[] args) throws FileNotFoundException, DocumentException {
    Document document = new Document();
    @SuppressWarnings("unused")
    PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
    document.open();

    Paragraph paragraph1 = new Paragraph("This is Paragraph 1");
    Paragraph paragraph2 = new Paragraph("This is Paragraph 2");
    paragraph1.setIndentationLeft(80);
    paragraph1.setIndentationRight(80);
    paragraph1.setAlignment(Element.ALIGN_CENTER);
    paragraph1.setSpacingAfter(15);
    paragraph2.setSpacingBefore(15);
    paragraph2.setAlignment(Element.ALIGN_LEFT);
    Phrase phrase = new Phrase("This is a large sentence.");
    for (int count = 0; count < 10; count++) {
      paragraph1.add(phrase);
      paragraph2.add(phrase);
    }

    document.add(paragraph1);
    document.add(paragraph2);

    document.close();
  }
예제 #3
0
 private void addHeader(Document document) throws Exception {
   Image image = loadDrawable(R.drawable.ic_launcher, 26);
   Paragraph para = new Paragraph();
   para.setAlignment(Element.ALIGN_CENTER);
   para.setIndentationLeft(20);
   para.setIndentationRight(20);
   para.setSpacingBefore(0);
   para.setSpacingAfter(24);
   para.add(new Chunk(image, 0, 0));
   para.add(new Phrase(" ", TITLE_FONT));
   para.add(new Phrase(mContext.getString(R.string.brew_shop_recipe), TITLE_FONT));
   para.add(new Phrase(" ", TITLE_FONT));
   para.add(new Chunk(image, 0, 0));
   document.add(para);
 }
예제 #4
0
  private static Paragraph createCleanParagraph(String txt1, float fontSize1, boolean bold1) {
    Phrase phrase = new Phrase(txt1);
    phrase.getFont().setSize(fontSize1);
    if (bold1) {
      phrase.getFont().setStyle(Font.BOLD);
      phrase.setLeading(fontSize1);
    }
    Paragraph paragraph = new Paragraph(phrase);

    paragraph.setLeading(fontSize1);
    paragraph.setSpacingBefore(0);
    paragraph.setSpacingAfter(0);
    paragraph.setExtraParagraphSpace(0);
    paragraph.setFirstLineIndent(0);
    paragraph.setIndentationLeft(0);
    paragraph.setIndentationRight(0);
    paragraph.setAlignment(Rectangle.ALIGN_CENTER);

    return paragraph;
  }