Esempio n. 1
0
 public int compareTo(Font font) {
   if (font == null) {
     return -1;
   }
   if (baseFont != null && !baseFont.equals(font.getBaseFont())) {
     return -2;
   }
   if (this.family != font.getFamily()) {
     return 1;
   }
   if (this.size != font.getSize()) {
     return 2;
   }
   if (this.style != font.getStyle()) {
     return 3;
   }
   if (this.color == null) {
     if (font.color == null) {
       return 0;
     }
     return 4;
   }
   if (font.color == null) {
     return 4;
   }
   if (this.color.equals(font.getColor())) {
     return 0;
   }
   return 4;
 }
 public PdfPCell printStrTopLine(
     String text, int colspan, int fontsize, boolean bold, boolean border, int align) {
   try {
     if (text == null) text = "";
     Paragraph p = new Paragraph();
     float padding = 3.0f;
     // set bold feature
     if (bold) {
       p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD)));
       padding = 3.0f;
     } else p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize)));
     PdfPCell cell = new PdfPCell(p);
     // set colspan feature
     cell.setColspan(colspan);
     // set alignment feature
     if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT);
     else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER);
     else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT);
     // set border feature
     cell.setBorder(cell.NO_BORDER);
     cell.setBorder(cell.TOP);
     cell.setPaddingBottom(padding);
     return cell;
   } catch (Exception e) {
     return null;
   }
 }
Esempio n. 3
0
 protected Paragraph rightPara(final float size, final Object value) {
   final Font font = new Font();
   font.setSize(size);
   final Paragraph header = new Paragraph(value == null ? "" : value.toString(), font);
   header.setAlignment(Element.ALIGN_RIGHT);
   return header;
 }
 public void encode(
     PdfContentByte directContent,
     IGenericCharacter character,
     IGenericDescription description,
     Bounds bounds)
     throws DocumentException {
   IVirtueFlaw resonance =
       ((IVirtueFlawModel) character.getAdditionalModel(AbyssalResonanceTemplate.ID))
           .getVirtueFlaw();
   Bounds textBounds =
       traitEncoder.encode(directContent, bounds, resonance.getLimitTrait().getCurrentValue());
   Font font = createFont(getBaseFont());
   Font nameFont = createNameFont(getBaseFont());
   Phrase phrase = new Phrase("", font); // $NON-NLS-1$
   phrase.add(
       new Chunk(
           resources.getString("Sheet.GreatCurse.FlawedVirtue") + ": ",
           nameFont)); //$NON-NLS-1$ //$NON-NLS-2$
   if (resonance.isFlawComplete()) {
     phrase.add(resonance.getRoot().getId() + ".\n");
   } else {
     Font undefinedFont = new Font(font);
     undefinedFont.setStyle(Font.UNDERLINE);
     phrase.add(
         new Chunk("                                          ", undefinedFont)); // $NON-NLS-1$
     phrase.add(".\n");
   }
   phrase.add(resources.getString("Sheet.GreatCurse.ResonanceReference")); // $NON-NLS-1$
   encodeTextWithReducedLineHeight(directContent, textBounds, phrase);
 }
Esempio n. 5
0
 private static Element newPara(String text, int alignment, int type) {
   Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK);
   Paragraph p = new Paragraph(text, font);
   p.setAlignment(alignment);
   p.setLeading(font.getSize() * 1.2f);
   return p;
 }
Esempio n. 6
0
 protected Paragraph makeParaWithFont(
     final float fontSize, final Object value, final int alignment) {
   final Font font = new Font();
   font.setSize(fontSize);
   final Paragraph header = new Paragraph(value == null ? "" : value.toString(), font);
   header.setAlignment(alignment);
   return header;
 }
Esempio n. 7
0
 @SuppressWarnings("serial")
 public float medidorFonte(String x) {
   // System.out.println("trecho:"+x+" , tamanho da string é:"+tamanho);
   float tamanho =
       fonteLetraEmUso
           .getCalculatedBaseFont(true)
           .getWidthPoint(x, fonteLetraEmUso.getCalculatedSize());
   return tamanho;
 }
Esempio n. 8
0
 /**
  * Process the text so that it will render with a combination of fonts if needed.
  *
  * @param text the text
  * @return a <CODE>Phrase</CODE> with one or more chunks
  */
 public Phrase process(String text) {
   int fsize = fonts.size();
   if (fsize == 0) throw new IndexOutOfBoundsException("No font is defined.");
   char cc[] = text.toCharArray();
   int len = cc.length;
   StringBuffer sb = new StringBuffer();
   Font font = null;
   int lastidx = -1;
   Phrase ret = new Phrase();
   for (int k = 0; k < len; ++k) {
     char c = cc[k];
     if (c == '\n' || c == '\r') {
       sb.append(c);
       continue;
     }
     if (Utilities.isSurrogatePair(cc, k)) {
       int u = Utilities.convertToUtf32(cc, k);
       for (int f = 0; f < fsize; ++f) {
         font = (Font) fonts.get(f);
         if (font.getBaseFont().charExists(u)) {
           if (lastidx != f) {
             if (sb.length() > 0 && lastidx != -1) {
               Chunk ck = new Chunk(sb.toString(), (Font) fonts.get(lastidx));
               ret.add(ck);
               sb.setLength(0);
             }
             lastidx = f;
           }
           sb.append(c);
           sb.append(cc[++k]);
           break;
         }
       }
     } else {
       for (int f = 0; f < fsize; ++f) {
         font = (Font) fonts.get(f);
         if (font.getBaseFont().charExists(c)) {
           if (lastidx != f) {
             if (sb.length() > 0 && lastidx != -1) {
               Chunk ck = new Chunk(sb.toString(), (Font) fonts.get(lastidx));
               ret.add(ck);
               sb.setLength(0);
             }
             lastidx = f;
           }
           sb.append(c);
           break;
         }
       }
     }
   }
   if (sb.length() > 0) {
     Chunk ck = new Chunk(sb.toString(), (Font) fonts.get(lastidx == -1 ? 0 : lastidx));
     ret.add(ck);
   }
   return ret;
 }
Esempio n. 9
0
 /**
  * Adds a <CODE>Font</CODE> to be searched for valid characters.
  *
  * @param font the <CODE>Font</CODE>
  */
 public void addFont(Font font) {
   System.out.println("i'm add font inside woowoo");
   if (font.getBaseFont() != null) {
     fonts.add(font);
     return;
   }
   BaseFont bf = font.getCalculatedBaseFont(true);
   Font f2 = new Font(bf, font.getSize(), font.getCalculatedStyle(), font.getColor());
   fonts.add(f2);
 }
Esempio n. 10
0
 private Font getFont(FormCell formCell) {
   Font font = pgInfo.getFontInfo().defaultF();
   if (formCell.getFont() != null) {
     font = formCell.getFont();
   }
   font = new Font(font);
   if (formCell.isBold()) {
     font.setStyle(Font.BOLD);
   } else {
     font.setStyle(Font.NORMAL);
   }
   return font;
 }
Esempio n. 11
0
 private void encodeOnlyConditionDefined(
     SheetGraphics graphics, VirtueFlawContent content, Bounds textBounds)
     throws DocumentException {
   Phrase phrase = new Phrase();
   Font undefinedFont = new Font(createNameFont(graphics));
   undefinedFont.setStyle(Font.UNDERLINE);
   phrase.add(
       new Chunk("                                          : ", undefinedFont)); // $NON-NLS-1$
   phrase.add(new Chunk(": ", createNameFont(graphics))); // $NON-NLS-1$
   phrase.add(new Chunk(content.getLimitBreakCondition(), createConditionFont(graphics)));
   graphics
       .createSimpleColumn(textBounds)
       .withLeading(REDUCED_LINE_HEIGHT)
       .andTextPart(phrase)
       .encode();
 }
  public void encode(SheetGraphics graphics, ReportContent reportContent, Bounds bounds) {
    tellMDV = hasTBA(reportContent.getCharacter()) ? 8 : 12;

    int offsetX = 0, offsetY = isHorizontal ? 0 : 5;
    font = graphics.createTableFont();

    if (isHorizontal) {
      bounds = new Bounds(bounds.x, bounds.y, bounds.width / 2, bounds.height);
      font.setSize(COMMENT_FONT_SIZE);
      lineHeight -= 2;
    }

    try {
      offsetY += writePowerNotes(graphics, "Shapeshifting", bounds, offsetX, offsetY);
      if (!reportContent.getCharacter().getTemplate().getTemplateType().equals(castelessType)) {
        offsetY += writePowerNotes(graphics, "Tattoos", bounds, offsetX, offsetY);
      }

      if (isHorizontal) {

        bounds = new Bounds(bounds.x + bounds.width, bounds.y, bounds.width, bounds.height);
        offsetY = 0;
      }

      offsetY += writePowerNotes(graphics, "Tell", bounds, offsetX, offsetY);
    } catch (DocumentException e) {
    }
  }
 private int writePowerNotes(
     SheetGraphics graphics, String power, Bounds bounds, int offsetX, int offsetY)
     throws DocumentException {
   Font boldFont = new Font(font);
   boldFont.setStyle(Font.BOLD);
   String text = resources.getString(powerBase + power);
   Phrase phrase = new Phrase(text, boldFont);
   int index = 0;
   int totalHeight = 0;
   while (!text.startsWith("##")) {
     Bounds newBounds =
         new Bounds(
             bounds.x + offsetX,
             bounds.y,
             bounds.width - offsetX,
             bounds.height - offsetY - totalHeight);
     totalHeight +=
         graphics
                 .createSimpleColumn(newBounds)
                 .withLeading(lineHeight)
                 .andTextPart(phrase)
                 .encode()
                 .getLinesWritten()
             * lineHeight;
     text = resources.getString(powerBase + power + (++index));
     text = text.replace("TELLMDV", "" + tellMDV);
     phrase = new Phrase(text, font);
   }
   if (!isHorizontal) {
     Bounds newBounds =
         new Bounds(
             bounds.x + offsetX,
             bounds.y + bounds.height - offsetY - totalHeight,
             bounds.x - offsetX,
             lineHeight);
     totalHeight +=
         graphics
                 .createSimpleColumn(newBounds)
                 .withLeading(lineHeight)
                 .andTextPart(new Phrase(" ", font))
                 .encode()
                 .getLinesWritten()
             * lineHeight;
   }
   return totalHeight;
 }
  public void getHeaderFooter(Document document) throws JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallRegular.setColor(tColor);

    java.util.Date dt = new java.util.Date();
    String dformat = "yyyy-MM-d";
    java.text.SimpleDateFormat dtf = new java.text.SimpleDateFormat(dformat);
    String DateStr = dtf.format(dt);

    // -------- header ----------------

    header = new PdfPTable(1);
    PdfPCell headerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    headerNotecell.setBorder(0);
    headerNotecell.setPaddingBottom(4);
    headerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    header.addCell(headerNotecell);

    PdfPCell headerSeparator = new PdfPCell(new Phrase(""));
    headerSeparator.setBorder(PdfPCell.BOX);
    headerSeparator.setPadding(0);
    headerSeparator.setColspan(1);
    header.addCell(headerSeparator);
    // -------- header end ----------------

    // -------- footer  -------------------
    footer = new PdfPTable(3);
    PdfPCell footerSeparator = new PdfPCell(new Phrase(""));
    footerSeparator.setBorder(PdfPCell.BOX);
    footerSeparator.setPadding(0);
    footerSeparator.setColspan(3);
    footer.addCell(footerSeparator);

    PdfPCell emptyCell = new PdfPCell(new Phrase("", fontSmallRegular));
    emptyCell.setBorder(0);
    emptyCell.setColspan(1);
    emptyCell.setHorizontalAlignment(PdfCell.ALIGN_LEFT);
    footer.addCell(emptyCell);

    PdfPCell footerNotecell = new PdfPCell(new Phrase("Project Summary Report", fontSmallRegular));
    footerNotecell.setBorder(0);
    footerNotecell.setColspan(1);
    footerNotecell.setHorizontalAlignment(PdfCell.ALIGN_CENTER);
    footer.addCell(footerNotecell);

    PdfPCell pagerDateCell = new PdfPCell(new Phrase(DateStr, fontSmallRegular));
    pagerDateCell.setBorder(0);
    pagerDateCell.setColspan(1);
    pagerDateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    footer.addCell(pagerDateCell);

    // -------- footer end   -----------
  }
Esempio n. 15
0
  /**
   * Replaces the attributes that are equal to <VAR>null</VAR> with the attributes of a given font.
   *
   * @param font the font of a bigger element class
   * @return a <CODE>Font</CODE>
   */
  public Font difference(Font font) {
    String dFamilyname = font.getFamilyname();
    if (dFamilyname == null || dFamilyname.trim().equals("")) {
      dFamilyname = this.familyName;
    }

    float dSize = font.size();
    if (dSize == Font.UNDEFINED) {
      dSize = this.size();
    }

    int dStyle = Font.UNDEFINED;
    if (this.style() != Font.UNDEFINED && font.style() != Font.UNDEFINED) {
      dStyle = this.style() | font.style();
    } else if (this.style() != Font.UNDEFINED) {
      dStyle = this.style();
    } else if (font.style() != Font.UNDEFINED) {
      dStyle = font.style();
    }

    Color dColor = font.color();
    if (dColor == null) {
      dColor = this.color();
    }

    return new RtfFont(dFamilyname, dSize, dStyle, dColor);
  }
Esempio n. 16
0
 public CostCalculationMaterial(
     String productNumber,
     String unit,
     BigDecimal productQuantity,
     BigDecimal costForGivenQuantity) {
   this.productNumber = productNumber;
   this.unit = unit;
   this.productQuantity = productQuantity;
   this.costForGivenQuantity = costForGivenQuantity;
   this.totalCost = costForGivenQuantity;
   this.toAdd = BigDecimal.ZERO;
   redFont = new Font(FontUtils.getDejavu(), 7);
   redFont.setColor(Color.RED);
 }
Esempio n. 17
0
  public Font difference(Font font) {
    if (font == null) return this;

    float dSize = font.size;
    if (dSize == UNDEFINED) {
      dSize = this.size;
    }

    int dStyle = UNDEFINED;
    int style1 = this.style;
    int style2 = font.getStyle();
    if (style1 != UNDEFINED || style2 != UNDEFINED) {
      if (style1 == UNDEFINED) style1 = 0;
      if (style2 == UNDEFINED) style2 = 0;
      dStyle = style1 | style2;
    }

    Color dColor = font.color;
    if (dColor == null) {
      dColor = this.color;
    }

    if (font.baseFont != null) {
      return new Font(font.baseFont, dSize, dStyle, dColor);
    }
    if (font.getFamily() != UNDEFINED) {
      return new Font(font.family, dSize, dStyle, dColor);
    }
    if (this.baseFont != null) {
      if (dStyle == style1) {
        return new Font(this.baseFont, dSize, dStyle, dColor);
      } else {
        return FontFactory.getFont(this.getFamilyname(), dSize, dStyle, dColor);
      }
    }
    return new Font(this.family, dSize, dStyle, dColor);
  }
  private static void addTitleSubtitle(Document d) throws DocumentException, JSONException {
    java.awt.Color tColor = new Color(0, 0, 0);
    fontBold.setColor(tColor);
    fontRegular.setColor(tColor);
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);
    java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
    java.util.Date today = new java.util.Date();

    table.setWidthPercentage(100);
    table.setSpacingBefore(6);

    // Report Title
    PdfPCell cell = new PdfPCell(new Paragraph("Project Summary", fontBold));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    // Sub-title(s)
    cell = new PdfPCell(new Paragraph("(on comparison with " + baseName + ")", fontRegular));
    cell.setBorder(0);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell);

    // Separator line
    PdfPTable line = new PdfPTable(1);
    line.setWidthPercentage(100);
    PdfPCell cell1 = null;
    cell1 = new PdfPCell(new Paragraph(""));
    cell1.setBorder(PdfPCell.BOTTOM);
    line.addCell(cell1);
    d.add(table);
    d.add(line);
  }
 public PdfPCell printStrBoldUnderline(String text, int colspan, int fontsize, int align) {
   try {
     Paragraph p = new Paragraph();
     float padding = 3f;
     // set bold feature
     p.add(new Chunk(text, new Font(Font.getFamilyIndex("Arial"), fontsize, Font.BOLD)));
     PdfPCell cell = new PdfPCell(p);
     // set colspan feature
     cell.setColspan(colspan);
     // set alignment feature
     if (align == 0) cell.setHorizontalAlignment(cell.ALIGN_LEFT);
     else if (align == 1) cell.setHorizontalAlignment(cell.ALIGN_CENTER);
     else if (align == 2) cell.setHorizontalAlignment(cell.ALIGN_RIGHT);
     // set border feature
     cell.disableBorderSide(cell.LEFT);
     cell.disableBorderSide(cell.RIGHT);
     cell.disableBorderSide(cell.TOP);
     cell.setPaddingBottom(padding);
     return cell;
   } catch (Exception e) {
     return null;
   }
 }
Esempio n. 20
0
 /**
  * Compares this <CODE>Font</CODE> with another
  *
  * @param object the other <CODE>Font</CODE>
  * @return a value
  */
 public int compareTo(Object object) {
   if (object == null) {
     return -1;
   }
   Font font;
   try {
     font = (Font) object;
     if (baseFont != null && !baseFont.equals(font.getBaseFont())) {
       return -2;
     }
     if (this.family != font.family()) {
       return 1;
     }
     if (this.size != font.size()) {
       return 2;
     }
     if (this.style != font.style()) {
       return 3;
     }
     if (this.color == null) {
       if (font.color == null) {
         return 0;
       }
       return 4;
     }
     if (font.color == null) {
       return 4;
     }
     if (this.color.equals(font.color())) {
       return 0;
     }
     return 4;
   } catch (ClassCastException cce) {
     return -3;
   }
 }
Esempio n. 21
0
 private Font createNameFont(SheetGraphics graphics) {
   Font newFont = graphics.createTableFont();
   newFont.setStyle(Font.BOLD);
   return newFont;
 }
Esempio n. 22
0
  public void onClick$buttonImprimir() {
    String nombrepdf = "";
    try {
      Calendar cal = Calendar.getInstance();
      // lol
      Calendar cal2 = new GregorianCalendar();
      Document document = new Document();
      String nombre =
          ""
              + (cal.getTime().getYear() + 1900)
              + "_"
              + (cal.getTime().getMonth() + 1)
              + "_"
              + cal.getTime().getDate();
      String tipo = "";
      Font miFuente = new Font();
      miFuente.setStyle(Font.BOLD);
      miFuente.setColor(Color.BLUE);
      Font miFuente2 = new Font();
      miFuente2.setStyle(Font.BOLD);
      miFuente2.setColor(Color.RED);
      PdfPTable tabla;
      PdfPCell celda;
      PdfPCell c1;
      ReporteProducto rowlista;
      String dem = "";
      String esp = "";
      if (cmb_demanda.getText().equals("Mayor Demanda")) {
        dem = "mayDemanda";
      } else {
        dem = "menDemanda";
      }

      if (cmb_tipo.getText().equals("General")) {
        esp = dem + "General";
      } else {
        esp = dem + "PorCat";
      }

      if (cmb_tiempo.getText().equals("Por Año")) {
        tipo = esp + "PorAño";
        tabla = new PdfPTable(4);
        celda = new PdfPCell(new Phrase("Año", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Producto", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Categoría", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
        celda.setHorizontalAlignment(Element.ALIGN_CENTER);
        celda.setVerticalAlignment(Element.ALIGN_CENTER);
        tabla.addCell(celda);
        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      } else {
        if (cmb_tiempo.getText().equals("Por Mes")) {
          tipo = esp + "PorMes";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Año", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Mes", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);

        } else {
          tipo = esp + "PorFecha";
          tabla = new PdfPTable(5);
          celda = new PdfPCell(new Phrase("Fecha Inicial", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Fecha Final", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Producto", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Categoría", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
          celda = new PdfPCell(new Phrase("Cantidad de Pedidos", miFuente2));
          celda.setHorizontalAlignment(Element.ALIGN_CENTER);
          celda.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(celda);
        }

        for (int i = 0; i < lista.size(); i++) {
          rowlista = lista.get(i);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFinicial()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getFfinal()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getProducto()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCategoria()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
          c1 = new PdfPCell(new Phrase("" + rowlista.getCantidad()));
          c1.setHorizontalAlignment(Element.ALIGN_CENTER);
          c1.setVerticalAlignment(Element.ALIGN_CENTER);
          tabla.addCell(c1);
        }
      }
      nombrepdf = "ReporteProductos" + tipo + "_" + nombre + ".pdf";
      PdfWriter.getInstance(document, new FileOutputStream(nombrepdf));
      document.open();
      Paragraph Titulo =
          new Paragraph(
              "Reporte "
                  + cmb_tipo.getText()
                  + " de Productos de "
                  + cmb_demanda.getText()
                  + " "
                  + cmb_tiempo.getText(),
              miFuente);
      Titulo.setAlignment(Element.ALIGN_CENTER);
      Paragraph encabezado = new Paragraph("Prueba");
      encabezado.setAlignment(Element.ALIGN_CENTER);
      document.add(Titulo);
      document.add(encabezado);
      document.add(new Paragraph(" "));

      document.add(tabla);
      document.close();
    } catch (Exception e) {

      e.printStackTrace();
    }
    Hashtable h = new Hashtable();
    h.put("File", nombrepdf);
    Executions.getCurrent()
        .createComponents("Modulo_Reportes/Pdf_Viewer.zul", win_reportesproductos, h);
    File filepdf = new File(nombrepdf);
    filepdf.delete();
    /*  try {
    if ((new File(nombrepdf)).exists()) {
    	Process p = Runtime
    	   .getRuntime()
    	   .exec("rundll32 url.dll,FileProtocolHandler "+nombrepdf);
    	p.waitFor();
    	buttonImprimir.setVisible(false);
    } else {
    	alert("File is not exists!");
    }
    alert("Done!");
    	  } catch (Exception ex) {
    ex.printStackTrace();
     }*/
  }
 private Font createNameFont(BaseFont baseFont) {
   Font newFont = createFont(baseFont);
   newFont.setStyle(Font.BOLD);
   return newFont;
 }
  /**
   * Constructs a <CODE>PdfChunk</CODE>-object.
   *
   * @param chunk the original <CODE>Chunk</CODE>-object
   * @param action the <CODE>PdfAction</CODE> if the <CODE>Chunk</CODE> comes from an <CODE>Anchor
   *     </CODE>
   */
  PdfChunk(Chunk chunk, PdfAction action) {
    thisChunk[0] = this;
    value = chunk.getContent();

    Font f = chunk.getFont();
    float size = f.getSize();
    if (size == Font.UNDEFINED) size = 12;
    baseFont = f.getBaseFont();
    int style = f.getStyle();
    if (style == Font.UNDEFINED) {
      style = Font.NORMAL;
    }
    if (baseFont == null) {
      // translation of the font-family to a PDF font-family
      baseFont = f.getCalculatedBaseFont(false);
    } else {
      // bold simulation
      if ((style & Font.BOLD) != 0)
        attributes.put(
            Chunk.TEXTRENDERMODE,
            new Object[] {
              new Integer(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE), new Float(size / 30f), null
            });
      // italic simulation
      if ((style & Font.ITALIC) != 0) attributes.put(Chunk.SKEW, new float[] {0, ITALIC_ANGLE});
    }
    font = new PdfFont(baseFont, size);
    // other style possibilities
    HashMap attr = chunk.getAttributes();
    if (attr != null) {
      for (Iterator i = attr.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        Object name = entry.getKey();
        if (keysAttributes.containsKey(name)) {
          attributes.put(name, entry.getValue());
        } else if (keysNoStroke.containsKey(name)) {
          noStroke.put(name, entry.getValue());
        }
      }
      if ("".equals(attr.get(Chunk.GENERICTAG))) {
        attributes.put(Chunk.GENERICTAG, chunk.getContent());
      }
    }
    if (f.isUnderlined()) {
      Object obj[] = {null, new float[] {0, 1f / 15, 0, -1f / 3, 0}};
      Object unders[][] = Utilities.addToArray((Object[][]) attributes.get(Chunk.UNDERLINE), obj);
      attributes.put(Chunk.UNDERLINE, unders);
    }
    if (f.isStrikethru()) {
      Object obj[] = {null, new float[] {0, 1f / 15, 0, 1f / 3, 0}};
      Object unders[][] = Utilities.addToArray((Object[][]) attributes.get(Chunk.UNDERLINE), obj);
      attributes.put(Chunk.UNDERLINE, unders);
    }
    if (action != null) attributes.put(Chunk.ACTION, action);
    // the color can't be stored in a PdfFont
    noStroke.put(Chunk.COLOR, f.getColor());
    noStroke.put(Chunk.ENCODING, font.getFont().getEncoding());
    Object obj[] = (Object[]) attributes.get(Chunk.IMAGE);
    if (obj == null) {
      image = null;
    } else {
      attributes.remove(Chunk.HSCALE); // images are scaled in other ways
      image = (Image) obj[0];
      offsetX = ((Float) obj[1]).floatValue();
      offsetY = ((Float) obj[2]).floatValue();
      changeLeading = ((Boolean) obj[3]).booleanValue();
    }
    font.setImage(image);
    Float hs = (Float) attributes.get(Chunk.HSCALE);
    if (hs != null) font.setHorizontalScaling(hs.floatValue());
    encoding = font.getFont().getEncoding();
    splitCharacter = (SplitCharacter) noStroke.get(Chunk.SPLITCHARACTER);
    if (splitCharacter == null) splitCharacter = DefaultSplitCharacter.DEFAULT;
  }
  private void addTable(
      JSONArray store,
      String[] res,
      String[] colIndex,
      String[] colHeader,
      String[] mainHeader,
      String[] val,
      Document document)
      throws JSONException, DocumentException {

    java.awt.Color tColor = new Color(0, 0, 0);
    fontSmallBold.setColor(tColor);
    Font f1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);

    float[] colw = new float[4];
    for (int x = 0; x < 4; x++) {
      colw[x] = 150;
    }
    int col = 0;

    for (int x = 0; x < mainHeader.length; x++) {
      // table start
      PdfPTable table = new PdfPTable(colw);
      table.setTotalWidth(88);
      table.setWidthPercentage(colw, document.getPageSize());
      // table.setSpacingBefore(10);

      PdfPTable mainTable = new PdfPTable(1);
      mainTable.setTotalWidth(90);
      mainTable.setWidthPercentage(100);
      mainTable.setSpacingBefore(20);

      // header cell for mainTable
      PdfPCell headcell = null;
      headcell = new PdfPCell(new Paragraph(mainHeader[x], fontSmallBold));
      headcell.setBackgroundColor(new Color(0xEEEEEE));
      headcell.setPadding(padding);
      mainTable.addCell(headcell);
      document.add(mainTable);

      // header cell added to mainTable
      int row = 3;
      if (x == 0 || x == 4) {
        row = 4;
      } else if (x == 5) {
        row = 0;
      }
      for (; row > 0; row--) {
        for (int y = 1;
            y < colw.length + 1;
            y++) { // for each column add the colHeader and value cell
          if (col != colHeader.length) {
            if (y % 2 != 0) {
              Paragraph p = new Paragraph(colHeader[col], f1);
              if (colHeader[col].contains("Variance")) {
                p = new Paragraph(colHeader[col], fontSmallBold);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
            } else {
              Paragraph p;
              p = new Paragraph(val[col], f1);
              if (colHeader[col].contains("Start Variance")
                  || colHeader[col].contains("End Variance")) {
                p = new Paragraph(val[col] + " days", fontSmallBold);
              } else if (colHeader[col].contains("Duration")) {
                if (colHeader[col].contains("Duration Variance"))
                  p = new Paragraph(val[col] + " days", fontSmallBold);
                else p = new Paragraph(val[col] + " days", f1);
              } else if (colHeader[col].contains("Work")) {
                if (colHeader[col].contains("Work Variance"))
                  p = new Paragraph(val[col] + " hrs", fontSmallBold);
                else p = new Paragraph(val[col] + " hrs", f1);
              } else if (colHeader[col].contains("Cost")) {
                if (colHeader[col].contains("Cost Variance"))
                  p = new Paragraph(currSymbol + " " + val[col], fontSmallBold);
                else p = new Paragraph(currSymbol + " " + val[col], f1);
              } else if (colHeader[col].contains("Percent Complete")) {
                p = new Paragraph(val[col] + " %", f1);
              }
              PdfPCell pcell = new PdfPCell(p);
              if (gridBorder) {
                pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
              } else {
                pcell.setBorder(0);
              }
              pcell.setPadding(padding);
              pcell.setBorderColor(new Color(0xF2F2F2));
              pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pcell.setVerticalAlignment(Element.ALIGN_CENTER);
              table.addCell(pcell);
              col++;
            }
          }
        }
      }
      if (x == 5) {
        int y = 0;
        row = res.length / 4;
        for (; row > 0; row--) {
          for (int c = 0; c < 2; c++) {
            Paragraph p = new Paragraph(res[y], f1);
            PdfPCell pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            p = new Paragraph(res[y + 1], f1);
            pcell = new PdfPCell(p);
            if (gridBorder) {
              pcell.setBorder(PdfPCell.BOTTOM | PdfPCell.LEFT | PdfPCell.RIGHT | PdfPCell.TOP);
            } else {
              pcell.setBorder(0);
            }
            pcell.setPadding(padding);
            pcell.setBorderColor(new Color(0xF2F2F2));
            pcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pcell.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(pcell);
            y += 2;
          }
        }
      }
      document.add(table);
    }
  }
Esempio n. 26
0
 protected Paragraph makePara(final float size, final Object value) {
   final Font font = new Font();
   font.setSize(size);
   return new Paragraph(value == null ? "" : value.toString(), font);
 }