You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2003/03/27 11:48:09 UTC

cvs commit: xml-fop/src/java/org/apache/fop/pdf PDFInfo.java

jeremias    2003/03/27 02:48:08

  Modified:    src/java/org/apache/fop/pdf PDFInfo.java
  Log:
  No object number in the constructor.
  Support encryption of string and text values.
  TODO: We need to improve generation of PDF dictionaries. The current way is suboptimal.
  
  Revision  Changes    Path
  1.2       +51 -40    xml-fop/src/java/org/apache/fop/pdf/PDFInfo.java
  
  Index: PDFInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/pdf/PDFInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PDFInfo.java	11 Mar 2003 13:05:09 -0000	1.1
  +++ PDFInfo.java	27 Mar 2003 10:48:08 -0000	1.2
  @@ -51,6 +51,8 @@
   package org.apache.fop.pdf;
   
   import java.util.Date;
  +import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
   import java.text.SimpleDateFormat;
   
   /**
  @@ -68,18 +70,11 @@
       private String subject = null;
       private String keywords = null;
   
  -    // the name of the application that created the
  -    // original document before converting to PDF
  -    private String creator;
  -
       /**
  -     * create an Info object
  -     *
  -     * @param number the object's number
  +     * the name of the application that created the
  +     * original document before converting to PDF
        */
  -    public PDFInfo(int number) {
  -        super(number);
  -    }
  +    private String creator;
   
       /**
        * set the producer string
  @@ -136,39 +131,55 @@
       }
   
       /**
  -     * produce the PDF representation of the object
  -     *
  -     * @return the PDF
  +     * @see org.apache.fop.pdf.PDFObject#toPDF()
        */
       public byte[] toPDF() {
  -        String p = this.number + " " + this.generation
  -                   + " obj\n<< /Type /Info\n";
  -        if (title != null) {
  -            p += "/Title (" + this.title + ")\n";
  -        }
  -        if (author != null) {
  -            p += "/Author (" + this.author + ")\n";
  +        ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
  +        try {
  +            bout.write(encode(getObjectID()));
  +            bout.write(encode("<< /Type /Info\n"));
  +            if (title != null) {
  +                bout.write(encode("/Title "));
  +                bout.write(encodeText(this.title));
  +                bout.write(encode("\n"));
  +            }
  +            if (author != null) {
  +                bout.write(encode("/Author "));
  +                bout.write(encodeText(this.author));
  +                bout.write(encode("\n"));
  +            }
  +            if (subject != null) {
  +                bout.write(encode("/Subject "));
  +                bout.write(encodeText(this.subject));
  +                bout.write(encode("\n"));
  +            }
  +            if (keywords != null) {
  +                bout.write(encode("/Keywords "));
  +                bout.write(encodeText(this.keywords));
  +                bout.write(encode("\n"));
  +            }
  +    
  +            if (creator != null) {
  +                bout.write(encode("/Creator "));
  +                bout.write(encodeText(this.creator));
  +                bout.write(encode("\n"));
  +            }
  +    
  +            bout.write(encode("/Producer "));
  +            bout.write(encodeText(this.producer));
  +            bout.write(encode("\n"));
  +    
  +            // creation date in form (D:YYYYMMDDHHmmSSOHH'mm')
  +            final Date date = new Date();
  +            final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  +            final String str = sdf.format(date) + "+00'00'";
  +            bout.write(encode("/CreationDate "));
  +            bout.write(encodeString("D:" + str));
  +            bout.write(encode("\n>>\nendobj\n"));
  +        } catch (IOException ioe) {
  +            getDocumentSafely().getLogger().error("Ignored I/O exception", ioe);
           }
  -        if (subject != null) {
  -            p += "/Subject (" + this.subject + ")\n";
  -        }
  -        if (keywords != null) {
  -            p += "/Keywords (" + this.keywords + ")\n";
  -        }
  -
  -        if (creator != null) {
  -            p += "/Creator (" + this.creator + ")\n";
  -        }
  -
  -        p += "/Producer (" + this.producer + ")\n";
  -
  -        // creation date in form (D:YYYYMMDDHHmmSSOHH'mm')
  -        Date date = new Date();
  -        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  -        String str = sdf.format(date) + "+00'00'";
  -        p += "/CreationDate (D:" + str + ")";
  -        p += " >>\nendobj\n";
  -        return p.getBytes();
  +        return bout.toByteArray();
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org