コード例 #1
0
ファイル: PdfStamper.java プロジェクト: RoDaniel/featurehouse
 public void setEncryption(
     int encryptionType, String userPassword, String ownerPassword, int permissions)
     throws DocumentException {
   setEncryption(
       DocWriter.getISOBytes(userPassword),
       DocWriter.getISOBytes(ownerPassword),
       permissions,
       encryptionType);
 }
コード例 #2
0
ファイル: PdfStamper.java プロジェクト: RoDaniel/featurehouse
 public void setEncryption(
     boolean strength, String userPassword, String ownerPassword, int permissions)
     throws DocumentException {
   setEncryption(
       DocWriter.getISOBytes(userPassword),
       DocWriter.getISOBytes(ownerPassword),
       permissions,
       strength);
 }
コード例 #3
0
ファイル: RtfParagraph.java プロジェクト: kjella/iText-4.2.0
  /**
   * Writes the content of this RtfParagraph. First paragraph specific data is written and then the
   * RtfChunks of this RtfParagraph are added.
   */
  public void writeContent(final OutputStream result) throws IOException {
    result.write(PARAGRAPH_DEFAULTS);
    result.write(PLAIN);

    if (inTable) {
      result.write(IN_TABLE);
    }

    if (this.paragraphStyle != null) {
      this.paragraphStyle.writeBegin(result);
    }
    result.write(DocWriter.getISOBytes("\\plain"));

    for (int i = 0; i < chunks.size(); i++) {
      RtfBasicElement rbe = (RtfBasicElement) chunks.get(i);
      rbe.writeContent(result);
    }

    if (this.paragraphStyle != null) {
      this.paragraphStyle.writeEnd(result);
    }

    if (!inTable) {
      result.write(PARAGRAPH);
    }
    this.document.outputDebugLinebreak(result);
  }
コード例 #4
0
 /** Write the content of this PatchRtfCell */
 public void writeContent(final OutputStream result) throws IOException {
   if (this.content.size() == 0) {
     result.write(RtfParagraph.PARAGRAPH_DEFAULTS);
     if (this.parentRow.getParentTable().getTableFitToPage()) {
       result.write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT);
     }
     result.write(RtfParagraph.IN_TABLE);
   } else {
     for (int i = 0; i < this.content.size(); i++) {
       RtfBasicElement rtfElement = this.content.get(i);
       if (rtfElement instanceof RtfParagraph) {
         ((RtfParagraph) rtfElement)
             .setKeepTogetherWithNext(this.parentRow.getParentTable().getTableFitToPage());
       }
       rtfElement.writeContent(result);
       if (rtfElement instanceof RtfParagraph && i < (this.content.size() - 1)) {
         result.write(RtfParagraph.PARAGRAPH);
       }
     }
   }
   result.write(DocWriter.getISOBytes("\\cell"));
 }
コード例 #5
0
ファイル: RtfTotalPageNumber.java プロジェクト: rototor/itext
/**
 * The RtfTotalPageNumber provides the total number of pages field in rtf documents.
 *
 * @version $Id$
 * @author Jose Hurtado ([email protected])
 * @author Mark Hall ([email protected])
 * @author Thomas Bickel ([email protected])
 */
public class RtfTotalPageNumber extends RtfField {

  /** Constant for arabic total page numbers. */
  private static final byte[] ARABIC_TOTAL_PAGES = DocWriter.getISOBytes("NUMPAGES \\\\* Arabic");

  /**
   * Constructs a RtfTotalPageNumber. This can be added anywhere to add a total number of pages
   * field.
   */
  public RtfTotalPageNumber() {
    super(null);
  }

  /**
   * Constructs a RtfTotalPageNumber with a specified Font. This can be added anywhere to add a
   * total number of pages field.
   *
   * @param font
   */
  public RtfTotalPageNumber(Font font) {
    super(null, font);
  }

  /**
   * Constructs a RtfTotalPageNumber object.
   *
   * @param doc The RtfDocument this RtfTotalPageNumber belongs to
   */
  public RtfTotalPageNumber(RtfDocument doc) {
    super(doc);
  }

  /**
   * Constructs a RtfTotalPageNumber object with a specific font.
   *
   * @param doc The RtfDocument this RtfTotalPageNumber belongs to
   * @param font The Font to use
   */
  public RtfTotalPageNumber(RtfDocument doc, Font font) {
    super(doc, font);
  }

  /**
   * Writes the field NUMPAGES instruction with Arabic format: "NUMPAGES \\\\* Arabic".
   *
   * @param result The <code>OutputStream</code> to write to.
   * @throws IOException on i/o errors.
   */
  @Override
  protected void writeFieldInstContent(OutputStream result) throws IOException {
    result.write(ARABIC_TOTAL_PAGES);
  }

  /**
   * Writes the field result content "1".
   *
   * @param out The <code>OutputStream</code> to write to.
   * @throws IOException on i/o errors.
   */
  @Override
  protected void writeFieldResultContent(final OutputStream out) throws IOException {
    out.write(DocWriter.getISOBytes("1"));
  }
}
コード例 #6
0
ファイル: RtfTotalPageNumber.java プロジェクト: rototor/itext
 /**
  * Writes the field result content "1".
  *
  * @param out The <code>OutputStream</code> to write to.
  * @throws IOException on i/o errors.
  */
 @Override
 protected void writeFieldResultContent(final OutputStream out) throws IOException {
   out.write(DocWriter.getISOBytes("1"));
 }
コード例 #7
0
ファイル: RtfParagraph.java プロジェクト: kjella/iText-4.2.0
/**
 * The RtfParagraph is an extension of the RtfPhrase that adds alignment and indentation properties.
 * It wraps a Paragraph.
 *
 * @version $Id: RtfParagraph.java 3670 2009-02-01 09:13:48Z blowagie $
 * @author Mark Hall ([email protected])
 * @author Thomas Bickel ([email protected])
 */
public class RtfParagraph extends RtfPhrase {

  /** Constant for the end of a paragraph */
  public static final byte[] PARAGRAPH = DocWriter.getISOBytes("\\par");

  /** An optional RtfParagraphStyle to use for styling. */
  protected RtfParagraphStyle paragraphStyle = null;

  /**
   * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph.
   *
   * @param doc The RtfDocument this RtfParagraph belongs to
   * @param paragraph The Paragraph that this RtfParagraph is based on
   */
  public RtfParagraph(RtfDocument doc, Paragraph paragraph) {
    super(doc);
    RtfFont baseFont = null;
    if (paragraph.getFont() instanceof RtfParagraphStyle) {
      this.paragraphStyle =
          this.document
              .getDocumentHeader()
              .getRtfParagraphStyle(((RtfParagraphStyle) paragraph.getFont()).getStyleName());
      baseFont = this.paragraphStyle;
    } else {
      baseFont = new RtfFont(this.document, paragraph.getFont());
      this.paragraphStyle =
          new RtfParagraphStyle(
              this.document, this.document.getDocumentHeader().getRtfParagraphStyle("Normal"));
      this.paragraphStyle.setAlignment(paragraph.getAlignment());
      this.paragraphStyle.setFirstLineIndent(
          (int) (paragraph.getFirstLineIndent() * RtfElement.TWIPS_FACTOR));
      this.paragraphStyle.setIndentLeft(
          (int) (paragraph.getIndentationLeft() * RtfElement.TWIPS_FACTOR));
      this.paragraphStyle.setIndentRight(
          (int) (paragraph.getIndentationRight() * RtfElement.TWIPS_FACTOR));
      this.paragraphStyle.setSpacingBefore(
          (int) (paragraph.getSpacingBefore() * RtfElement.TWIPS_FACTOR));
      this.paragraphStyle.setSpacingAfter(
          (int) (paragraph.getSpacingAfter() * RtfElement.TWIPS_FACTOR));
      if (paragraph.hasLeading()) {
        this.paragraphStyle.setLineLeading(
            (int) (paragraph.getLeading() * RtfElement.TWIPS_FACTOR));
      }
      this.paragraphStyle.setKeepTogether(paragraph.getKeepTogether());
    }
    for (int i = 0; i < paragraph.size(); i++) {
      Element chunk = (Element) paragraph.get(i);
      if (chunk instanceof Chunk) {
        ((Chunk) chunk).setFont(baseFont.difference(((Chunk) chunk).getFont()));
      } else if (chunk instanceof RtfImage) {
        ((RtfImage) chunks.get(i)).setAlignment(this.paragraphStyle.getAlignment());
      }
      try {
        RtfBasicElement[] rtfElements = doc.getMapper().mapElement(chunk);
        for (int j = 0; j < rtfElements.length; j++) {
          chunks.add(rtfElements[j]);
        }
      } catch (DocumentException de) {
      }
    }
  }

  /**
   * Set whether this RtfParagraph must stay on the same page as the next one.
   *
   * @param keepTogetherWithNext Whether this RtfParagraph must keep together with the next.
   */
  public void setKeepTogetherWithNext(boolean keepTogetherWithNext) {
    this.paragraphStyle.setKeepTogetherWithNext(keepTogetherWithNext);
  }

  /**
   * Writes the content of this RtfParagraph. First paragraph specific data is written and then the
   * RtfChunks of this RtfParagraph are added.
   */
  public void writeContent(final OutputStream result) throws IOException {
    result.write(PARAGRAPH_DEFAULTS);
    result.write(PLAIN);

    if (inTable) {
      result.write(IN_TABLE);
    }

    if (this.paragraphStyle != null) {
      this.paragraphStyle.writeBegin(result);
    }
    result.write(DocWriter.getISOBytes("\\plain"));

    for (int i = 0; i < chunks.size(); i++) {
      RtfBasicElement rbe = (RtfBasicElement) chunks.get(i);
      rbe.writeContent(result);
    }

    if (this.paragraphStyle != null) {
      this.paragraphStyle.writeEnd(result);
    }

    if (!inTable) {
      result.write(PARAGRAPH);
    }
    this.document.outputDebugLinebreak(result);
  }

  /**
   * Gets the left indentation of this RtfParagraph.
   *
   * @return The left indentation.
   */
  public int getIndentLeft() {
    return this.paragraphStyle.getIndentLeft();
  }

  /**
   * Sets the left indentation of this RtfParagraph.
   *
   * @param indentLeft The left indentation to use.
   */
  public void setIndentLeft(int indentLeft) {
    this.paragraphStyle.setIndentLeft(indentLeft);
  }

  /**
   * Gets the right indentation of this RtfParagraph.
   *
   * @return The right indentation.
   */
  public int getIndentRight() {
    return this.paragraphStyle.getIndentRight();
  }

  /**
   * Sets the right indentation of this RtfParagraph.
   *
   * @param indentRight The right indentation to use.
   */
  public void setIndentRight(int indentRight) {
    this.paragraphStyle.setIndentRight(indentRight);
  }
}
コード例 #8
0
 /**
  * Transforms an integer into its String representation and then returns the bytes of that string.
  *
  * @param i The integer to convert
  * @return A byte array representing the integer
  */
 private byte[] intToByteArray(int i) {
   return DocWriter.getISOBytes(Integer.toString(i));
 }
コード例 #9
0
  /** Write the cell definition part of this PatchRtfCell */
  public void writeDefinition(final OutputStream result) throws IOException {
    if (this.mergeType == MERGE_VERT_PARENT) {
      result.write(DocWriter.getISOBytes("\\clvmgf"));
    } else if (this.mergeType == MERGE_VERT_CHILD) {
      result.write(DocWriter.getISOBytes("\\clvmrg"));
    }
    switch (verticalAlignment) {
      case Element.ALIGN_BOTTOM:
        result.write(DocWriter.getISOBytes("\\clvertalb"));
        break;
      case Element.ALIGN_CENTER:
      case Element.ALIGN_MIDDLE:
        result.write(DocWriter.getISOBytes("\\clvertalc"));
        break;
      case Element.ALIGN_TOP:
        result.write(DocWriter.getISOBytes("\\clvertalt"));
        break;
    }
    this.borders.writeContent(result);

    if (this.backgroundColor != null) {
      result.write(DocWriter.getISOBytes("\\clcbpat"));
      result.write(intToByteArray(this.backgroundColor.getColorNumber()));
    }
    this.document.outputDebugLinebreak(result);

    result.write(DocWriter.getISOBytes("\\clftsWidth3"));
    this.document.outputDebugLinebreak(result);

    result.write(DocWriter.getISOBytes("\\clwWidth"));
    result.write(intToByteArray(this.cellWidth));
    this.document.outputDebugLinebreak(result);

    if (this.cellPadding > 0) {
      result.write(DocWriter.getISOBytes("\\clpadl"));
      result.write(intToByteArray(this.cellPadding / 2));
      result.write(DocWriter.getISOBytes("\\clpadt"));
      result.write(intToByteArray(this.cellPadding / 2));
      result.write(DocWriter.getISOBytes("\\clpadr"));
      result.write(intToByteArray(this.cellPadding / 2));
      result.write(DocWriter.getISOBytes("\\clpadb"));
      result.write(intToByteArray(this.cellPadding / 2));
      result.write(DocWriter.getISOBytes("\\clpadfl3"));
      result.write(DocWriter.getISOBytes("\\clpadft3"));
      result.write(DocWriter.getISOBytes("\\clpadfr3"));
      result.write(DocWriter.getISOBytes("\\clpadfb3"));
    }
    result.write(DocWriter.getISOBytes("\\cellx"));
    result.write(intToByteArray(this.cellRight));
  }
コード例 #10
0
 /**
  * Writes the field instruction content
  *
  * @param result The <code>OutputStream</code> to write to.
  * @throws IOException on i/o errors.
  */
 protected void writeFieldInstContent(final OutputStream result) throws IOException {
   result.write(DocWriter.getISOBytes(FIELD_INST));
 }
コード例 #11
0
ファイル: RtfTOCEntry.java プロジェクト: RealEnder/jsignpdf
/**
 * The RtfTOCEntry is used together with the RtfTableOfContents to generate a table of contents. Add
 * the RtfTOCEntry in those locations in the document where table of contents entries should link to
 *
 * @version $Id: RtfTOCEntry.java,v 1.1 2010/04/14 17:50:40 kwart Exp $
 * @author Mark Hall ([email protected])
 * @author Steffen.Stundzig ([email protected])
 * @author Thomas Bickel ([email protected])
 */
public class RtfTOCEntry extends RtfField {

  /** Constant for the beginning of hidden text */
  private static final byte[] TEXT_HIDDEN_ON = DocWriter.getISOBytes("\\v");
  /** Constant for the end of hidden text */
  private static final byte[] TEXT_HIDDEN_OFF = DocWriter.getISOBytes("\\v0");
  /** Constant for a TOC entry with page numbers */
  private static final byte[] TOC_ENTRY_PAGE_NUMBER = DocWriter.getISOBytes("\\tc");
  /** Constant for a TOC entry without page numbers */
  private static final byte[] TOC_ENTRY_NO_PAGE_NUMBER = DocWriter.getISOBytes("\\tcn");

  /** The entry text of this RtfTOCEntry */
  private String entry = "";
  /** Whether to show page numbers in the table of contents */
  private boolean showPageNumber = true;

  /**
   * Constructs a RtfTOCEntry with a certain entry text.
   *
   * @param entry The entry text to display
   */
  public RtfTOCEntry(String entry) {
    super(null, new Font());
    if (entry != null) {
      this.entry = entry;
    }
  }

  /**
   * Writes the content of the <code>RtfTOCEntry</code>.
   *
   * @param result The <code>OutputStream</code> to write to.
   * @throws IOException on i/o errors.
   */
  public void writeContent(final OutputStream result) throws IOException {
    result.write(TEXT_HIDDEN_ON);
    result.write(OPEN_GROUP);
    if (this.showPageNumber) {
      result.write(TOC_ENTRY_PAGE_NUMBER);
    } else {
      result.write(TOC_ENTRY_NO_PAGE_NUMBER);
    }
    result.write(DELIMITER);
    this.document.filterSpecialChar(result, this.entry, true, false);
    result.write(CLOSE_GROUP);
    result.write(TEXT_HIDDEN_OFF);
  }

  /**
   * Sets whether to display a page number in the table of contents, or not
   *
   * @param showPageNumber Whether to display a page number or not
   */
  public void setShowPageNumber(boolean showPageNumber) {
    this.showPageNumber = showPageNumber;
  }

  /** unused */
  protected void writeFieldInstContent(OutputStream out) throws IOException {}

  /** unused */
  protected void writeFieldResultContent(OutputStream out) throws IOException {}
}
コード例 #12
0
ファイル: RtfDocumentHeader.java プロジェクト: rototor/itext
/**
 * The RtfDocumentHeader contains all classes required for the generation of the document header
 * area.
 *
 * @version $Id$
 * @author Mark Hall ([email protected])
 * @author Thomas Bickel ([email protected])
 * @author Howard Shank ([email protected])
 */
public class RtfDocumentHeader extends RtfElement {
  /** Constant for the title page */
  private static final byte[] TITLE_PAGE = DocWriter.getISOBytes("\\titlepg");
  /** Constant for facing pages */
  private static final byte[] FACING_PAGES = DocWriter.getISOBytes("\\facingp");

  /** The code page to use */
  private RtfCodePage codePage = null;
  /** Stores all the colors used in the document */
  private RtfColorList colorList = null;
  /** Stores all the fonts used in the document */
  private RtfFontList fontList = null;
  /** Manages List tables */
  private RtfListTable listTable = null;
  /** Stores all paragraph styles used in the document. */
  private RtfStylesheetList stylesheetList = null;
  /** Generator string in document */
  private RtfGenerator generator = null;
  /** The information group with author/subject/keywords/title/producer/creationdate data */
  private RtfInfoGroup infoGroup = null;
  /**
   * The protection settings Author: Howard Shank ([email protected])
   *
   * @since 2.1.1
   */
  private RtfProtectionSetting protectionSetting = null;
  /** The page settings */
  private RtfPageSetting pageSetting = null;
  /** The current RtfHeaderFooterGroup for the header */
  private HeaderFooter header = null;
  /** The current RtfHeaderFooterGroup for the footer */
  private HeaderFooter footer = null;

  /**
   * Constructs a RtfDocumentHeader for a RtfDocument
   *
   * @param doc The RtfDocument this RtfDocumentHeader belongs to
   */
  protected RtfDocumentHeader(RtfDocument doc) {
    super(doc);
  }

  /** initializes the RtfDocumentHeader. */
  protected void init() {
    this.codePage = new RtfCodePage(this.document);
    this.colorList = new RtfColorList(this.document);
    this.fontList = new RtfFontList(this.document);
    this.listTable = new RtfListTable(this.document);
    this.stylesheetList = new RtfStylesheetList(this.document);
    this.infoGroup = new RtfInfoGroup(this.document);
    this.protectionSetting = new RtfProtectionSetting(this.document);
    this.pageSetting = new RtfPageSetting(this.document);
    this.header = new RtfHeaderFooterGroup(this.document, RtfHeaderFooter.TYPE_HEADER);
    this.footer = new RtfHeaderFooterGroup(this.document, RtfHeaderFooter.TYPE_FOOTER);
    this.generator = new RtfGenerator(this.document);
  }

  /** Writes the contents of the document header area. */
  @Override
  public void writeContent(final OutputStream result) throws IOException {
    try {
      // This is so that all color, font and similar information is processed once, before
      // the header section is written.
      writeSectionDefinition(new RtfNilOutputStream());

      this.codePage.writeDefinition(result);
      this.fontList.writeDefinition(result);
      this.colorList.writeDefinition(result);
      this.stylesheetList.writeDefinition(result);
      this.listTable.writeDefinition(result);
      this.generator.writeContent(result);
      this.infoGroup.writeContent(result);
      this.protectionSetting.writeDefinition(result);
      this.pageSetting.writeDefinition(result);

      writeSectionDefinition(result);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }

  /**
   * Writes the section definition data
   *
   * @param result
   */
  public void writeSectionDefinition(final OutputStream result) {
    try {
      RtfHeaderFooterGroup header = convertHeaderFooter(this.header, RtfHeaderFooter.TYPE_HEADER);
      RtfHeaderFooterGroup footer = convertHeaderFooter(this.footer, RtfHeaderFooter.TYPE_FOOTER);
      if (header.hasTitlePage() || footer.hasTitlePage()) {
        result.write(TITLE_PAGE);
        header.setHasTitlePage();
        footer.setHasTitlePage();
      }
      if (header.hasFacingPages() || footer.hasFacingPages()) {
        result.write(FACING_PAGES);
        header.setHasFacingPages();
        footer.setHasFacingPages();
      }
      footer.writeContent(result);
      header.writeContent(result);
      pageSetting.writeSectionDefinition(result);
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }

  /**
   * Gets the number of the specified RtfFont
   *
   * @param font The RtfFont for which to get the number
   * @return The number of the font
   */
  public int getFontNumber(RtfFont font) {
    return this.fontList.getFontNumber(font);
  }

  /**
   * Gets the number of the specified RtfColor
   *
   * @param color The RtfColor for which to get the number
   * @return The number of the color
   */
  public int getColorNumber(RtfColor color) {
    return this.colorList.getColorNumber(color);
  }

  /**
   * Gets the number of the specified RtfList
   *
   * @param list The RtfList for which to get the number
   * @return The number of the list
   */
  public int getListNumber(RtfList list) {
    return this.listTable.getListNumber(list);
  }
  /**
   * Gets the RtfParagraphStyle with the given style name.
   *
   * @param styleName The style name of the RtfParagraphStyle to get.
   * @return The RtfParagraphStyle with the given style name or null.
   */
  public RtfParagraphStyle getRtfParagraphStyle(String styleName) {
    return this.stylesheetList.getRtfParagraphStyle(styleName);
  }

  /**
   * Removes a RtfList from the list table
   *
   * @param list The RtfList to remove
   */
  public void freeListNumber(RtfList list) {
    this.listTable.freeListNumber(list);
  }

  /**
   * Gets the RtfPageSetting object of this RtfDocument
   *
   * @return The RtfPageSetting object
   */
  public RtfPageSetting getPageSetting() {
    return this.pageSetting;
  }

  /**
   * Adds an RtfInfoElement to the list of RtfInfoElements
   *
   * @param rtfInfoElement The RtfInfoElement to add
   */
  public void addInfoElement(RtfInfoElement rtfInfoElement) {
    this.infoGroup.add(rtfInfoElement);
  }

  /**
   * Sets the current header to use
   *
   * @param header The HeaderFooter to use as header
   */
  public void setHeader(HeaderFooter header) {
    this.header = header;
  }

  /**
   * Sets the current footer to use
   *
   * @param footer The HeaderFooter to use as footer
   */
  public void setFooter(HeaderFooter footer) {
    this.footer = footer;
  }

  /**
   * Registers the RtfParagraphStyle for further use in the document.
   *
   * @param rtfParagraphStyle The RtfParagraphStyle to register.
   */
  public void registerParagraphStyle(RtfParagraphStyle rtfParagraphStyle) {
    this.stylesheetList.registerParagraphStyle(rtfParagraphStyle);
  }

  /**
   * Converts a HeaderFooter into a RtfHeaderFooterGroup. Depending on which class the HeaderFooter
   * is, the correct RtfHeaderFooterGroup is created.
   *
   * @param hf The HeaderFooter to convert.
   * @param type Whether the conversion is being done on a footer or header
   * @return The converted RtfHeaderFooterGroup.
   * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooter
   * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup
   */
  private RtfHeaderFooterGroup convertHeaderFooter(HeaderFooter hf, int type) {
    if (hf != null) {
      if (hf instanceof RtfHeaderFooterGroup) {
        return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooterGroup) hf, type);
      } else if (hf instanceof RtfHeaderFooter) {
        return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooter) hf, type);
      } else {
        return new RtfHeaderFooterGroup(this.document, hf, type);
      }
    } else {
      return new RtfHeaderFooterGroup(this.document, type);
    }
  }
  /**
   * Get the <code>RtfListTable</code> object.
   *
   * @return the ListTable object.
   * @since 2.1.3
   */
  public RtfListTable getListTable() {
    return this.listTable;
  }
}
コード例 #13
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;
  }
コード例 #14
0
ファイル: RtfPageSetting.java プロジェクト: rototor/itext
/**
 * The RtfPageSetting stores the page size / page margins for a RtfDocument. INTERNAL CLASS - NOT TO
 * BE USED DIRECTLY
 *
 * @version $Id:RtfPageSetting.java 3126 2008-02-07 20:30:46Z hallm $
 * @author Mark Hall ([email protected])
 * @author Thomas Bickel ([email protected])
 */
public class RtfPageSetting extends RtfElement implements RtfExtendedElement {

  /** Constant for the page height */
  private static final byte[] PAGE_WIDTH = DocWriter.getISOBytes("\\paperw");
  /** Constant for the page width */
  private static final byte[] PAGE_HEIGHT = DocWriter.getISOBytes("\\paperh");
  /** Constant for the left margin */
  private static final byte[] MARGIN_LEFT = DocWriter.getISOBytes("\\margl");
  /** Constant for the right margin */
  private static final byte[] MARGIN_RIGHT = DocWriter.getISOBytes("\\margr");
  /** Constant for the top margin */
  private static final byte[] MARGIN_TOP = DocWriter.getISOBytes("\\margt");
  /** Constant for the bottom margin */
  private static final byte[] MARGIN_BOTTOM = DocWriter.getISOBytes("\\margb");
  /** Constant for landscape */
  private static final byte[] LANDSCAPE = DocWriter.getISOBytes("\\lndscpsxn");
  /** Constant for the section page width */
  private static final byte[] SECTION_PAGE_WIDTH = DocWriter.getISOBytes("\\pgwsxn");
  /** Constant for the section page height */
  private static final byte[] SECTION_PAGE_HEIGHT = DocWriter.getISOBytes("\\pghsxn");
  /** Constant for the section left margin */
  private static final byte[] SECTION_MARGIN_LEFT = DocWriter.getISOBytes("\\marglsxn");
  /** Constant for the section right margin */
  private static final byte[] SECTION_MARGIN_RIGHT = DocWriter.getISOBytes("\\margrsxn");
  /** Constant for the section top margin */
  private static final byte[] SECTION_MARGIN_TOP = DocWriter.getISOBytes("\\margtsxn");
  /** Constant for the section bottom margin */
  private static final byte[] SECTION_MARGIN_BOTTOM = DocWriter.getISOBytes("\\margbsxn");

  /** The page width to use */
  private int pageWidth = 11906;
  /** The page height to use */
  private int pageHeight = 16840;
  /** The left margin to use */
  private int marginLeft = 1800;
  /** The right margin to use */
  private int marginRight = 1800;
  /** The top margin to use */
  private int marginTop = 1440;
  /** The bottom margin to use */
  private int marginBottom = 1440;
  /** Whether the page is portrait or landscape */
  private boolean landscape = false;

  /**
   * Constructs a new RtfPageSetting object belonging to a RtfDocument.
   *
   * @param doc The RtfDocument this RtfPageSetting belongs to
   */
  public RtfPageSetting(RtfDocument doc) {
    super(doc);
  }

  /** unused */
  @Override
  public void writeContent(final OutputStream out) throws IOException {}

  /** Writes the page size / page margin definition */
  @Override
  public void writeDefinition(final OutputStream result) throws IOException {
    result.write(PAGE_WIDTH);
    result.write(intToByteArray(pageWidth));
    result.write(PAGE_HEIGHT);
    result.write(intToByteArray(pageHeight));
    result.write(MARGIN_LEFT);
    result.write(intToByteArray(marginLeft));
    result.write(MARGIN_RIGHT);
    result.write(intToByteArray(marginRight));
    result.write(MARGIN_TOP);
    result.write(intToByteArray(marginTop));
    result.write(MARGIN_BOTTOM);
    result.write(intToByteArray(marginBottom));
    this.document.outputDebugLinebreak(result);
  }

  /** Writes the definition part for a new section */
  public void writeSectionDefinition(final OutputStream result) throws IOException {
    if (landscape) {
      result.write(LANDSCAPE);
      result.write(SECTION_PAGE_WIDTH);
      result.write(intToByteArray(pageWidth));
      result.write(SECTION_PAGE_HEIGHT);
      result.write(intToByteArray(pageHeight));
      this.document.outputDebugLinebreak(result);
    } else {
      result.write(SECTION_PAGE_WIDTH);
      result.write(intToByteArray(pageWidth));
      result.write(SECTION_PAGE_HEIGHT);
      result.write(intToByteArray(pageHeight));
      this.document.outputDebugLinebreak(result);
    }
    result.write(SECTION_MARGIN_LEFT);
    result.write(intToByteArray(marginLeft));
    result.write(SECTION_MARGIN_RIGHT);
    result.write(intToByteArray(marginRight));
    result.write(SECTION_MARGIN_TOP);
    result.write(intToByteArray(marginTop));
    result.write(SECTION_MARGIN_BOTTOM);
    result.write(intToByteArray(marginBottom));
  }

  /**
   * Gets the bottom margin
   *
   * @return Returns the bottom margin
   */
  public int getMarginBottom() {
    return marginBottom;
  }

  /**
   * Sets the bottom margin
   *
   * @param marginBottom The bottom margin to use
   */
  public void setMarginBottom(int marginBottom) {
    this.marginBottom = marginBottom;
  }

  /**
   * Gets the left margin
   *
   * @return Returns the left margin
   */
  public int getMarginLeft() {
    return marginLeft;
  }

  /**
   * Sets the left margin to use
   *
   * @param marginLeft The left margin to use
   */
  public void setMarginLeft(int marginLeft) {
    this.marginLeft = marginLeft;
  }

  /**
   * Gets the right margin
   *
   * @return Returns the right margin
   */
  public int getMarginRight() {
    return marginRight;
  }

  /**
   * Sets the right margin to use
   *
   * @param marginRight The right margin to use
   */
  public void setMarginRight(int marginRight) {
    this.marginRight = marginRight;
  }

  /**
   * Gets the top margin
   *
   * @return Returns the top margin
   */
  public int getMarginTop() {
    return marginTop;
  }

  /**
   * Sets the top margin to use
   *
   * @param marginTop The top margin to use
   */
  public void setMarginTop(int marginTop) {
    this.marginTop = marginTop;
  }

  /**
   * Gets the page height
   *
   * @return Returns the page height
   */
  public int getPageHeight() {
    return pageHeight;
  }

  /**
   * Sets the page height to use
   *
   * @param pageHeight The page height to use
   */
  public void setPageHeight(int pageHeight) {
    this.pageHeight = pageHeight;
  }

  /**
   * Gets the page width
   *
   * @return Returns the page width
   */
  public int getPageWidth() {
    return pageWidth;
  }

  /**
   * Sets the page width to use
   *
   * @param pageWidth The page width to use
   */
  public void setPageWidth(int pageWidth) {
    this.pageWidth = pageWidth;
  }

  /**
   * Set the page size to use. This method will use guessFormat to try to guess the correct page
   * format. If no format could be guessed, the sizes from the pageSize are used and the landscape
   * setting is determined by comparing width and height;
   *
   * @param pageSize The pageSize to use
   */
  public void setPageSize(Rectangle pageSize) {
    if (!guessFormat(pageSize, false)) {
      this.pageWidth = (int) (pageSize.getWidth() * RtfElement.TWIPS_FACTOR);
      this.pageHeight = (int) (pageSize.getHeight() * RtfElement.TWIPS_FACTOR);
      this.landscape = pageWidth > pageHeight;
    }
  }

  /**
   * This method tries to fit the <code>Rectangle pageSize</code> to one of the predefined PageSize rectangles.
   * If a match is found the pageWidth and pageHeight will be set according to values determined from files
   * generated by MS Word2000 and OpenOffice 641. If no match is found the method will try to match the rotated
   * Rectangle by calling itself with the parameter rotate set to true.
   *
   * @param pageSize the page size for which to guess the correct format
   * @param rotate Whether we should try to rotate the size befor guessing the format
   * @return <code>True</code> if the format was guessed, <code>false/<code> otherwise
   */
  private boolean guessFormat(Rectangle pageSize, boolean rotate) {
    if (rotate) {
      pageSize = pageSize.rotate();
    }
    if (rectEquals(pageSize, PageSize.A3)) {
      pageWidth = 16837;
      pageHeight = 23811;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.A4)) {
      pageWidth = 11907;
      pageHeight = 16840;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.A5)) {
      pageWidth = 8391;
      pageHeight = 11907;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.A6)) {
      pageWidth = 5959;
      pageHeight = 8420;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.B4)) {
      pageWidth = 14570;
      pageHeight = 20636;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.B5)) {
      pageWidth = 10319;
      pageHeight = 14572;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.HALFLETTER)) {
      pageWidth = 7927;
      pageHeight = 12247;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.LETTER)) {
      pageWidth = 12242;
      pageHeight = 15842;
      landscape = rotate;
      return true;
    }
    if (rectEquals(pageSize, PageSize.LEGAL)) {
      pageWidth = 12252;
      pageHeight = 20163;
      landscape = rotate;
      return true;
    }
    if (!rotate && guessFormat(pageSize, true)) {
      int x = pageWidth;
      pageWidth = pageHeight;
      pageHeight = x;
      return true;
    }
    return false;
  }

  /**
   * This method compares to Rectangles. They are considered equal if width and height are the same
   *
   * @param rect1 The first Rectangle to compare
   * @param rect2 The second Rectangle to compare
   * @return <code>True</code> if the Rectangles equal, <code>false</code> otherwise
   */
  private boolean rectEquals(Rectangle rect1, Rectangle rect2) {
    return (rect1.getWidth() == rect2.getWidth()) && (rect1.getHeight() == rect2.getHeight());
  }
}