Package com.itextpdf.text

Examples of com.itextpdf.text.Font


    Document document = null;

    try {
      BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250,
          BaseFont.EMBEDDED);
      Font f = new Font(bf, 12, Font.NORMAL);

      document = new Document(PageSize.A4, 10, 10, 50, 50);
      PdfWriter instance = PdfWriter.getInstance(document, os);
      document.open();
View Full Code Here


                    float x = (rect.getWidth() - w) / 2;
                    float y = (rect.getHeight() - h) / 2;
                    t.addImage(image, w, 0, 0, h, x, y);
                }
            }
            Font font;
            if (layer2Font == null)
                font = new Font();
            else
                font = new Font(layer2Font);
            float size = font.getSize();

            Rectangle dataRect = null;
            Rectangle signatureRect = null;

            if (renderingMode == RenderingMode.NAME_AND_DESCRIPTION ||
                renderingMode == RenderingMode.GRAPHIC_AND_DESCRIPTION && this.signatureGraphic != null) {
                // origin is the bottom-left
                signatureRect = new Rectangle(
                    MARGIN,
                    MARGIN,
                    rect.getWidth() / 2 - MARGIN,
                    rect.getHeight() - MARGIN);
                dataRect = new Rectangle(
                    rect.getWidth() / 2 +  MARGIN / 2,
                    MARGIN,
                    rect.getWidth() - MARGIN / 2,
                    rect.getHeight() - MARGIN);

                if (rect.getHeight() > rect.getWidth()) {
                    signatureRect = new Rectangle(
                        MARGIN,
                        rect.getHeight() / 2,
                        rect.getWidth() - MARGIN,
                        rect.getHeight());
                    dataRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.getWidth() - MARGIN,
                        rect.getHeight() / 2 - MARGIN);
                }
            }
            else if (renderingMode == RenderingMode.GRAPHIC) {
                if (signatureGraphic == null) {
                    throw new IllegalStateException(MessageLocalization.getComposedMessage("a.signature.image.should.be.present.when.rendering.mode.is.graphic.only"));
                }
                signatureRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.getWidth() - MARGIN, // take all space available
                        rect.getHeight() - MARGIN);
            }
            else {
                dataRect = new Rectangle(
                        MARGIN,
                        MARGIN,
                        rect.getWidth() - MARGIN,
                        rect.getHeight() * (1 - TOP_SECTION) - MARGIN);
            }

            switch (renderingMode) {
            case NAME_AND_DESCRIPTION:
                String signedBy = CertificateInfo.getSubjectFields((X509Certificate)signCertificate).getField("CN");
                if (signedBy == null)
                    signedBy = CertificateInfo.getSubjectFields((X509Certificate)signCertificate).getField("E");
                if (signedBy == null)
                    signedBy = "";
                Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN );
                float signedSize = ColumnText.fitText(font, signedBy, sr2, -1, runDirection);

                ColumnText ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT);

                ct2.go();
                break;
            case GRAPHIC_AND_DESCRIPTION:
                if (signatureGraphic == null) {
                    throw new IllegalStateException(MessageLocalization.getComposedMessage("a.signature.image.should.be.present.when.rendering.mode.is.graphic.and.description"));
                }
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                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();
                break;
            case GRAPHIC:
                ct2 = new ColumnText(t);
                ct2.setRunDirection(runDirection);
                ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);

                im = Image.getInstance(signatureGraphic);
                im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());

                p = new Paragraph(signatureRect.getHeight());
                // must calculate the point to draw from to make image appear in middle of column
                x = (signatureRect.getWidth() - im.getScaledWidth()) / 2;
                y = (signatureRect.getHeight() - im.getScaledHeight()) / 2;
                p.add(new Chunk(im, x, y, false));
                ct2.addElement(p);
                ct2.go();
                break;
            default:
            }

            if(renderingMode != RenderingMode.GRAPHIC) {
              if (size <= 0) {
                    Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight());
                    size = ColumnText.fitText(font, text, sr, 12, runDirection);
                }
                ColumnText ct = new ColumnText(t);
                ct.setRunDirection(runDirection);
                ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT);
                ct.go();
            }
        }
        if (app[3] == null && !acro6Layers) {
            PdfTemplate t = app[3] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(100, 100));
            writer.addDirectTemplateSimple(t, new PdfName("n3"));
            t.setLiteral("% DSBlank\n");
        }
        if (app[4] == null && !acro6Layers) {
            PdfTemplate t = app[4] = new PdfTemplate(writer);
            t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), rect.getRight(), rect.getTop()));
            writer.addDirectTemplateSimple(t, new PdfName("n4"));
            Font font;
            if (layer2Font == null)
                font = new Font();
            else
                font = new Font(layer2Font);
            //float size = font.getSize();
            String text = "Signature Not Verified";
            if (layer4Text != null)
                text = layer4Text;
            Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, rect.getHeight() * TOP_SECTION - 2 * MARGIN);
 
View Full Code Here

    }

    private Phrase composePhrase(String text, BaseFont ufont, BaseColor color, float fontSize) {
        Phrase phrase = null;
        if (extensionFont == null && (substitutionFonts == null || substitutionFonts.isEmpty()))
            phrase = new Phrase(new Chunk(text, new Font(ufont, fontSize, 0, color)));
        else {
            FontSelector fs = new FontSelector();
            fs.addFont(new Font(ufont, fontSize, 0, color));
            if (extensionFont != null)
                fs.addFont(new Font(extensionFont, fontSize, 0, color));
            if (substitutionFonts != null) {
                for (int k = 0; k < substitutionFonts.size(); ++k)
                    fs.addFont(new Font(substitutionFonts.get(k), fontSize, 0, color));
            }
            phrase = fs.process(text);
        }
        return phrase;
    }
View Full Code Here

      response.setHeader("Content-Disposition", "inline; filename=" + module + ".pdf"); // TODO add more information about the entity into the filename.

      final Dto dto = readService.get(module, id);
      final ModuleDto moduleDto = config.getModuleDtos().get(module);

      document.add(new Paragraph(moduleDto.getTitle(), new Font(FontFamily.HELVETICA, 20, Font.BOLD)));
     
      for (final Entry<String, Serializable> entry : dto.getAllData().entrySet()) {
        if ("id".equals(entry.getKey()) || entry.getKey().endsWith("_resolved")) {
          continue;
        }
        final String label = moduleDto.getFieldById(entry.getKey()).getLabel();
        final String value;
       
        if (dto.getAllData().containsKey(entry.getKey() + "_resolved")) {
          final Dto resolved = (Dto) dto.getAllData().get(entry.getKey() + "_resolved");
          value = String.valueOf(resolved.get("name"));
        } else {
          value = null == entry.getValue() ? "-" : String.valueOf(entry.getValue());
        }

        if (entry.getValue() instanceof List<?>) {
          if (!((List<?>)entry.getValue() ).isEmpty()) {
            final List<Dto> list = (List<Dto>) entry.getValue();
            final ModuleDto listModuleDto = config.getModuleDtos().get(list.get(0).getModule());
           
            PdfPTable table = new PdfPTable(listModuleDto.getListFieldIds().length);
            table.setHeaderRows(1);

            for (final String col: listModuleDto.getListFieldIds()) {
              final String colHeader = listModuleDto.getFieldById(col).getLabel();
              table.addCell(new Phrase(colHeader, new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
            }
           
            for (int i = 0; i < list.size(); i++) {
              for (final String col: listModuleDto.getListFieldIds()) {
                final String colValue;
               
                if (list.get(i).getAllData().containsKey(col + "_resolved")) {
                  final Dto resolved = (Dto) list.get(i).get(col + "_resolved");
                  colValue = String.valueOf(resolved.get("name"));
                } else {
                  colValue = String.valueOf(list.get(i).get(col));
                }

                if ("true".equals(colValue) || "false".equals(colValue)) {
                  // final RadioCheckField r = new RadioCheckField(writer, new Rectangle(10, 10, 20, 20), "asd", "v1");
                  // r.setChecked("true".equals(colValue));
                  table.addCell(new Phrase("true".equals(colValue) ? "X" : ""));
                } else {
                  table.addCell(new Phrase(colValue));
                }
              }
            }
           
            document.add(new Chunk(label, new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
            document.add(new Chunk(Chunk.NEWLINE));
            document.add(table);
            document.add(new Chunk(Chunk.NEWLINE));
          }
        } else {
View Full Code Here

    }
  }

  protected Element getAttributeParagraph(final String key, final String value) {
    final Paragraph p = new Paragraph();
    p.add(new Chunk(key + ": ", new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
    p.add(new Chunk(value));
    return p;
  }
View Full Code Here

            os = new FileOutputStream("Relatório iCards.pdf");//cria a stream de saída

            PdfWriter.getInstance(doc, os); //associa a stream de saída ao

            doc.open(); //abre o documento
            Font fonte2 = new Font(FontFamily.HELVETICA, 24,Font.BOLD);
            Font fonte = new Font(FontFamily.HELVETICA, 16,Font.BOLD);
            Paragraph title = new Paragraph("Relatório iCards",fonte2); //adiciona o texto ao PDF
            title.setAlignment(Element.ALIGN_CENTER);
            title.setSpacingAfter(5);
            Paragraph linha = new Paragraph("__________________________________________________",fonte);
            doc.add(linha);
View Full Code Here

   * @param content the content of the Chunk
   * @param chain the hierarchy chain
   * @return a Chunk
   */
  public Chunk createChunk(final String content, final ChainedProperties chain) {
    Font font = getFont(chain);
    Chunk ck = new Chunk(content, font);
    if (chain.hasProperty(HtmlTags.SUB))
      ck.setTextRise(-font.getSize() / 2);
    else if (chain.hasProperty(HtmlTags.SUP))
      ck.setTextRise(font.getSize() / 2);
    ck.setHyphenation(getHyphenation(chain));
    return ck;
  }
View Full Code Here

  }
  public void align(int col, String alignment) { alignments[col] = alignment;  }

  private int cellcount = 0;
  public void cell(int colspan, String txt, String align) {
    Font f = new Font(fontfamily, fontsize, fontstyle);
    PdfPCell c = new PdfPCell(new Phrase(txt,f));
    int col = cellcount % alignments.length;
    String al = alignments[col];
    if (al != null) {
      //print("align: " + col + " " + al);
View Full Code Here

        tabla = new PdfPTable(headers.length);
        for (int i = 0; i < headers.length; i++) {
          String header = headers[i];
          PdfPCell cell = new PdfPCell();
          cell.setGrayFill(0.9f);
          cell.setPhrase(new Phrase(header.toUpperCase(), new Font(
              FontFamily.HELVETICA, 10, Font.BOLD)));
          tabla.addCell(cell);
        }
        tabla.completeRow();

        while (iteNovedades.hasNext()) {
          BitacoraLN falla = iteNovedades.next();
          PdfPCell cell0 = new PdfPCell();
          PdfPCell cell1 = new PdfPCell();
          PdfPCell cell2 = new PdfPCell();

          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          String fecha = sdf.format(falla.getFecha());
          cell0.setPhrase(new Phrase(fecha, new Font(
              FontFamily.HELVETICA, 10, Font.NORMAL)));
          cell1.setPhrase(new Phrase(falla.getEquipoNombre(),
              new Font(FontFamily.HELVETICA, 10, Font.NORMAL)));
          cell2.setPhrase(new Phrase(falla.getComentario().getValue(), new Font(
              FontFamily.HELVETICA, 10, Font.NORMAL)));
          tabla.addCell(cell0);
          tabla.addCell(cell1);
          tabla.addCell(cell2);
          tabla.completeRow();
View Full Code Here

          for (int i = 0; i < headers.length; i++) {
            String header = headers[i];
            PdfPCell cell = new PdfPCell();
            cell.setGrayFill(0.9f);
            cell.setPhrase(new Phrase(header.toUpperCase(),
                new Font(FontFamily.HELVETICA, 10, Font.BOLD)));
            tabla.addCell(cell);
          }
          tabla.completeRow();
          while (iteNovedadesfallas.hasNext()) {

            BitacoraLN bitacora = iteNovedadesfallas.next();
            PdfPCell cell0 = new PdfPCell();
            PdfPCell cell1 = new PdfPCell();
            PdfPCell cell2 = new PdfPCell();
            PdfPCell cell3 = new PdfPCell();
            PdfPCell cell4 = new PdfPCell();
            SimpleDateFormat sdf = new SimpleDateFormat(
                "dd/MM/yyyy");
            String fecha = sdf.format(bitacora.getFecha());
            cell0.setPhrase(new Phrase(fecha, new Font(
                FontFamily.HELVETICA, 8, Font.NORMAL)));
            if (bitacora.getUsuarioNombre() != null) {
              cell1.setPhrase(new Phrase(bitacora
                  .getUsuarioNombre(), new Font(
                  FontFamily.HELVETICA, 8, Font.NORMAL)));
            } else {
              cell1.setPhrase(new Phrase("", new Font(
                  FontFamily.HELVETICA, 8, Font.NORMAL)));
            }
            cell2.setPhrase(new Phrase(bitacora.getTurnoNombre(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            cell3.setPhrase(new Phrase(bitacora.getEquipoNombre(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            cell4.setPhrase(new Phrase(bitacora.getComentario().getValue(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            tabla.addCell(cell0);
            tabla.addCell(cell1);
            tabla.addCell(cell2);
            tabla.addCell(cell3);
            tabla.addCell(cell4);
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Font

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.