Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PDFPage.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.pdf;
  18. /**
  19. * Class representing a /Page object.
  20. * <p>
  21. * There is one of these for every page in a PDF document. The object
  22. * specifies the dimensions of the page and references a /Resources
  23. * object, a contents stream and the page's parent in the page
  24. * hierarchy.
  25. */
  26. public class PDFPage extends PDFResourceContext {
  27. /**
  28. * Holds a reference on the parent PDFPages object.
  29. */
  30. private String parentRef;
  31. /**
  32. * the contents stream
  33. */
  34. protected PDFStream contents;
  35. /**
  36. * the width of the page in points
  37. */
  38. protected int pagewidth;
  39. /**
  40. * the height of the page in points
  41. */
  42. protected int pageheight;
  43. /**
  44. * Duration to display page
  45. */
  46. protected int duration = -1;
  47. /**
  48. * Transition dictionary
  49. */
  50. protected TransitionDictionary trDictionary = null;
  51. /**
  52. * create a /Page object
  53. *
  54. * @param resources the /Resources object
  55. * @param contents the content stream
  56. * @param pagewidth the page's width in points
  57. * @param pageheight the page's height in points
  58. */
  59. public PDFPage(PDFResources resources, PDFStream contents,
  60. int pagewidth, int pageheight) {
  61. /* generic creation of object */
  62. super(resources);
  63. /* set fields using parameters */
  64. this.contents = contents;
  65. this.pagewidth = pagewidth;
  66. this.pageheight = pageheight;
  67. }
  68. /**
  69. * create a /Page object
  70. *
  71. * @param resources the /Resources object
  72. * @param pagewidth the page's width in points
  73. * @param pageheight the page's height in points
  74. */
  75. public PDFPage(PDFResources resources,
  76. int pagewidth, int pageheight) {
  77. /* generic creation of object */
  78. super(resources);
  79. /* set fields using parameters */
  80. this.pagewidth = pagewidth;
  81. this.pageheight = pageheight;
  82. }
  83. /**
  84. * set this page contents
  85. *
  86. * @param contents the contents of the page
  87. */
  88. public void setContents(PDFStream contents) {
  89. this.contents = contents;
  90. }
  91. /**
  92. * set this page's parent
  93. *
  94. * @param parent the /Pages object that is this page's parent
  95. */
  96. public void setParent(PDFPages parent) {
  97. this.parentRef = parent.referencePDF();
  98. }
  99. /**
  100. * Set the transition dictionary and duration.
  101. * This sets the duration of the page and the transition
  102. * dictionary used when going to the next page.
  103. *
  104. * @param dur the duration in seconds
  105. * @param tr the transition dictionary
  106. */
  107. public void setTransition(int dur, TransitionDictionary tr) {
  108. duration = dur;
  109. trDictionary = tr;
  110. }
  111. /**
  112. * Returns the page width.
  113. * @return the page width
  114. */
  115. public int getWidth() {
  116. return this.pagewidth;
  117. }
  118. /**
  119. * Returns the page height.
  120. * @return the page height
  121. */
  122. public int getHeight() {
  123. return this.pageheight;
  124. }
  125. /**
  126. * @see org.apache.fop.pdf.PDFObject#toPDFString()
  127. */
  128. public String toPDFString() {
  129. StringBuffer sb = new StringBuffer();
  130. sb = sb.append(getObjectID()
  131. + "<< /Type /Page\n"
  132. + "/Parent " + this.parentRef + "\n"
  133. + "/MediaBox [ 0 0 " + getWidth() + " "
  134. + getHeight() + " ]\n"
  135. + "/Resources " + this.resources.referencePDF() + "\n"
  136. + "/Contents " + this.contents.referencePDF() + "\n");
  137. if (this.annotList != null) {
  138. sb = sb.append("/Annots " + this.annotList.referencePDF() + "\n");
  139. }
  140. if (this.duration != -1) {
  141. sb = sb.append("/Dur " + this.duration + "\n");
  142. }
  143. if (this.trDictionary != null) {
  144. sb = sb.append("/Trans << " + this.trDictionary.getDictionary() + " >>\n");
  145. }
  146. sb = sb.append(">>\nendobj\n");
  147. return sb.toString();
  148. }
  149. }