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.

PDFPages.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // Java
  19. import java.util.List;
  20. import java.util.ArrayList;
  21. /**
  22. * class representing a /Pages object.
  23. *
  24. * A /Pages object is an ordered collection of pages (/Page objects)
  25. * (Actually, /Pages can contain further /Pages as well but this
  26. * implementation doesn't allow this)
  27. */
  28. public class PDFPages extends PDFObject {
  29. /**
  30. * the /Page objects
  31. */
  32. protected List kids = new ArrayList();
  33. /**
  34. * the number of /Page objects
  35. */
  36. protected int count = 0;
  37. // private PDFPages parent;
  38. /**
  39. * create a /Pages object. NOTE: The PDFPages
  40. * object must be created before the PDF document is
  41. * generated, but it is not written to the stream immediately.
  42. * It must also be allocated an object ID (so that the kids
  43. * can refer to the parent) so that the XRef table needs to
  44. * be updated before this object is written.
  45. *
  46. * @param objnum the object's number
  47. */
  48. public PDFPages(int objnum) {
  49. super();
  50. setObjectNumber(objnum);
  51. }
  52. /**
  53. * add a /Page object.
  54. *
  55. * @param page the PDFPage to add.
  56. */
  57. public void addPage(PDFPage page) {
  58. page.setParent(this);
  59. this.incrementCount();
  60. }
  61. /**
  62. * Use this method to notify the PDFPages object that a child page
  63. * @param page the child page
  64. */
  65. public void notifyKidRegistered(PDFPage page) {
  66. this.kids.add(page.referencePDF());
  67. }
  68. /**
  69. * get the count of /Page objects
  70. *
  71. * @return the number of pages
  72. */
  73. public int getCount() {
  74. return this.count;
  75. }
  76. /**
  77. * increment the count of /Page objects
  78. */
  79. public void incrementCount() {
  80. this.count++;
  81. // log.debug("Incrementing count to " + this.getCount());
  82. }
  83. /**
  84. * @see org.apache.fop.pdf.PDFObject#toPDFString()
  85. */
  86. public String toPDFString() {
  87. StringBuffer sb = new StringBuffer(64);
  88. sb.append(getObjectID()).
  89. append("<< /Type /Pages\n/Count ").
  90. append(this.getCount()).
  91. append("\n/Kids [");
  92. for (int i = 0; i < kids.size(); i++) {
  93. sb.append(kids.get(i)).append(" ");
  94. }
  95. sb.append("] >>\nendobj\n");
  96. return sb.toString();
  97. }
  98. }