Пример #1
0
 /**
  * Constructs a <CODE>PdfPCell</CODE> with a <CODE>PdfPtable</CODE>. This constructor allows
  * nested tables.
  *
  * @param table The <CODE>PdfPTable</CODE>
  * @param style The style to apply to the cell (you could use getDefaultCell())
  * @since 2.1.0
  */
 public PdfPCell(PdfPTable table, PdfPCell style) {
   super(0, 0, 0, 0);
   borderWidth = 0.5f;
   border = BOX;
   column.setLeading(0, 1);
   this.table = table;
   table.setWidthPercentage(100);
   table.setExtendLastRow(true);
   column.addElement(table);
   if (style != null) {
     cloneNonPositionParameters(style);
     verticalAlignment = style.verticalAlignment;
     paddingLeft = style.paddingLeft;
     paddingRight = style.paddingRight;
     paddingTop = style.paddingTop;
     paddingBottom = style.paddingBottom;
     colspan = style.colspan;
     rowspan = style.rowspan;
     cellEvent = style.cellEvent;
     useDescender = style.useDescender;
     useBorderPadding = style.useBorderPadding;
     rotation = style.rotation;
   } else {
     setPadding(0);
   }
 }
Пример #2
0
 void setTable(PdfPTable table) {
   this.table = table;
   column.setText(null);
   image = null;
   if (table != null) {
     table.setExtendLastRow(verticalAlignment == Element.ALIGN_TOP);
     column.addElement(table);
     table.setWidthPercentage(100);
   }
 }
  // --- GENERATE PDF DOCUMENT BYTES -------------------------------------------------------------
  public ByteArrayOutputStream generatePDFDocumentBytes(
      final HttpServletRequest req, String type, String title, Hashtable parameters)
      throws Exception {
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    docWriter = PdfWriter.getInstance(doc, baosPDF);
    this.req = req;

    String sURL = req.getRequestURL().toString();
    if (sURL.indexOf("openclinic", 10) > 0) {
      sURL = sURL.substring(0, sURL.indexOf("openclinic", 10));
    }

    String sContextPath = req.getContextPath() + "/";
    HttpSession session = req.getSession();
    String sProjectDir = (String) session.getAttribute("activeProjectDir");

    this.url = sURL;
    this.contextPath = sContextPath;
    this.projectDir = sProjectDir;

    try {
      doc.addProducer();
      doc.addAuthor(user.person.firstname + " " + user.person.lastname);
      doc.addCreationDate();
      doc.addCreator("OpenClinic Software");
      Rectangle rectangle = null;
      doc.setPageSize(PageSize.A4);
      doc.setMargins(10, 10, 10, 10);
      doc.setJavaScript_onLoad("print();\r");
      doc.open();

      PdfPTable table = new PdfPTable(1);
      table.setWidthPercentage(100);
      if (type.equalsIgnoreCase("piechart")) {
        KeyValue[] values = new KeyValue[parameters.size()];
        Enumeration pars = parameters.keys();
        int n = 0;
        while (pars.hasMoreElements()) {
          String parameterkey = (String) pars.nextElement();
          values[n] = new KeyValue(parameterkey, (String) parameters.get(parameterkey));
          n++;
        }
        table.addCell(
            createKPGSPieChartCell(
                values, ScreenHelper.getTranNoLink("web", title, sPrintLanguage)));
      }
      doc.add(table);
    } catch (Exception e) {
      baosPDF.reset();
      e.printStackTrace();
    } finally {
      if (doc != null) doc.close();
      if (docWriter != null) docWriter.close();
    }

    if (baosPDF.size() < 1) {
      throw new DocumentException("document has no bytes");
    }

    return baosPDF;
  }