123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- /*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* $Id$ */
-
- package org.apache.fop.pdf;
-
- import java.util.Date;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.text.SimpleDateFormat;
-
- /**
- * class representing an /Info object
- */
- public class PDFInfo extends PDFObject {
-
- /**
- * the application producing the PDF
- */
- private String producer;
-
- private String title = null;
- private String author = null;
- private String subject = null;
- private String keywords = null;
- private Date creationDate = null;
-
- /**
- * the name of the application that created the
- * original document before converting to PDF
- */
- private String creator;
-
- /**
- * set the producer string
- *
- * @param producer the producer string
- */
- public void setProducer(String producer) {
- this.producer = producer;
- }
-
- /**
- * set the creator string
- *
- * @param creator the document creator
- */
- public void setCreator(String creator) {
- this.creator = creator;
- }
-
- /**
- * set the title string
- *
- * @param t the document title
- */
- public void setTitle(String t) {
- this.title = t;
- }
-
- /**
- * set the author string
- *
- * @param a the document author
- */
- public void setAuthor(String a) {
- this.author = a;
- }
-
- /**
- * set the subject string
- *
- * @param s the document subject
- */
- public void setSubject(String s) {
- this.subject = s;
- }
-
- /**
- * set the keywords string
- *
- * @param k the keywords for this document
- */
- public void setKeywords(String k) {
- this.keywords = k;
- }
-
- /**
- * @return last set creation date
- */
- public Date getCreationDate() {
- return creationDate;
- }
-
- /**
- * @param date Date to store in the PDF as creation date. Use null to force current system date.
- */
- public void setCreationDate(Date date) {
- creationDate = date;
- }
-
- /**
- * @see org.apache.fop.pdf.PDFObject#toPDF()
- */
- public byte[] toPDF() {
- 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')
- if(creationDate==null) {
- creationDate = new Date();
- }
- final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
- final String str = sdf.format(creationDate) + "+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);
- }
- return bout.toByteArray();
- }
-
- }
|