001: /*
002: * $Id: PdfPage.java 2157 2006-02-16 16:17:59Z psoares33 $
003: * $Name$
004: *
005: * Copyright 1999, 2000, 2001, 2002 Bruno Lowagie
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: */
050:
051: package com.lowagie.text.pdf;
052:
053: import java.util.HashMap;
054:
055: /**
056: * <CODE>PdfPage</CODE> is the PDF Page-object.
057: * <P>
058: * A Page object is a dictionary whose keys describe a single page containing text,
059: * graphics, and images. A Page onjects is a leaf of the Pages tree.<BR>
060: * This object is described in the 'Portable Document Format Reference Manual version 1.3'
061: * section 6.4 (page 73-81)
062: *
063: * @see PdfPages
064: */
065:
066: public class PdfPage extends PdfDictionary {
067:
068: private static final String boxStrings[] = { "crop", "trim", "art",
069: "bleed" };
070: private static final PdfName boxNames[] = { PdfName.CROPBOX,
071: PdfName.TRIMBOX, PdfName.ARTBOX, PdfName.BLEEDBOX };
072: // membervariables
073:
074: /** value of the <B>Rotate</B> key for a page in PORTRAIT */
075: public static final PdfNumber PORTRAIT = new PdfNumber(0);
076:
077: /** value of the <B>Rotate</B> key for a page in LANDSCAPE */
078: public static final PdfNumber LANDSCAPE = new PdfNumber(90);
079:
080: /** value of the <B>Rotate</B> key for a page in INVERTEDPORTRAIT */
081: public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180);
082:
083: /** value of the <B>Rotate</B> key for a page in SEASCAPE */
084: public static final PdfNumber SEASCAPE = new PdfNumber(270);
085:
086: /** value of the <B>MediaBox</B> key */
087: PdfRectangle mediaBox;
088:
089: // constructors
090:
091: /**
092: * Constructs a <CODE>PdfPage</CODE>.
093: *
094: * @param mediaBox a value for the <B>MediaBox</B> key
095: * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
096: * @param rotate a value for the <B>Rotate</B> key
097: */
098:
099: // PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources, PdfNumber rotate) {
100: // super(PAGE);
101: // this.mediaBox = mediaBox;
102: // put(PdfName.MEDIABOX, mediaBox);
103: // put(PdfName.RESOURCES, resources);
104: // if (rotate != null) {
105: // put(PdfName.ROTATE, rotate);
106: // }
107: // if (cropBox != null)
108: // put(PdfName.CROPBOX, new PdfRectangle(cropBox));
109: // }
110: /**
111: * Constructs a <CODE>PdfPage</CODE>.
112: *
113: * @param mediaBox a value for the <B>MediaBox</B> key
114: * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
115: * @param rotate a value for the <B>Rotate</B> key
116: */
117:
118: PdfPage(PdfRectangle mediaBox, HashMap boxSize,
119: PdfDictionary resources, int rotate) {
120: super (PAGE);
121: this .mediaBox = mediaBox;
122: put(PdfName.MEDIABOX, mediaBox);
123: put(PdfName.RESOURCES, resources);
124: if (rotate != 0) {
125: put(PdfName.ROTATE, new PdfNumber(rotate));
126: }
127: for (int k = 0; k < boxStrings.length; ++k) {
128: PdfObject rect = (PdfObject) boxSize.get(boxStrings[k]);
129: if (rect != null)
130: put(boxNames[k], rect);
131: }
132: }
133:
134: /**
135: * Constructs a <CODE>PdfPage</CODE>.
136: *
137: * @param mediaBox a value for the <B>MediaBox</B> key
138: * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
139: */
140:
141: // PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources) {
142: // this(mediaBox, cropBox, resources, null);
143: // }
144: /**
145: * Constructs a <CODE>PdfPage</CODE>.
146: *
147: * @param mediaBox a value for the <B>MediaBox</B> key
148: * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object
149: */
150:
151: PdfPage(PdfRectangle mediaBox, HashMap boxSize,
152: PdfDictionary resources) {
153: this (mediaBox, boxSize, resources, 0);
154: }
155:
156: /**
157: * Checks if this page element is a tree of pages.
158: * <P>
159: * This method allways returns <CODE>false</CODE>.
160: *
161: * @return <CODE>false</CODE> because this is a single page
162: */
163:
164: public boolean isParent() {
165: return false;
166: }
167:
168: // methods
169:
170: /**
171: * Adds an indirect reference pointing to a <CODE>PdfContents</CODE>-object.
172: *
173: * @param contents an indirect reference to a <CODE>PdfContents</CODE>-object
174: */
175:
176: void add(PdfIndirectReference contents) {
177: put(PdfName.CONTENTS, contents);
178: }
179:
180: /**
181: * Rotates the mediabox, but not the text in it.
182: *
183: * @return a <CODE>PdfRectangle</CODE>
184: */
185:
186: PdfRectangle rotateMediaBox() {
187: this .mediaBox = mediaBox.rotate();
188: put(PdfName.MEDIABOX, this .mediaBox);
189: return this .mediaBox;
190: }
191:
192: /**
193: * Returns the MediaBox of this Page.
194: *
195: * @return a <CODE>PdfRectangle</CODE>
196: */
197:
198: PdfRectangle getMediaBox() {
199: return mediaBox;
200: }
201: }
|