Java Code Examples for com.lowagie.text.DocWriter#getISOBytes()

The following examples show how to use com.lowagie.text.DocWriter#getISOBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfEncryptionValidateIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testSaveEncrypted() throws Exception {
  final URL url = getClass().getResource( "pdf-encryption-validate.xml" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  final byte[] b = createPDF( report );
  final PdfReader reader = new PdfReader( b, DocWriter.getISOBytes( "Duck" ) );
  assertTrue( reader.isEncrypted() );
}
 
Example 2
Source File: RtfDirectContent.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the element content to the given output stream.
 */    
public void writeContent(final OutputStream out) throws IOException
{
	final byte[] contentBytes = DocWriter.getISOBytes(this.directContent);
	out.write(contentBytes);
}
 
Example 3
Source File: PdfDocumentWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
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: " + userpassword + " - OwnerPassword: " + ownerpassword);
      final byte[] userpasswordbytes = DocWriter.getISOBytes( userpassword );
      byte[] ownerpasswordbytes = DocWriter.getISOBytes( ownerpassword );
      if ( ownerpasswordbytes == null ) {
        ownerpasswordbytes = PdfDocumentWriter.PDF_PASSWORD_PAD;
      }
      final int encryptionType;
      if ( encrypt.equals( PdfPageableModule.SECURITY_ENCRYPTION_128BIT ) ) {
        encryptionType = PdfWriter.STANDARD_ENCRYPTION_128;
      } else {
        encryptionType = PdfWriter.STANDARD_ENCRYPTION_40;
      }
      writer.setEncryption( userpasswordbytes, ownerpasswordbytes, getPermissions(), encryptionType );
    }
  }

  /**
   * MetaData can be set when the writer is registered to the document.
   */
  final String title =
      config.getConfigProperty( "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;
}
 
Example 4
Source File: PdfVersionImp.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Returns the version as a byte[].
 * @param version the version character
 */
public byte[] getVersionAsByteArray(char version) {
	return DocWriter.getISOBytes(getVersionAsName(version).toString().substring(1));
}
 
Example 5
Source File: PdfVersionImp.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Returns the version as a byte[].
 * @param version the version character
 */
public byte[] getVersionAsByteArray(char version) {
	return DocWriter.getISOBytes(getVersionAsName(version).toString().substring(1));
}
 
Example 6
Source File: RtfElement.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 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
 */
public byte[] intToByteArray(int i)
{
    return DocWriter.getISOBytes(Integer.toString(i));
}
 
Example 7
Source File: RtfFont.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 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
 */
protected byte[] intToByteArray(int i) {
    return DocWriter.getISOBytes(Integer.toString(i));
}
 
Example 8
Source File: RtfAddableElement.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 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
 */
public byte[] intToByteArray(int i) {
    return DocWriter.getISOBytes(Integer.toString(i));
}
 
Example 9
Source File: RtfCell.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 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));
}
 
Example 10
Source File: RtfDocumentSettings.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Author: Howard Shank ([email protected])
 * @return RTF document protection level as a byte array (byte[])
 * @since 2.1.1
 */
public byte[] getProtectionLevelBytes() {
	return DocWriter.getISOBytes(Integer.toString(convertProtectionLevel()));
}
 
Example 11
Source File: RtfDocumentSettings.java    From itext2 with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Obtain the password has as a byte array.
 * Author: Howard Shank ([email protected])
 * @return The bytes of the password hash as a byte array (byte[])
 * @since 2.1.1
 */
public byte[] getProtectionHashBytes() {
	return DocWriter.getISOBytes(this.protectionHash);
}
 
Example 12
Source File: PatchRtfCell.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 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 ) );
}