001/* 002 * $Id: PdfPage.java 4784 2011-03-15 08:33:00Z blowagie $ 003 * 004 * This file is part of the iText (R) project. 005 * Copyright (c) 1998-2011 1T3XT BVBA 006 * Authors: Bruno Lowagie, Paulo Soares, et al. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU Affero General Public License version 3 010 * as published by the Free Software Foundation with the addition of the 011 * following permission added to Section 15 as permitted in Section 7(a): 012 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY 1T3XT, 013 * 1T3XT DISCLAIMS THE WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 014 * 015 * This program is distributed in the hope that it will be useful, but 016 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 017 * or FITNESS FOR A PARTICULAR PURPOSE. 018 * See the GNU Affero General Public License for more details. 019 * You should have received a copy of the GNU Affero General Public License 020 * along with this program; if not, see http://www.gnu.org/licenses or write to 021 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 022 * Boston, MA, 02110-1301 USA, or download the license from the following URL: 023 * http://itextpdf.com/terms-of-use/ 024 * 025 * The interactive user interfaces in modified source and object code versions 026 * of this program must display Appropriate Legal Notices, as required under 027 * Section 5 of the GNU Affero General Public License. 028 * 029 * In accordance with Section 7(b) of the GNU Affero General Public License, 030 * a covered work must retain the producer line in every PDF that is created 031 * or manipulated using iText. 032 * 033 * You can be released from the requirements of the license by purchasing 034 * a commercial license. Buying such a license is mandatory as soon as you 035 * develop commercial activities involving the iText software without 036 * disclosing the source code of your own applications. 037 * These activities include: offering paid services to customers as an ASP, 038 * serving PDFs on the fly in a web application, shipping iText with a closed 039 * source product. 040 * 041 * For more information, please contact iText Software Corp. at this 042 * address: sales@itextpdf.com 043 */ 044package com.itextpdf.text.pdf; 045import java.util.HashMap; 046/** 047 * <CODE>PdfPage</CODE> is the PDF Page-object. 048 * <P> 049 * A Page object is a dictionary whose keys describe a single page containing text, 050 * graphics, and images. A Page object is a leaf of the Pages tree.<BR> 051 * This object is described in the 'Portable Document Format Reference Manual version 1.3' 052 * section 6.4 (page 73-81) 053 * 054 * @see PdfPages 055 */ 056 057public class PdfPage extends PdfDictionary { 058 059 private static final String boxStrings[] = {"crop", "trim", "art", "bleed"}; 060 private static final PdfName boxNames[] = {PdfName.CROPBOX, PdfName.TRIMBOX, PdfName.ARTBOX, PdfName.BLEEDBOX}; 061 // membervariables 062 063/** value of the <B>Rotate</B> key for a page in PORTRAIT */ 064 public static final PdfNumber PORTRAIT = new PdfNumber(0); 065 066/** value of the <B>Rotate</B> key for a page in LANDSCAPE */ 067 public static final PdfNumber LANDSCAPE = new PdfNumber(90); 068 069/** value of the <B>Rotate</B> key for a page in INVERTEDPORTRAIT */ 070 public static final PdfNumber INVERTEDPORTRAIT = new PdfNumber(180); 071 072/** value of the <B>Rotate</B> key for a page in SEASCAPE */ 073 public static final PdfNumber SEASCAPE = new PdfNumber(270); 074 075/** value of the <B>MediaBox</B> key */ 076 PdfRectangle mediaBox; 077 078 // constructors 079 080/** 081 * Constructs a <CODE>PdfPage</CODE>. 082 * 083 * @param mediaBox a value for the <B>MediaBox</B> key 084 * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object 085 * @param rotate a value for the <B>Rotate</B> key 086 */ 087 088// PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources, PdfNumber rotate) { 089// super(PAGE); 090// this.mediaBox = mediaBox; 091// put(PdfName.MEDIABOX, mediaBox); 092// put(PdfName.RESOURCES, resources); 093// if (rotate != null) { 094// put(PdfName.ROTATE, rotate); 095// } 096// if (cropBox != null) 097// put(PdfName.CROPBOX, new PdfRectangle(cropBox)); 098// } 099 100/** 101 * Constructs a <CODE>PdfPage</CODE>. 102 * 103 * @param mediaBox a value for the <B>MediaBox</B> key 104 * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object 105 * @param rotate a value for the <B>Rotate</B> key 106 */ 107 108 PdfPage(PdfRectangle mediaBox, HashMap<String, PdfRectangle> boxSize, PdfDictionary resources, int rotate) { 109 super(PAGE); 110 this.mediaBox = mediaBox; 111 put(PdfName.MEDIABOX, mediaBox); 112 put(PdfName.RESOURCES, resources); 113 if (rotate != 0) { 114 put(PdfName.ROTATE, new PdfNumber(rotate)); 115 } 116 for (int k = 0; k < boxStrings.length; ++k) { 117 PdfObject rect = boxSize.get(boxStrings[k]); 118 if (rect != null) 119 put(boxNames[k], rect); 120 } 121 } 122 123/** 124 * Constructs a <CODE>PdfPage</CODE>. 125 * 126 * @param mediaBox a value for the <B>MediaBox</B> key 127 * @param resources an indirect reference to a <CODE>PdfResources</CODE>-object 128 */ 129 130// PdfPage(PdfRectangle mediaBox, Rectangle cropBox, PdfIndirectReference resources) { 131// this(mediaBox, cropBox, resources, null); 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, HashMap<String, PdfRectangle> boxSize, PdfDictionary resources) { 142 this(mediaBox, boxSize, resources, 0); 143 } 144 145/** 146 * Checks if this page element is a tree of pages. 147 * <P> 148 * This method always returns <CODE>false</CODE>. 149 * 150 * @return <CODE>false</CODE> because this is a single page 151 */ 152 153 public boolean isParent() { 154 return false; 155 } 156 157 // methods 158 159/** 160 * Adds an indirect reference pointing to a <CODE>PdfContents</CODE>-object. 161 * 162 * @param contents an indirect reference to a <CODE>PdfContents</CODE>-object 163 */ 164 165 void add(PdfIndirectReference contents) { 166 put(PdfName.CONTENTS, contents); 167 } 168 169/** 170 * Rotates the mediabox, but not the text in it. 171 * 172 * @return a <CODE>PdfRectangle</CODE> 173 */ 174 175 PdfRectangle rotateMediaBox() { 176 this.mediaBox = mediaBox.rotate(); 177 put(PdfName.MEDIABOX, this.mediaBox); 178 return this.mediaBox; 179 } 180 181/** 182 * Returns the MediaBox of this Page. 183 * 184 * @return a <CODE>PdfRectangle</CODE> 185 */ 186 187 PdfRectangle getMediaBox() { 188 return mediaBox; 189 } 190}