]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
No object number in the constructor.
authorJeremias Maerki <jeremias@apache.org>
Thu, 27 Mar 2003 10:48:08 +0000 (10:48 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 27 Mar 2003 10:48:08 +0000 (10:48 +0000)
Support encryption of string and text values.
TODO: We need to improve generation of PDF dictionaries. The current way is suboptimal.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196161 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/pdf/PDFInfo.java

index 58cafb02dec4e686140990de9e65f22f6db9074c..01b443370fb0b4d393ddc98ff2d48a80269fc1ba 100644 (file)
@@ -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 @@ public class PDFInfo extends PDFObject {
     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 @@ public class PDFInfo extends PDFObject {
     }
 
     /**
-     * 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();
     }
 }