blob: 2bae2b91b10989bb40b31d8de071c3530f6a99d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.pdf;
// Java
import java.io.IOException;
import java.io.PrintWriter;
/**
* class representing a Root (/Catalog) object
*/
public class PDFRoot extends PDFObject {
/**
* the /Pages object that is root of the Pages hierarchy
*/
protected PDFPages rootPages;
/**
* Root outline object
*/
private PDFOutline _outline;
/**
* create a Root (/Catalog) object. NOTE: The PDFRoot
* object must be created before the PDF document is
* generated, but it is not assigned an object ID until
* it is about to be written (immediately before the xref
* table as part of the trsailer). (mark-fop@inomial.com)
*
* @param number the object's number
*/
public PDFRoot(int number, PDFPages pages) {
super(number);
setRootPages(pages);
}
/**
* Before the root is written to the document stream,
* make sure it's object number is set. Package-private access
* only; outsiders should not be fiddling with this stuff.
*/
void setNumber(int number) {
this.number = number;
}
/**
* add a /Page object to the root /Pages object
*
* @param page the /Page object to add
*/
public void addPage(PDFPage page) {
this.rootPages.addPage(page);
}
/**
* set the root /Pages object
*
* @param pages the /Pages object to set as root
*/
public void setRootPages(PDFPages pages) {
this.rootPages = pages;
}
public void setRootOutline(PDFOutline outline) {
_outline = outline;
}
public PDFOutline getRootOutline()
{
return _outline;
}
/**
* represent the object as PDF.
*
* @throws IllegalStateException if the setNumber() method has
* not been called.
*
* @return the PDF string
*/
public byte[] toPDF()
throws IllegalStateException
{
StringBuffer p = new StringBuffer(this.number + " " + this.generation
+ " obj\n<< /Type /Catalog\n/Pages "
+ this.rootPages.referencePDF()
+ "\n");
if (_outline != null) {
p.append(" /Outlines " + _outline.referencePDF() + "\n");
p.append(" /PageMode /UseOutlines\n");
}
p.append(" >>\nendobj\n");
return p.toString().getBytes();
}
}
|