コード例 #1
0
 private void addMetaData(Document document) {
   document.addTitle("Expense Report");
   document.addSubject("Expense Report");
   document.addKeywords("Java, PDF, iText");
   document.addAuthor("www.Ihalkhata.com");
   document.addCreator("www.Ihalkhata.com");
 }
コード例 #2
0
ファイル: PdfExporter.java プロジェクト: mcolucci82/GovPay
 private static void addMetaData(Document document) {
   document.addTitle("Report Eventi");
   document.addSubject("Report Eventi selezionati nella console Govpay");
   document.addKeywords("Report, Eventi, Govpay");
   document.addAuthor("Govpay");
   document.addCreator("Govpay");
 }
コード例 #3
0
ファイル: AbstractPdfCopier.java プロジェクト: Zabrane/sejda
 /**
  * Opens the copier using the given reader and the given output version.
  *
  * @param reader
  * @param outputStream the output stream to write to.
  * @param version version for the created pdf copy, if null the version number is taken from the
  *     input {@link PdfReader}
  */
 void open(PdfReader reader, OutputStream outputStream, PdfVersion version) throws TaskException {
   try {
     pdfDocument = new Document(reader.getPageSizeWithRotation(1));
     pdfCopy = new PdfSmartCopy(pdfDocument, outputStream);
     if (version == null) {
       pdfCopy.setPdfVersion(reader.getPdfVersion());
     } else {
       pdfCopy.setPdfVersion(version.getVersionAsCharacter());
     }
     pdfDocument.addCreator(Sejda.CREATOR);
     pdfDocument.open();
   } catch (DocumentException e) {
     throw new TaskException("An error occurred opening the PdfSmartCopy.", e);
   }
 }
コード例 #4
0
ファイル: PdfWorksheet.java プロジェクト: so0orena/unitime
  private PdfWorksheet(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber)
      throws IOException, DocumentException {
    iUseCommitedAssignments = ApplicationProperty.WorksheetPdfUseCommittedAssignments.isTrue();
    iSubjectAreas =
        new TreeSet<SubjectArea>(
            new Comparator<SubjectArea>() {
              @Override
              public int compare(SubjectArea s1, SubjectArea s2) {
                return s1.getSubjectAreaAbbreviation().compareTo(s2.getSubjectAreaAbbreviation());
              }
            });
    iSubjectAreas.addAll(subjectAreas);
    iCourseNumber = courseNumber;
    if (iCourseNumber != null
        && (iCourseNumber.trim().length() == 0 || "*".equals(iCourseNumber.trim().length())))
      iCourseNumber = null;
    iDoc = new Document(PageSize.LETTER.rotate());

    iOut = out;
    PdfWriter.getInstance(iDoc, iOut);

    String session = null;
    String subjects = "";
    for (SubjectArea sa : iSubjectAreas) {
      if (subjects.isEmpty()) subjects += ", ";
      subjects += sa.getSubjectAreaAbbreviation();
      if (session == null) session += sa.getSession().getLabel();
    }
    iDoc.addTitle(subjects + (iCourseNumber == null ? "" : " " + iCourseNumber) + " Worksheet");
    iDoc.addAuthor(
        ApplicationProperty.WorksheetPdfAuthor.value().replace("%", Constants.getVersion()));
    iDoc.addSubject(subjects + (session == null ? "" : " -- " + session));
    iDoc.addCreator("UniTime " + Constants.getVersion() + ", www.unitime.org");
    if (!iSubjectAreas.isEmpty()) iCurrentSubjectArea = iSubjectAreas.first();

    iDoc.open();

    printHeader();
  }
コード例 #5
0
ファイル: SgtUtil.java プロジェクト: BobSimons/erddap
  /**
   * This creates a file to capture the pdf output generated by calls to graphics2D (e.g., use
   * makeMap). This will overwrite an existing file.
   *
   * @param pageSize e.g, PageSize.LETTER or PageSize.LETTER.rotate() (or A4, or, ...)
   * @param width the bounding box width, in 1/144ths of an inch
   * @param height the bounding box height, in 1/144ths of an inch
   * @param outputStream
   * @return an object[] with 0=g2D, 1=document, 2=pdfContentByte, 3=pdfTemplate
   * @throws Exception if trouble
   */
  public static Object[] createPdf(
      com.lowagie.text.Rectangle pageSize, int bbWidth, int bbHeight, OutputStream outputStream)
      throws Exception {
    // currently, this uses itext
    // see the sample program:
    //
    // file://localhost/C:/programs/iText/examples/com/lowagie/examples/directcontent/graphics2D/G2D.java
    // Document.compress = false; //for test purposes only
    Document document = new Document(pageSize);
    document.addCreationDate();
    document.addCreator("gov.noaa.pfel.coastwatch.SgtUtil.createPdf");

    document.setPageSize(pageSize);
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    document.open();

    // create contentByte and template and Graphics2D objects
    PdfContentByte pdfContentByte = writer.getDirectContent();
    PdfTemplate pdfTemplate = pdfContentByte.createTemplate(bbWidth, bbHeight);
    Graphics2D g2D = pdfTemplate.createGraphics(bbWidth, bbHeight);

    return new Object[] {g2D, document, pdfContentByte, pdfTemplate};
  }
コード例 #6
0
  public void open() throws DocumentException {
    this.document = new Document();
    // pageSize, marginLeft, marginRight, marginTop, marginBottom));

    writer = PdfWriter.getInstance(document, out);
    writer.setLinearPageMode();

    version = getVersion();
    writer.setPdfVersion(version);
    writer.setViewerPreferences(getViewerPreferences());

    final String encrypt =
        config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Encryption");

    if (encrypt != null) {
      if (encrypt.equals(PdfPageableModule.SECURITY_ENCRYPTION_128BIT) == true
          || encrypt.equals(PdfPageableModule.SECURITY_ENCRYPTION_40BIT) == true) {
        final String userpassword =
            config.getConfigProperty(
                "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.UserPassword");
        final String ownerpassword =
            config.getConfigProperty(
                "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.OwnerPassword");
        // Log.debug ("UserPassword: "******" - OwnerPassword: "******"org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Title",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Title"));
    final String subject =
        config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Description",
            config.getConfigProperty(
                "org.pentaho.reporting.engine.classic.core.metadata.Description"));
    final String author =
        config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Author",
            config.getConfigProperty("org.pentaho.reporting.engine.classic.core.metadata.Author"));
    final String keyWords =
        config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.Keywords",
            config.getConfigProperty(
                "org.pentaho.reporting.engine.classic.core.metadata.Keywords"));

    if (title != null) {
      document.addTitle(title);
    }
    if (author != null) {
      document.addAuthor(author);
    }
    if (keyWords != null) {
      document.addKeywords(keyWords);
    }
    if (keyWords != null) {
      document.addSubject(subject);
    }

    document.addCreator(PdfDocumentWriter.CREATOR);
    document.addCreationDate();

    // getDocument().open();
    awaitOpenDocument = true;
  }
コード例 #7
0
  /** @noinspection IOResourceOpenedButNotSafelyClosed */
  public void print(
      final LogicalPageKey logicalPageKey,
      final LogicalPageBox logicalPage,
      final TableContentProducer contentProducer,
      final RTFOutputProcessorMetaData metaData,
      final boolean incremental)
      throws ContentProcessingException {
    final int startRow = contentProducer.getFinishedRows();
    final int finishRow = contentProducer.getFilledRows();
    if (incremental && startRow == finishRow) {
      return;
    }

    if (document == null) {
      this.cellBackgroundProducer =
          new CellBackgroundProducer(
              metaData.isFeatureSupported(AbstractTableOutputProcessor.TREAT_ELLIPSE_AS_RECTANGLE),
              metaData.isFeatureSupported(OutputProcessorFeature.UNALIGNED_PAGEBANDS));

      final PhysicalPageBox pageFormat = logicalPage.getPageGrid().getPage(0, 0);
      final float urx = (float) StrictGeomUtility.toExternalValue(pageFormat.getWidth());
      final float ury = (float) StrictGeomUtility.toExternalValue(pageFormat.getHeight());

      final float marginLeft =
          (float) StrictGeomUtility.toExternalValue(pageFormat.getImageableX());
      final float marginRight =
          (float)
              StrictGeomUtility.toExternalValue(
                  pageFormat.getWidth()
                      - pageFormat.getImageableWidth()
                      - pageFormat.getImageableX());
      final float marginTop = (float) StrictGeomUtility.toExternalValue(pageFormat.getImageableY());
      final float marginBottom =
          (float)
              StrictGeomUtility.toExternalValue(
                  pageFormat.getHeight()
                      - pageFormat.getImageableHeight()
                      - pageFormat.getImageableY());
      final Rectangle pageSize = new Rectangle(urx, ury);

      document = new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom);
      imageCache = new RTFImageCache(resourceManager);

      // rtf does not support PageFormats or other meta data...
      final PatchRtfWriter2 instance =
          PatchRtfWriter2.getInstance(document, new NoCloseOutputStream(outputStream));
      instance.getDocumentSettings().setAlwaysUseUnicode(true);

      final String author =
          config.getConfigProperty(
              "org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.Author");
      if (author != null) {
        document.addAuthor(author);
      }

      final String title =
          config.getConfigProperty(
              "org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.Title");
      if (title != null) {
        document.addTitle(title);
      }

      document.addProducer();
      document.addCreator(RTFPrinter.CREATOR);

      try {
        document.addCreationDate();
      } catch (Exception e) {
        RTFPrinter.logger.debug("Unable to add creation date. It will have to work without it.", e);
      }

      document.open();
    }

    // Start a new page.
    try {
      final SheetLayout sheetLayout = contentProducer.getSheetLayout();
      final int columnCount = contentProducer.getColumnCount();
      if (table == null) {
        final int rowCount = contentProducer.getRowCount();
        table = new Table(columnCount, rowCount);
        table.setAutoFillEmptyCells(false);
        table.setWidth(100); // span the full page..
        // and finally the content ..

        final float[] cellWidths = new float[columnCount];
        for (int i = 0; i < columnCount; i++) {
          cellWidths[i] =
              (float) StrictGeomUtility.toExternalValue(sheetLayout.getCellWidth(i, i + 1));
        }
        table.setWidths(cellWidths);
      }

      // logger.debug ("Processing: " + startRow + " " + finishRow + " " + incremental);

      for (int row = startRow; row < finishRow; row++) {
        for (short col = 0; col < columnCount; col++) {
          final RenderBox content = contentProducer.getContent(row, col);
          final CellMarker.SectionType sectionType = contentProducer.getSectionType(row, col);

          if (content == null) {
            final RenderBox backgroundBox = contentProducer.getBackground(row, col);
            final CellBackground background;
            if (backgroundBox != null) {
              background =
                  cellBackgroundProducer.getBackgroundForBox(
                      logicalPage, sheetLayout, col, row, 1, 1, true, sectionType, backgroundBox);
            } else {
              background =
                  cellBackgroundProducer.getBackgroundAt(
                      logicalPage, sheetLayout, col, row, true, sectionType);
            }
            if (background == null) {
              // An empty cell .. ignore
              final PatchRtfCell cell = new PatchRtfCell();
              cell.setBorderWidth(0);
              cell.setMinimumHeight(
                  (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row)));
              table.addCell(cell, row, col);
              continue;
            }

            // A empty cell with a defined background ..
            final PatchRtfCell cell = new PatchRtfCell();
            cell.setBorderWidth(0);
            cell.setMinimumHeight(
                (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row)));
            updateCellStyle(cell, background);
            table.addCell(cell, row, col);
            continue;
          }

          if (content.isCommited() == false) {
            throw new InvalidReportStateException("Uncommited content encountered");
          }

          final long contentOffset = contentProducer.getContentOffset(row, col);
          final long colPos = sheetLayout.getXPosition(col);
          final long rowPos = sheetLayout.getYPosition(row);
          if (content.getX() != colPos || (content.getY() + contentOffset) != rowPos) {
            // A spanned cell ..
            continue;
          }

          final int colSpan = sheetLayout.getColSpan(col, content.getX() + content.getWidth());
          final int rowSpan =
              sheetLayout.getRowSpan(row, content.getY() + content.getHeight() + contentOffset);

          final CellBackground realBackground =
              cellBackgroundProducer.getBackgroundForBox(
                  logicalPage,
                  sheetLayout,
                  col,
                  row,
                  colSpan,
                  rowSpan,
                  false,
                  sectionType,
                  content);

          final PatchRtfCell cell = new PatchRtfCell();
          cell.setRowspan(rowSpan);
          cell.setColspan(colSpan);
          cell.setBorderWidth(0);
          cell.setMinimumHeight(
              (float) StrictGeomUtility.toExternalValue(sheetLayout.getRowHeight(row)));
          if (realBackground != null) {
            updateCellStyle(cell, realBackground);
          }

          computeCellStyle(content, cell);

          // export the cell and all content ..
          final RTFTextExtractor etx = new RTFTextExtractor(metaData);
          etx.compute(content, cell, imageCache);

          table.addCell(cell, row, col);
          content.setFinishedTable(true);
          // logger.debug("set Finished to cell (" + col + ", " + row + "," + content.getName() +
          // ")");
        }
      }

      if (incremental == false) {
        document.add(table);
        table = null;
      }
    } catch (DocumentException e) {
      throw new ContentProcessingException("Failed to generate RTF-Document", e);
    }
  }