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;
  }
Example #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();
  }
 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);
 }
Example #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;
  }
  private void addIngredient(Yeast yeast, Document document) throws DocumentException {
    Image image = loadDrawable(R.drawable.yeast_cap, 30);

    Paragraph namePara = new Paragraph();
    namePara.setSpacingBefore(0);
    namePara.add(new Phrase("1 Pkg. " + yeast.getName() + "\n", NORMAL_FONT));
    namePara.add(new Phrase("\n", new Font(Font.FontFamily.TIMES_ROMAN, 2)));
    namePara.add(new Phrase(IngredientInfo.getInfo(yeast), SMALL_FONT));

    PdfPTable table = new PdfPTable(new float[] {40, 400});
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cellOne = new PdfPCell(image);
    cellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell cellTwo = new PdfPCell(namePara);
    cellTwo.setBorder(Rectangle.NO_BORDER);

    table.addCell(cellOne);
    table.addCell(cellTwo);
    document.add(table);
  }
  public PDFCreator(
      String name,
      String amount,
      String procedure,
      String dateIssued,
      String chargeDate,
      int patient_ID,
      int billing_ID) {

    this.name = name;
    this.amount = amount;
    this.procedure = procedure;
    this.dateIssued = dateIssued;
    this.chargeDate = chargeDate;
    this.patient_ID = patient_ID;
    this.billing_ID = billing_ID;

    Document document = new Document();
    try {
      PdfWriter writer =
          PdfWriter.getInstance(document, new FileOutputStream("Bill" + billing_ID + ".pdf"));
      document.open();

      /*     PdfPTable table = new PdfPTable(4); // 3 columns.
           table.setWidthPercentage(100); //Width 100%
           table.setSpacingBefore(10f); //Space before table
           table.setSpacingAfter(10f); //Space after table

           //Set Column widths
           float[] columnWidths = {1f, 1f, 1f, 1f};
           table.setWidths(columnWidths);

           PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
           cell1.setBorderColor(BaseColor.BLUE);
           cell1.setPaddingLeft(10);
           cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

           PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
           cell2.setBorderColor(BaseColor.GREEN);
           cell2.setPaddingLeft(10);
           cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

           PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
           cell3.setBorderColor(BaseColor.RED);
           cell3.setPaddingLeft(10);
           cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);



           //To avoid having the cell border and the content overlap, if you are having thick cell borders
           //cell1.setUserBorderPadding(true);
           //cell2.setUserBorderPadding(true);
           //cell3.setUserBorderPadding(true);

           table.addCell(cell1);
           table.addCell(cell2);
           table.addCell(cell3);
           table.addCell("cell 4");
           table.addCell("Cell 5");
      */

      // Add Image
      Image image1 = Image.getInstance("Pictures\\Logo.PNG");
      // Fixed Positioning
      image1.setAbsolutePosition(150f, 750f);
      image1.scaleAbsolute(image1.getScaledWidth() / 2, image1.getScaledHeight() / 2);

      // Scale to new height and new width of image
      // image1.scaleAbsolute(500, 200);

      // Add to document
      document.add(image1);

      Paragraph companyInfo =
          new Paragraph(
              "Nimbus Clinical Management \n8421 West Forest Drive,\nFayetteville, Arkansas, 72701\n555-382-9876\n12/31/2016");
      companyInfo.setSpacingBefore(55f);
      companyInfo.setSpacingAfter(10f);

      Paragraph billingInvoice = new Paragraph("Billing Invoice");
      billingInvoice.setAlignment(Element.ALIGN_CENTER);

      document.add(companyInfo);
      document.add(billingInvoice);
      // document.add(paragraphTable1);
      document.add(createFirstTable());

      document.close();
      writer.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void addRecipeInfo(Document document) throws DocumentException {
    int iconRes = mRecipe.getStyle().getIconDrawable();
    Image image = loadDrawable(iconRes, 40);

    Paragraph namePara = new Paragraph();
    namePara.setSpacingBefore(0);
    namePara.add(new Phrase(mRecipe.getName() + "\n", HEADER_FONT));
    namePara.add(new Phrase("\n", new Font(Font.FontFamily.TIMES_ROMAN, 2)));
    namePara.add(new Phrase(mRecipe.getStyle().getDisplayName(), SMALL_FONT));

    PdfPTable table = new PdfPTable(new float[] {50, 400});
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cellOne = new PdfPCell(image);
    cellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell cellTwo = new PdfPCell(namePara);
    cellTwo.setBorder(Rectangle.NO_BORDER);

    table.addCell(cellOne);
    table.addCell(cellTwo);
    document.add(table);

    addLineSeparator(document);

    Paragraph setupPara = new Paragraph();
    setupPara.add(
        new Phrase(
            "Batch Volume: " + mConverter.fromGallonsWithUnits(mRecipe.getBatchVolume(), 1),
            NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Boil Volume: " + mConverter.fromGallonsWithUnits(mRecipe.getBoilVolume(), 1),
            NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Boil Time: " + Util.fromDouble(mRecipe.getBoilTime(), 0) + " minutes", NORMAL_FONT));
    setupPara.add(new Phrase("\n\n", SPACING_FONT));
    setupPara.add(
        new Phrase(
            "Efficiency: " + Util.fromDouble(mRecipe.getEfficiency(), 1) + "%", NORMAL_FONT));

    Paragraph para = new Paragraph();
    String og = "";
    switch (mSettings.getExtractUnits()) {
      case SPECIFIC_GRAVITY:
        og = Util.fromDouble(mRecipe.getOg(), 3, false);
        break;
      case DEGREES_PLATO:
        og = Util.fromDouble(mRecipe.getOgPlato(), 1, false) + "°P";
        break;
    }
    para.add(new Phrase("OG: " + og, NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    para.add(new Phrase("IBU: " + Util.fromDouble(mRecipe.getTotalIbu(), 1), NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));
    para.add(new Phrase("SRM: " + Util.fromDouble(mRecipe.getSrm(), 1), NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    String fg = "n/a";
    if (mRecipe.hasYeast()) {
      switch (mSettings.getExtractUnits()) {
        case SPECIFIC_GRAVITY:
          fg = Util.fromDouble(mRecipe.getFg(), 3, false);
          break;
        case DEGREES_PLATO:
          fg = Util.fromDouble(mRecipe.getFgPlato(), 1, false) + "°P";
          break;
      }
    }
    para.add(new Phrase("Estimated FG: " + fg, NORMAL_FONT));
    para.add(new Phrase("\n\n", SPACING_FONT));

    String abv = "n/a";
    if (mRecipe.hasYeast()) {
      abv = Util.fromDouble(mRecipe.getAbv(), 1) + "%";
    }
    para.add(new Phrase("Estimated ABV: " + abv, NORMAL_FONT));

    PdfPTable statsTable = new PdfPTable(new float[] {200, 200});
    statsTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell statsCellOne = new PdfPCell(para);
    statsCellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell statsCellTwo = new PdfPCell(setupPara);
    statsCellTwo.setBorder(Rectangle.NO_BORDER);

    statsTable.addCell(statsCellOne);
    statsTable.addCell(statsCellTwo);
    document.add(statsTable);
  }