001/*
002 * $Id: PageSize.java 4847 2011-05-05 19:46:13Z redlab_b $
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;
045
046import java.lang.reflect.Field;
047import com.itextpdf.text.error_messages.MessageLocalization;
048
049/**
050 * The <CODE>PageSize</CODE>-object contains a number of rectangles representing the most common paper sizes.
051 *
052 * @see         Rectangle
053 */
054
055public class PageSize {
056
057    // membervariables
058
059        /** This is the letter format */
060    public static final Rectangle LETTER = new RectangleReadOnly(612,792);
061
062    /** This is the note format */
063    public static final Rectangle NOTE = new RectangleReadOnly(540,720);
064
065    /** This is the legal format */
066    public static final Rectangle LEGAL = new RectangleReadOnly(612,1008);
067
068    /** This is the tabloid format */
069    public static final Rectangle TABLOID = new RectangleReadOnly(792,1224);
070
071    /** This is the executive format */
072    public static final Rectangle EXECUTIVE = new RectangleReadOnly(522,756);
073
074    /** This is the postcard format */
075    public static final Rectangle POSTCARD = new RectangleReadOnly(283,416);
076
077    /** This is the a0 format */
078    public static final Rectangle A0 = new RectangleReadOnly(2384,3370);
079
080    /** This is the a1 format */
081    public static final Rectangle A1 = new RectangleReadOnly(1684,2384);
082
083    /** This is the a2 format */
084    public static final Rectangle A2 = new RectangleReadOnly(1191,1684);
085
086    /** This is the a3 format */
087    public static final Rectangle A3 = new RectangleReadOnly(842,1191);
088
089    /** This is the a4 format */
090    public static final Rectangle A4 = new RectangleReadOnly(595,842);
091
092    /** This is the a5 format */
093    public static final Rectangle A5 = new RectangleReadOnly(420,595);
094
095    /** This is the a6 format */
096    public static final Rectangle A6 = new RectangleReadOnly(297,420);
097
098    /** This is the a7 format */
099    public static final Rectangle A7 = new RectangleReadOnly(210,297);
100
101    /** This is the a8 format */
102    public static final Rectangle A8 = new RectangleReadOnly(148,210);
103
104    /** This is the a9 format */
105    public static final Rectangle A9 = new RectangleReadOnly(105,148);
106
107    /** This is the a10 format */
108    public static final Rectangle A10 = new RectangleReadOnly(73,105);
109
110    /** This is the b0 format */
111    public static final Rectangle B0 = new RectangleReadOnly(2834,4008);
112
113    /** This is the b1 format */
114    public static final Rectangle B1 = new RectangleReadOnly(2004,2834);
115
116    /** This is the b2 format */
117    public static final Rectangle B2 = new RectangleReadOnly(1417,2004);
118
119    /** This is the b3 format */
120    public static final Rectangle B3 = new RectangleReadOnly(1000,1417);
121
122    /** This is the b4 format */
123    public static final Rectangle B4 = new RectangleReadOnly(708,1000);
124
125    /** This is the b5 format */
126    public static final Rectangle B5 = new RectangleReadOnly(498,708);
127
128    /** This is the b6 format */
129    public static final Rectangle B6 = new RectangleReadOnly(354,498);
130
131    /** This is the b7 format */
132    public static final Rectangle B7 = new RectangleReadOnly(249,354);
133
134    /** This is the b8 format */
135    public static final Rectangle B8 = new RectangleReadOnly(175,249);
136
137    /** This is the b9 format */
138    public static final Rectangle B9 = new RectangleReadOnly(124,175);
139
140    /** This is the b10 format */
141    public static final Rectangle B10 = new RectangleReadOnly(87,124);
142
143    /** This is the archE format */
144    public static final Rectangle ARCH_E = new RectangleReadOnly(2592,3456);
145
146    /** This is the archD format */
147    public static final Rectangle ARCH_D = new RectangleReadOnly(1728,2592);
148
149    /** This is the archC format */
150    public static final Rectangle ARCH_C = new RectangleReadOnly(1296,1728);
151
152    /** This is the archB format */
153    public static final Rectangle ARCH_B = new RectangleReadOnly(864,1296);
154
155    /** This is the archA format */
156    public static final Rectangle ARCH_A = new RectangleReadOnly(648,864);
157
158    /** This is the American Foolscap format */
159    public static final Rectangle FLSA = new RectangleReadOnly(612,936);
160
161    /** This is the European Foolscap format */
162    public static final Rectangle FLSE = new RectangleReadOnly(648,936);
163
164    /** This is the halfletter format */
165    public static final Rectangle HALFLETTER = new RectangleReadOnly(396,612);
166
167    /** This is the 11x17 format */
168    public static final Rectangle _11X17 = new RectangleReadOnly(792,1224);
169
170    /** This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch) */
171    public static final Rectangle ID_1 = new RectangleReadOnly(242.65f,153);
172
173    /** This is the ISO 7810 ID-2 format (A7 rotated) */
174    public static final Rectangle ID_2 = new RectangleReadOnly(297,210);
175
176    /** This is the ISO 7810 ID-3 format (B7 rotated) */
177    public static final Rectangle ID_3 = new RectangleReadOnly(354,249);
178
179    /** This is the ledger format */
180    public static final Rectangle LEDGER = new RectangleReadOnly(1224,792);
181
182    /** This is the Crown Quarto format */
183    public static final Rectangle CROWN_QUARTO = new RectangleReadOnly(535,697);
184
185    /** This is the Large Crown Quarto format */
186    public static final Rectangle LARGE_CROWN_QUARTO = new RectangleReadOnly(569,731);
187
188    /** This is the Demy Quarto format. */
189    public static final Rectangle DEMY_QUARTO = new RectangleReadOnly(620,782);
190
191    /** This is the Royal Quarto format. */
192    public static final Rectangle ROYAL_QUARTO = new RectangleReadOnly(671,884);
193
194    /** This is the Crown Octavo format */
195    public static final Rectangle CROWN_OCTAVO = new RectangleReadOnly(348,527);
196
197    /** This is the Large Crown Octavo format */
198    public static final Rectangle LARGE_CROWN_OCTAVO = new RectangleReadOnly(365,561);
199
200    /** This is the Demy Octavo format */
201    public static final Rectangle DEMY_OCTAVO = new RectangleReadOnly(391,612);
202
203    /** This is the Royal Octavo format. */
204    public static final Rectangle ROYAL_OCTAVO = new RectangleReadOnly(442,663);
205
206    /** This is the small paperback format. */
207    public static final Rectangle SMALL_PAPERBACK = new RectangleReadOnly(314,504);
208
209    /** This is the Pengiun small paperback format. */
210    public static final Rectangle PENGUIN_SMALL_PAPERBACK = new RectangleReadOnly(314,513);
211
212    /** This is the Penguin large paperback format. */
213    public static final Rectangle PENGUIN_LARGE_PAPERBACK = new RectangleReadOnly(365,561);
214
215    // Some extra shortcut values for pages in Landscape
216
217        /**
218         * This is the letter format
219         * @since iText 5.0.6
220         */
221    public static final Rectangle LETTER_LANDSCAPE = new RectangleReadOnly(612, 792, 90);
222
223    /**
224     * This is the legal format
225     * @since iText 5.0.6
226     */
227    public static final Rectangle LEGAL_LANDSCAPE = new RectangleReadOnly(612, 1008, 90);
228
229    /**
230     * This is the a4 format
231     * @since iText 5.0.6
232     */
233    public static final Rectangle A4_LANDSCAPE = new RectangleReadOnly(595, 842, 90);
234
235
236
237    /**
238     * This method returns a Rectangle based on a String.
239     * Possible values are the the names of a constant in this class
240     * (for instance "A4", "LETTER",...) or a value like "595 842"
241     * @param name the name as defined by the constants of PageSize or a numeric pair string
242     * @return the rectangle
243     */
244    public static Rectangle getRectangle(String name)  {
245        name = name.trim().toUpperCase();
246        int pos = name.indexOf(' ');
247        if (pos == -1) {
248            try {
249                Field field = PageSize.class.getDeclaredField(name.toUpperCase());
250                return (Rectangle) field.get(null);
251            } catch (Exception e) {
252                throw new RuntimeException(MessageLocalization.getComposedMessage("can.t.find.page.size.1", name));
253            }
254        }
255        else {
256                try {
257                        String width = name.substring(0, pos);
258                        String height = name.substring(pos + 1);
259                        return new Rectangle(Float.parseFloat(width), Float.parseFloat(height));
260                } catch(Exception e) {
261                        throw new RuntimeException(MessageLocalization.getComposedMessage("1.is.not.a.valid.page.size.format.2", name, e.getMessage()));
262                }
263        }
264    }
265}