1 51 package org.apache.fop.pdf; 52 53 import java.io.UnsupportedEncodingException ; 55 import java.util.*; 56 57 60 public class PDFRoot extends PDFObject { 61 62 65 protected PDFPages rootPages; 66 67 70 private PDFOutline _outline; 71 72 75 private Collection _destinations; 76 77 86 public PDFRoot(int number, PDFPages pages) { 87 super(number); 88 setRootPages(pages); 89 } 90 91 96 void setNumber(int number) { 97 this.number = number; 98 } 99 100 105 public void addPage(PDFPage page) { 106 this.rootPages.addPage(page); 107 } 108 109 114 public void setRootPages(PDFPages pages) { 115 this.rootPages = pages; 116 } 117 118 public void setRootOutline(PDFOutline outline) { 119 _outline = outline; 120 } 121 122 public PDFOutline getRootOutline() { 123 return _outline; 124 } 125 126 public Collection getDestinations() { 127 if (_destinations == null) { 128 _destinations = new ArrayList(); 129 } 130 return _destinations; 131 } 132 133 134 142 public byte[] toPDF() 143 throws IllegalStateException { 144 StringBuffer p = new StringBuffer (this.number + " " + this.generation 145 + " obj\n<< /Type /Catalog\n/Pages " 146 + this.rootPages.referencePDF() 147 + "\n"); 148 if (_outline != null) { 149 p.append(" /Outlines " + _outline.referencePDF() + "\n"); 150 p.append(" /PageMode /UseOutlines\n"); 151 152 } 153 if (_destinations != null) { 154 p.append(" /Names << /Dests << /Names [ "); 155 for (Iterator i = _destinations.iterator(); i.hasNext(); ) { 156 PDFDestination dest = (PDFDestination)i.next(); 157 p.append(dest.toPDF()); 158 } 159 p.append(" ] >> >>\n"); 160 } 161 p.append(" >>\nendobj\n"); 162 163 try { 164 return p.toString().getBytes(PDFDocument.ENCODING); 165 } catch (UnsupportedEncodingException ue) { 166 return p.toString().getBytes(); 167 } 168 } 169 170 } 171 | Popular Tags |