示例#1
0
  public void setHeader(Document document, String clientName)
      throws DocumentException, IOException {

    LineSeparator line = new LineSeparator(1, 80, null, Element.ALIGN_CENTER, -5);

    Image img = Image.getInstance(getClass().getResource("img/LISLogo.png"));
    // Image img = Image.getInstance("img/LISLogo.png");
    img.scaleAbsoluteHeight(80);
    img.scaleAbsoluteWidth(200);
    img.setAlignment(Element.ALIGN_CENTER);

    Paragraph clientNameParagraph = new Paragraph();
    clientNameParagraph.setAlignment(Element.ALIGN_CENTER);
    clientNameParagraph.add(clientName);
    clientNameParagraph.setSpacingAfter(12);

    Paragraph investmentRecommendations = new Paragraph("Your Legacy Investment Income Portfolio");
    investmentRecommendations.setAlignment(Element.ALIGN_CENTER);
    investmentRecommendations.add(line);
    investmentRecommendations.setSpacingAfter(4);

    document.add(clientNameParagraph);
    document.add(investmentRecommendations);
    document.add(img);
  }
示例#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
  public void print(String filename) throws IOException, DocumentException {
    EventTree tree = app.getTimelines().getCurrentTree();
    if (tree == null || tree.isEmpty()) return;

    ComplexEvent parent = tree.getTopSelectionParent();
    if (parent == null) return;

    // Instantiation of document object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    // Creation of PdfWriter object
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();

    // Creation of table
    Paragraph title =
        new Paragraph(
            "A sample output from Zeitline:",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 14, BaseColor.BLUE));
    title.setSpacingAfter(20);
    document.add(title);

    // Setting width rations
    PdfPTable table = new PdfPTable(3);
    float[] tableWidth = {(float) 0.2, (float) 0.12, (float) 0.68};
    table.setWidths(tableWidth);

    // Setting the header
    java.util.List<PdfPCell> headerCells =
        asList(getHeaderCell("Date"), getHeaderCell("MACB"), getHeaderCell("Short Description"));

    for (PdfPCell cell : headerCells) table.addCell(cell);

    // Setting the body
    int max = parent.countChildren();
    for (int i = 0; i < max; i++) {
      AbstractTimeEvent entry = parent.getEventByIndex(i);
      table.addCell(getBodyCell(entry.getStartTime().toString()));

      String name = entry.getName();
      if (name != null && name.length() > 5) {
        String macb = name.substring(0, 4);
        String desc = name.substring(5);

        table.addCell(getBodyCell(macb));
        table.addCell(getBodyCell(desc));
      } else {
        table.addCell("");
        table.addCell("");
      }
    }
    document.add(table);

    // Closure
    document.close();
    writer.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);
 }
示例#5
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;
  }
  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 static Document ESingnature(
      Document document, PdfWriter writer, AddressBook addressbook) {
    // TODO Auto-generated method stub
    log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature ");
    try {

      document.newPage();

      PdfPTable table = new PdfPTable(2);
      table.setSpacingBefore(10);
      table.setWidthPercentage(100f);

      PdfPCell c1 = new PdfPCell(new Phrase("E-singnature "));
      c1.setHorizontalAlignment(Element.ALIGN_LEFT);
      c1.setColspan(4);
      c1.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP);
      c1.setFixedHeight(30f);
      c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
      c1.setBorder(Rectangle.BOX);
      c1.setFixedHeight(25f);
      table.addCell(c1);
      table.setHeaderRows(1);

      for (int i = 0; i < 2; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      Iterator itr = null;
      CandidateESignature esignature = new CandidateESignature();
      if (addressbook.getCandidateESignatures().size() > 0) {
        itr = addressbook.getCandidateESignatures().iterator();
        esignature = (CandidateESignature) itr.next();
      }

      c1 = new PdfPCell(new Phrase("Branch : " + esignature.getBranch(), font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      c1.setBorder(Rectangle.BOTTOM);
      table.addCell(c1);

      c1 =
          new PdfPCell(
              new Phrase("Servicing Department : " + esignature.getServiceDepartment(), font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      c1.setBorder(Rectangle.BOTTOM);
      table.addCell(c1);

      for (int i = 0; i < 2; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 = new PdfPCell(new Phrase("City : " + esignature.getCity(), font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      c1.setBorder(Rectangle.BOTTOM);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Agent Code : " + esignature.getAgentId(), font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      c1.setBorder(Rectangle.BOTTOM);
      table.addCell(c1);

      for (int i = 0; i < 4; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      document.add(table);

      table = new PdfPTable(2);
      table.setSpacingBefore(10);
      table.setWidthPercentage(100f);
      table.setWidths(new int[] {80, 20});

      c1 = new PdfPCell(new Phrase("Presently attached with another insurance Company ?  ", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      for (int i = 0; i < 2; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 =
          new PdfPCell(
              new Phrase(
                  "Presently in contact with any other AIA'S servicing Department ?   ", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      for (int i = 0; i < 2; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 =
          new PdfPCell(
              new Phrase(
                  "Taken LOMBRA occupational test or PSP test in the past ?  If Yes, ", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Yes \t\t\t\t\t\t\t\t  No", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      for (int i = 0; i < 2; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 = new PdfPCell(new Phrase("Please provide the result.  ", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      for (int i = 0; i < 5; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }
      document.add(table);

      Paragraph para1 = new Paragraph();
      para1.add(new Chunk("Applicant's Declaration ", font));
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setSpacingAfter(5f);
      document.add(para1);

      table = new PdfPTable(2);
      table.setSpacingBefore(10);
      table.setWidthPercentage(100f);

      for (int i = 0; i < 4; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 = new PdfPCell(new Phrase("Application Date", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      c1 = new PdfPCell(new Phrase("Applicant/Candidate Name  :", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      if (esignature.getApplicationDate() != null) {
        c1 = new PdfPCell(new Phrase(format.format(esignature.getApplicationDate()), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      } else {
        c1 = new PdfPCell(new Phrase("", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }

      c1 = new PdfPCell(new Phrase(esignature.getCandidateName(), font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      for (int i = 0; i < 4; i++) {
        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setLeading(4f, 0f);
        c1.setFixedHeight(15f);
        table.addCell(c1);
      }
      document.add(table);

      para1 = new Paragraph();
      para1.add(new Chunk("E-Signature  : ", font));
      para1.setAlignment(Element.ALIGN_LEFT);
      para1.setSpacingAfter(5f);
      document.add(para1);

      c1 = new PdfPCell(new Phrase(" ", font));
      c1.setBorder(Rectangle.NO_BORDER);
      c1.setLeading(4f, 0f);
      c1.setFixedHeight(15f);
      table.addCell(c1);

      if (esignature.geteSignaturePhoto() != null) {
        Image image = Image.getInstance(esignature.geteSignaturePhoto());
        para1 = new Paragraph();
        para1.add(image);
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);
      } else {
        para1 = new Paragraph();
        para1.add("");
        para1.setAlignment(Element.ALIGN_LEFT);
        para1.setSpacingAfter(5f);
        document.add(para1);
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      log.log(Level.INFO, "ApplicationFormPDFMaintenance --> ESingnature " + e.getMessage());
      e.printStackTrace();
      e.printStackTrace();
      LogsMaintenance logsMain = new LogsMaintenance();
      StringWriter errors = new StringWriter();
      e.printStackTrace(new PrintWriter(errors));
      logsMain.insertLogs("ApplicationFormPDFMaintenance", Level.SEVERE + "", errors.toString());
    }

    return document;
  }