Hello there,
I make just an ant task for merge, burst, with ... PDFBox.
For this I need the paper size (A4, A5, B2, ...).
public static PDRectangle getRectangle (final String name)
Since I have found nothing, I have a class with the main paper sizes
written (I hope the Annex is not cut).
Perhaps this can have someone need.
greeting
Michael
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.nm.ant.bpdf.util;
import java.util.HashMap;
import java.util.Map;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
/**
* Class for getting the page size as a {@link PDRectangle}.
*
* @author <a href="mailto:m....@gmx.de">Michael Niedermair</a>
* @version $Revision: 95 $
*
* @see <a href="https://de.wikipedia.org/wiki/Papierformat" >Wikipedia:
* Papierformat</a>
*/
public class PageSize {
/** see PDPage.DEFAULT_USER_SPACE_UNIT_DPI (private !!!!) */
private static final int DEFAULT_USER_SPACE_UNIT_DPI = 72;
/** see PDPage.MM_TO_UNITS (private !!!!) */
private static final float MM_TO_UNITS = 1 / (10 * 2.54f) * DEFAULT_USER_SPACE_UNIT_DPI;
/** the page size map */
private static Map<String, PDRectangle> ps = new HashMap<>(80);
/** store the entries */
static {
// DIN A...
ps.put("A0", PDPage.PAGE_SIZE_A0);
ps.put("A1", PDPage.PAGE_SIZE_A1);
ps.put("A2", PDPage.PAGE_SIZE_A2);
ps.put("A3", PDPage.PAGE_SIZE_A3);
ps.put("A4", PDPage.PAGE_SIZE_A4);
ps.put("A5", PDPage.PAGE_SIZE_A5);
ps.put("A6", PDPage.PAGE_SIZE_A6);
ps.put("A7", new PDRectangle(74 * MM_TO_UNITS, 105 * MM_TO_UNITS));
ps.put("A8", new PDRectangle(52 * MM_TO_UNITS, 74 * MM_TO_UNITS));
ps.put("A9", new PDRectangle(37 * MM_TO_UNITS, 52 * MM_TO_UNITS));
ps.put("A10", new PDRectangle(26 * MM_TO_UNITS, 37 * MM_TO_UNITS));
// DIN B...
ps.put("B0", new PDRectangle(1000 * MM_TO_UNITS, 1414 * MM_TO_UNITS));
ps.put("B1", new PDRectangle(707 * MM_TO_UNITS, 1000 * MM_TO_UNITS));
ps.put("B2", new PDRectangle(500 * MM_TO_UNITS, 707 * MM_TO_UNITS));
ps.put("B3", new PDRectangle(353 * MM_TO_UNITS, 500 * MM_TO_UNITS));
ps.put("B4", new PDRectangle(250 * MM_TO_UNITS, 353 * MM_TO_UNITS));
ps.put("B5", new PDRectangle(176 * MM_TO_UNITS, 250 * MM_TO_UNITS));
ps.put("B6", new PDRectangle(125 * MM_TO_UNITS, 176 * MM_TO_UNITS));
ps.put("B7", new PDRectangle(88 * MM_TO_UNITS, 125 * MM_TO_UNITS));
ps.put("B8", new PDRectangle(62 * MM_TO_UNITS, 88 * MM_TO_UNITS));
ps.put("B9", new PDRectangle(44 * MM_TO_UNITS, 62 * MM_TO_UNITS));
ps.put("B10", new PDRectangle(31 * MM_TO_UNITS, 44 * MM_TO_UNITS));
// DIN C...
ps.put("C0", new PDRectangle(917 * MM_TO_UNITS, 1297 * MM_TO_UNITS));
ps.put("C1", new PDRectangle(648 * MM_TO_UNITS, 917 * MM_TO_UNITS));
ps.put("C2", new PDRectangle(458 * MM_TO_UNITS, 648 * MM_TO_UNITS));
ps.put("C3", new PDRectangle(324 * MM_TO_UNITS, 458 * MM_TO_UNITS));
ps.put("C4", new PDRectangle(229 * MM_TO_UNITS, 324 * MM_TO_UNITS));
ps.put("C5", new PDRectangle(162 * MM_TO_UNITS, 229 * MM_TO_UNITS));
ps.put("C6", new PDRectangle(114 * MM_TO_UNITS, 162 * MM_TO_UNITS));
ps.put("C7", new PDRectangle(81 * MM_TO_UNITS, 114 * MM_TO_UNITS));
ps.put("C8", new PDRectangle(57 * MM_TO_UNITS, 81 * MM_TO_UNITS));
ps.put("C9", new PDRectangle(40 * MM_TO_UNITS, 57 * MM_TO_UNITS));
ps.put("C10", new PDRectangle(28 * MM_TO_UNITS, 40 * MM_TO_UNITS));
// DIN D...
ps.put("D0", new PDRectangle(771 * MM_TO_UNITS, 1091 * MM_TO_UNITS));
ps.put("D1", new PDRectangle(545 * MM_TO_UNITS, 771 * MM_TO_UNITS));
ps.put("D2", new PDRectangle(385 * MM_TO_UNITS, 545 * MM_TO_UNITS));
ps.put("D3", new PDRectangle(272 * MM_TO_UNITS, 385 * MM_TO_UNITS));
ps.put("D4", new PDRectangle(192 * MM_TO_UNITS, 272 * MM_TO_UNITS));
ps.put("D5", new PDRectangle(136 * MM_TO_UNITS, 192 * MM_TO_UNITS));
ps.put("D6", new PDRectangle(96 * MM_TO_UNITS, 136 * MM_TO_UNITS));
ps.put("D7", new PDRectangle(68 * MM_TO_UNITS, 96 * MM_TO_UNITS));
// Gebräuchliche nordamerikanische Papierformate
ps.put("LETTER", PDPage.PAGE_SIZE_LETTER);
ps.put("INVOICE", new PDRectangle(140 * MM_TO_UNITS, 216 * MM_TO_UNITS));
ps.put("LEGAL", new PDRectangle(216 * MM_TO_UNITS, 356 * MM_TO_UNITS));
ps.put("LEDGER", new PDRectangle(279 * MM_TO_UNITS, 432 * MM_TO_UNITS));
ps.put("TABLOID", new PDRectangle(279 * MM_TO_UNITS, 432 * MM_TO_UNITS));
ps.put("BROADSHEET", new PDRectangle(432 * MM_TO_UNITS, 559 * MM_TO_UNITS));
// Notendruckformate
ps.put("GROSSPARTITUR", new PDRectangle(420 * MM_TO_UNITS, 680 * MM_TO_UNITS));
ps.put("QUARTFORMAT", new PDRectangle(270 * MM_TO_UNITS, 340 * MM_TO_UNITS));
ps.put("BACHFORMAT", new PDRectangle(240 * MM_TO_UNITS, 325 * MM_TO_UNITS));
ps.put("N4", new PDRectangle(231 * MM_TO_UNITS, 303 * MM_TO_UNITS));
ps.put("OKTAVFORMAT", new PDRectangle(170 * MM_TO_UNITS, 270 * MM_TO_UNITS));
ps.put("STUDIENPARTITUR", new PDRectangle(170 * MM_TO_UNITS, 240 * MM_TO_UNITS));
ps.put("SALONORCHESTER", new PDRectangle(190 * MM_TO_UNITS, 290 * MM_TO_UNITS));
ps.put("KLAVIERAUSZUG", new PDRectangle(190 * MM_TO_UNITS, 270 * MM_TO_UNITS));
ps.put("PARISER FORMAT", new PDRectangle(190 * MM_TO_UNITS, 272 * MM_TO_UNITS));
ps.put("KLAVIERFORMAT", new PDRectangle(235 * MM_TO_UNITS, 310 * MM_TO_UNITS));
ps.put("GROSSMARSCH", new PDRectangle(135 * MM_TO_UNITS, 190 * MM_TO_UNITS));
ps.put("MARSCHFORMAT", new PDRectangle(135 * MM_TO_UNITS, 170 * MM_TO_UNITS));
// Historische europäische Formate
ps.put("OKTAV", new PDRectangle(142.f * MM_TO_UNITS, 225 * MM_TO_UNITS));
ps.put("QUART", new PDRectangle(225 * MM_TO_UNITS, 285 * MM_TO_UNITS));
ps.put("FOLIO", new PDRectangle(210 * MM_TO_UNITS, 330 * MM_TO_UNITS));
ps.put("BRIEF", new PDRectangle(270 * MM_TO_UNITS, 420 * MM_TO_UNITS));
ps.put("KANZLEI", new PDRectangle(330 * MM_TO_UNITS, 420 * MM_TO_UNITS));
ps.put("DOPPELFOLIO", new PDRectangle(330 * MM_TO_UNITS, 420 * MM_TO_UNITS));
ps.put("PROPATRIA", new PDRectangle(340 * MM_TO_UNITS, 430 * MM_TO_UNITS));
ps.put("GROSS PATRIA", new PDRectangle(360 * MM_TO_UNITS, 430 * MM_TO_UNITS));
ps.put("BISCHOF", new PDRectangle(380 * MM_TO_UNITS, 480 * MM_TO_UNITS));
ps.put("REGISTER", new PDRectangle(400 * MM_TO_UNITS, 500 * MM_TO_UNITS));
ps.put("LÃWEN", new PDRectangle(400 * MM_TO_UNITS, 500 * MM_TO_UNITS));
ps.put("MEDIAN I", new PDRectangle(420 * MM_TO_UNITS, 530 * MM_TO_UNITS));
ps.put("MEDIAN", new PDRectangle(440 * MM_TO_UNITS, 560 * MM_TO_UNITS));
ps.put("POST", new PDRectangle(460 * MM_TO_UNITS, 560 * MM_TO_UNITS));
ps.put("MEDIAN II", new PDRectangle(460 * MM_TO_UNITS, 590 * MM_TO_UNITS));
ps.put("KLEIN ROYAL", new PDRectangle(480 * MM_TO_UNITS, 640 * MM_TO_UNITS));
ps.put("ROYAL", new PDRectangle(480 * MM_TO_UNITS, 650 * MM_TO_UNITS));
ps.put("LEXIKON", new PDRectangle(500 * MM_TO_UNITS, 650 * MM_TO_UNITS));
ps.put("SUPER ROYAL", new PDRectangle(500 * MM_TO_UNITS, 680 * MM_TO_UNITS));
ps.put("IMPERIAL", new PDRectangle(570 * MM_TO_UNITS, 780 * MM_TO_UNITS));
ps.put("OLIFANT", new PDRectangle(675 * MM_TO_UNITS, 1082 * MM_TO_UNITS));
}
/**
* Search the page size.
*
* @param name The name (A4, A5, ...) of the page format.
* @return the {@link PDRectangle} of the page size or
* {@link PDPage.PAGE_SIZE_A4} if not found.
*/
public static PDRectangle getRectangle(final String name) {
if (name != null) {
final PDRectangle rec = ps.get(name.toUpperCase());
if (rec != null) {
return rec;
}
}
// use default - A4
return PDPage.PAGE_SIZE_A4;
}
/**
* Rotate the {@link PDRectangle}, e.g. for 'landscape'.
*
* @param rec the rectangle
* @return the new rotated rectangle
*/
public static PDRectangle rotate(final PDRectangle rec) {
if (rec == null) {
throw new IllegalArgumentException("'rec' must be set!");
}
return new PDRectangle(rec.getHeight(), rec.getWidth());
}
// public static void main(final String[] args) {
//
// System.out.println("count : " + ps.size());
// System.out.println();
// System.out.println(PageSize.getRectangle("A3"));
// System.out.println(PageSize.getRectangle("a4"));
// System.out.println(PageSize.getRectangle("nicht da"));
// System.out.println(PageSize.getRectangle(null));
// System.out.println();
// System.out.println(PageSize.getRectangle("a4"));
// System.out.println(PageSize.rotate(PageSize.getRectangle("a4")));
//
// }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org