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.

PDFRoot.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 Root (/Catalog) object
  20. */
  21. public class PDFRoot extends PDFObject {
  22. /**
  23. * Use no page mode setting, default
  24. */
  25. public static final int PAGEMODE_USENONE = 0;
  26. /**
  27. * Use outlines page mode to show bookmarks
  28. */
  29. public static final int PAGEMODE_USEOUTLINES = 1;
  30. /**
  31. * Use thumbs page mode to show thumbnail images
  32. */
  33. public static final int PAGEMODE_USETHUMBS = 2;
  34. /**
  35. * Full screen page mode
  36. */
  37. public static final int PAGEMODE_FULLSCREEN = 3;
  38. /**
  39. * the /Pages object that is root of the Pages hierarchy
  40. */
  41. protected PDFPages rootPages;
  42. /**
  43. * Root outline object
  44. */
  45. private PDFOutline outline;
  46. private int pageMode = PAGEMODE_USENONE;
  47. /**
  48. * create a Root (/Catalog) object. NOTE: The PDFRoot
  49. * object must be created before the PDF document is
  50. * generated, but it is not assigned an object ID until
  51. * it is about to be written (immediately before the xref
  52. * table as part of the trsailer). (mark-fop@inomial.com)
  53. *
  54. * @param objnum the object's number
  55. * @param pages the PDFPages object
  56. */
  57. public PDFRoot(int objnum, PDFPages pages) {
  58. super();
  59. setObjectNumber(objnum);
  60. setRootPages(pages);
  61. }
  62. /**
  63. * Set the page mode for the PDF document.
  64. *
  65. * @param mode the page mode
  66. */
  67. public void setPageMode(int mode) {
  68. pageMode = mode;
  69. }
  70. /**
  71. * add a /Page object to the root /Pages object
  72. *
  73. * @param page the /Page object to add
  74. */
  75. public void addPage(PDFPage page) {
  76. this.rootPages.addPage(page);
  77. }
  78. /**
  79. * set the root /Pages object
  80. *
  81. * @param pages the /Pages object to set as root
  82. */
  83. public void setRootPages(PDFPages pages) {
  84. this.rootPages = pages;
  85. }
  86. /**
  87. * Set the root outline for the PDF document.
  88. *
  89. * @param out the root PDF Outline
  90. */
  91. public void setRootOutline(PDFOutline out) {
  92. outline = out;
  93. }
  94. /**
  95. * Get the root PDF outline for the document.
  96. *
  97. * @return the root PDF Outline
  98. */
  99. public PDFOutline getRootOutline() {
  100. return outline;
  101. }
  102. /**
  103. * @see org.apache.fop.pdf.PDFObject#toPDFString()
  104. */
  105. public String toPDFString() {
  106. StringBuffer p = new StringBuffer(128);
  107. p.append(getObjectID());
  108. p.append("<< /Type /Catalog\n/Pages "
  109. + this.rootPages.referencePDF()
  110. + "\n");
  111. if (outline != null) {
  112. p.append(" /Outlines " + outline.referencePDF() + "\n");
  113. p.append(" /PageMode /UseOutlines\n");
  114. } else {
  115. switch (pageMode) {
  116. case PAGEMODE_USEOUTLINES:
  117. p.append(" /PageMode /UseOutlines\n");
  118. break;
  119. case PAGEMODE_USETHUMBS:
  120. p.append(" /PageMode /UseThumbs\n");
  121. break;
  122. case PAGEMODE_FULLSCREEN:
  123. p.append(" /PageMode /FullScreen\n");
  124. break;
  125. case PAGEMODE_USENONE:
  126. default:
  127. break;
  128. }
  129. }
  130. p.append(">>\nendobj\n");
  131. return p.toString();
  132. }
  133. }