You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFInfo.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.pdf;
  8. import java.util.Date;
  9. import java.text.SimpleDateFormat;
  10. /**
  11. * class representing an /Info object
  12. */
  13. public class PDFInfo extends PDFObject {
  14. /**
  15. * the application producing the PDF
  16. */
  17. protected String producer;
  18. protected String title = null;
  19. protected String author = null;
  20. protected String subject = null;
  21. protected String keywords = null;
  22. // the name of the application that created the
  23. // original document before converting to PDF
  24. protected String creator;
  25. /**
  26. * create an Info object
  27. *
  28. * @param number the object's number
  29. */
  30. public PDFInfo(int number) {
  31. super(number);
  32. }
  33. /**
  34. * set the producer string
  35. *
  36. * @param producer the producer string
  37. */
  38. public void setProducer(String producer) {
  39. this.producer = producer;
  40. }
  41. public void setTitle(String t) {
  42. this.title = t;
  43. }
  44. public void setAuthor(String a) {
  45. this.author = a;
  46. }
  47. public void setSubject(String s) {
  48. this.subject = s;
  49. }
  50. public void setKeywords(String k) {
  51. this.keywords = k;
  52. }
  53. /**
  54. * produce the PDF representation of the object
  55. *
  56. * @return the PDF
  57. */
  58. public byte[] toPDF() {
  59. String p = this.number + " " + this.generation
  60. + " obj\n<< /Type /Info\n";
  61. if (title != null) {
  62. p += "/Title (" + this.title + ")\n";
  63. }
  64. if (author != null) {
  65. p += "/Author (" + this.author + ")\n";
  66. }
  67. if (subject != null) {
  68. p += "/Subject (" + this.subject + ")\n";
  69. }
  70. if (keywords != null) {
  71. p += "/Keywords (" + this.keywords + ")\n";
  72. }
  73. p += "/Producer (" + this.producer + ")\n";
  74. // creation date in form (D:YYYYMMDDHHmmSSOHH'mm')
  75. Date date = new Date();
  76. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  77. String str = sdf.format(date) + "+00'00'";
  78. p += "/CreationDate (D:" + str + ")";
  79. p += " >>\nendobj\n";
  80. return p.getBytes();
  81. }
  82. }