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.

PDFOutputIntent.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. import java.io.IOException;
  20. import org.apache.commons.io.IOUtils;
  21. import org.apache.commons.io.output.ByteArrayOutputStream;
  22. /**
  23. * Represents the OutputIntent dictionary.
  24. * @since PDF 1.4
  25. */
  26. public class PDFOutputIntent extends PDFObject {
  27. /** Subtype for PDF/X output intents */
  28. public static final String GTS_PDFX = "GTS_PDFX";
  29. /** Subtype for PDF/A-1 output intents */
  30. public static final String GTS_PDFA1 = "GTS_PDFA1";
  31. private String subtype; //S in the PDF spec
  32. private String outputCondition;
  33. private String outputConditionIdentifier;
  34. private String registryName;
  35. private String info;
  36. private PDFICCStream destOutputProfile;
  37. /** @return the output intent subtype. */
  38. public String getSubtype() {
  39. return subtype;
  40. }
  41. /**
  42. * Sets the output intent subtype.
  43. * @param subtype the subtype (usually "GTS_PDFX")
  44. */
  45. public void setSubtype(String subtype) {
  46. this.subtype = subtype;
  47. }
  48. /** @return the OutputCondition field */
  49. public String getOutputCondition() {
  50. return outputCondition;
  51. }
  52. /**
  53. * Sets the human-readable form of the output condition.
  54. * @param outputCondition A text string concisely identifying the intended output
  55. * device or production condition in human-readable form.
  56. */
  57. public void setOutputCondition(String outputCondition) {
  58. this.outputCondition = outputCondition;
  59. }
  60. /** @return the OutputConditionIdentifier field */
  61. public String getOutputConditionIdentifier() {
  62. return outputConditionIdentifier;
  63. }
  64. /**
  65. * Sets the identifier for the output condition.
  66. * @param outputConditionIdentifier A string identifying the intended output device or
  67. * production condition in human- or machine-readable form.
  68. */
  69. public void setOutputConditionIdentifier(String outputConditionIdentifier) {
  70. this.outputConditionIdentifier = outputConditionIdentifier;
  71. }
  72. /** @return the RegistryName field */
  73. public String getRegistryName() {
  74. return registryName;
  75. }
  76. /**
  77. * Sets the registry name.
  78. * @param registryName A string (conventionally a uniform resource identifier,
  79. * or URI) identifying the registry in which the condition designated
  80. * by OutputConditionIdentifier is defined.
  81. */
  82. public void setRegistryName(String registryName) {
  83. this.registryName = registryName;
  84. }
  85. /** @return the Info field */
  86. public String getInfo() {
  87. return info;
  88. }
  89. /**
  90. * Sets the Info field.
  91. * @param info A human-readable text string containing additional information or comments about
  92. * the intended target device or production condition.
  93. */
  94. public void setInfo(String info) {
  95. this.info = info;
  96. }
  97. /** @return the DestOutputProfile */
  98. public PDFICCStream getDestOutputProfile() {
  99. return destOutputProfile;
  100. }
  101. /**
  102. * Sets the destination ICC profile.
  103. * @param destOutputProfile An ICC profile stream defining the transformation from the PDF
  104. * document's source colors to output device colorants.
  105. */
  106. public void setDestOutputProfile(PDFICCStream destOutputProfile) {
  107. this.destOutputProfile = destOutputProfile;
  108. }
  109. /** {@inheritDoc} */
  110. public byte[] toPDF() {
  111. ByteArrayOutputStream bout = new ByteArrayOutputStream(128);
  112. try {
  113. bout.write(encode("<<\n"));
  114. bout.write(encode("/Type /OutputIntent\n"));
  115. bout.write(encode("/S /"));
  116. bout.write(encode(this.subtype));
  117. bout.write(encode("\n"));
  118. if (outputCondition != null) {
  119. bout.write(encode("/OutputCondition "));
  120. bout.write(encodeText(this.outputCondition));
  121. bout.write(encode("\n"));
  122. }
  123. bout.write(encode("/OutputConditionIdentifier "));
  124. bout.write(encodeText(this.outputConditionIdentifier));
  125. bout.write(encode("\n"));
  126. if (registryName != null) {
  127. bout.write(encode("/RegistryName "));
  128. bout.write(encodeText(this.registryName));
  129. bout.write(encode("\n"));
  130. }
  131. if (info != null) {
  132. bout.write(encode("/Info "));
  133. bout.write(encodeText(this.info));
  134. bout.write(encode("\n"));
  135. }
  136. if (destOutputProfile != null) {
  137. bout.write(encode("/DestOutputProfile " + destOutputProfile.referencePDF() + "\n"));
  138. }
  139. bout.write(encode(">>"));
  140. } catch (IOException ioe) {
  141. log.error("Ignored I/O exception", ioe);
  142. }
  143. byte[] bytes = bout.toByteArray();
  144. IOUtils.closeQuietly(bout);
  145. return bytes;
  146. }
  147. }