From fd0d2dfad7598a9f21398022f1279176a6621cf0 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 27 Mar 2003 10:48:08 +0000 Subject: [PATCH] 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. 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 | 91 +++++++++++++----------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/src/java/org/apache/fop/pdf/PDFInfo.java b/src/java/org/apache/fop/pdf/PDFInfo.java index 58cafb02d..01b443370 100644 --- a/src/java/org/apache/fop/pdf/PDFInfo.java +++ b/src/java/org/apache/fop/pdf/PDFInfo.java @@ -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(); } } -- 2.39.5