KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > pdf > PdfPage


1 /*
2  * $Id: PdfPage.java 2157 2006-02-16 16:17:59Z psoares33 $
3  * $Name$
4  *
5  * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text.pdf;
52 import java.util.HashMap JavaDoc;
53 /**
54  * <CODE>PdfPage</CODE> is the PDF Page-object.
55  * <P>
56  * A Page object is a dictionary whose keys describe a single page containing text,
57  * graphics, and images. A Page onjects is a leaf of the Pages tree.<BR>
58  * This object is described in the 'Portable Document Format Reference Manual version 1.3'
59  * section 6.4 (page 73-81)
60  *
61  * @see PdfPages
62  */

63
64 public class PdfPage extends PdfDictionary {
65
66     private static final String JavaDoc boxStrings[] = {"crop", "trim", "art", "bleed"};
67     private static final PdfName boxNames[] = {PdfName.CROPBOX, PdfName.TRIMBOX, PdfName.ARTBOX, PdfName.BLEEDBOX};
68     // membervariables
69

70 /** value of the <B>Rotate</B> key for a page in PORTRAIT */
71     public static final PdfNumber PORTRAIT = new PdfNumber(0);
72     
73 /** value of the <B>Rotate</B> key for a page in LANDSCAPE */
74     public static final PdfNumber LANDSCAPE = new PdfNumber(90);
75     
76 /** value of the <B>Rotate</B> key for a page in INVERTEDPORTRAIT */
77     public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
78     
79 /** value of the <B>Rotate</B> key for a page in SEASCAPE */
80     public static final PdfNumber SEASCAPE = new PdfNumber(270);
81     
82 /** value of the <B>MediaBox</B> key */
83     PdfRectangle mediaBox;
84     
85     // constructors
86

87 /**
88  * Constructs a <CODE>PdfPage</CODE>.
89  *
90  * @param mediaBox a value for the <B>MediaBox</B> key
91  * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
92  * @param rotate a value for the <B>Rotate</B> key
93  */

94     
95 // PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources, PdfNumber rotate) {
96
// super(PAGE);
97
// this.mediaBox = mediaBox;
98
// put(PdfName.MEDIABOX, mediaBox);
99
// put(PdfName.RESOURCES, resources);
100
// if (rotate != null) {
101
// put(PdfName.ROTATE, rotate);
102
// }
103
// if (cropBox != null)
104
// put(PdfName.CROPBOX, new PdfRectangle(cropBox));
105
// }
106

107 /**
108  * Constructs a <CODE>PdfPage</CODE>.
109  *
110  * @param mediaBox a value for the <B>MediaBox</B> key
111  * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
112  * @param rotate a value for the <B>Rotate</B> key
113  */

114     
115     PdfPage(PdfRectangle mediaBox, HashMap JavaDoc boxSize, PdfDictionary resources, int rotate) {
116         super(PAGE);
117         this.mediaBox = mediaBox;
118         put(PdfName.MEDIABOX, mediaBox);
119         put(PdfName.RESOURCES, resources);
120         if (rotate != 0) {
121             put(PdfName.ROTATE, new PdfNumber(rotate));
122         }
123         for (int k = 0; k < boxStrings.length; ++k) {
124             PdfObject rect = (PdfObject)boxSize.get(boxStrings[k]);
125             if (rect != null)
126                 put(boxNames[k], rect);
127         }
128     }
129     
130 /**
131  * Constructs a <CODE>PdfPage</CODE>.
132  *
133  * @param mediaBox a value for the <B>MediaBox</B> key
134  * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
135  */

136     
137 // PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources) {
138
// this(mediaBox, cropBox, resources, null);
139
// }
140

141 /**
142  * Constructs a <CODE>PdfPage</CODE>.
143  *
144  * @param mediaBox a value for the <B>MediaBox</B> key
145  * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
146  */

147     
148     PdfPage(PdfRectangle mediaBox, HashMap JavaDoc boxSize, PdfDictionary resources) {
149         this(mediaBox, boxSize, resources, 0);
150     }
151     
152 /**
153  * Checks if this page element is a tree of pages.
154  * <P>
155  * This method allways returns <CODE>false</CODE>.
156  *
157  * @return <CODE>false</CODE> because this is a single page
158  */

159     
160     public boolean isParent() {
161         return false;
162     }
163     
164     // methods
165

166 /**
167  * Adds an indirect reference pointing to a <CODE>PdfContents</CODE>-object.
168  *
169  * @param contents an indirect reference to a <CODE>PdfContents</CODE>-object
170  */

171     
172     void add(PdfIndirectReference contents) {
173         put(PdfName.CONTENTS, contents);
174     }
175     
176 /**
177  * Rotates the mediabox, but not the text in it.
178  *
179  * @return a <CODE>PdfRectangle</CODE>
180  */

181     
182     PdfRectangle rotateMediaBox() {
183         this.mediaBox = mediaBox.rotate();
184         put(PdfName.MEDIABOX, this.mediaBox);
185         return this.mediaBox;
186     }
187     
188 /**
189  * Returns the MediaBox of this Page.
190  *
191  * @return a <CODE>PdfRectangle</CODE>
192  */

193     
194     PdfRectangle getMediaBox() {
195         return mediaBox;
196     }
197 }
Popular Tags