iText では出力する PDF の紙のサイズを com.lowagie.text.Rectangle クラスのオブジェクトで指定できる。

A4 とか B5 とか有名な紙の大きさについては com.lowagie.text.PageSize クラスが定数の Rectangle オブジェクトを持っている。

その Rectangle 定数の一覧を表にしてみた。

定数名説明サイズ(ピクセル)サイズ(ミリメートル)
_11X17This is the 11x17 format792.0,1224.0279.4,431.8
A0This is the a0 format2384.0,3370.0841.0222,1188.8611
A1This is the a1 format1684.0,2384.0594.07776,841.0222
A10This is the a10 format73.0,105.025.752777,37.041668
A2This is the a2 format1191.0,1684.0420.15833,594.07776
A3This is the a3 format842.0,1191.0297.03888,420.15833
A4This is the a4 format595.0,842.0209.90277,297.03888
A5This is the a5 format420.0,595.0148.16667,209.90277
A6This is the a6 format297.0,420.0104.774994,148.16667
A7This is the a7 format210.0,297.074.083336,104.774994
A8This is the a8 format148.0,210.052.21111,74.083336
A9This is the a9 format105.0,148.037.041668,52.21111
ARCH_AThis is the archA format648.0,864.0228.59999,304.8
ARCH_BThis is the archB format864.0,1296.0304.8,457.19998
ARCH_CThis is the archC format1296.0,1728.0457.19998,609.6
ARCH_DThis is the archD format1728.0,2592.0609.6,914.39996
ARCH_EThis is the archE format2592.0,3456.0914.39996,1219.2
B0This is the b0 format2834.0,4008.0999.7722,1413.9332
B1This is the b1 format2004.0,2834.0706.9666,999.7722
B10This is the b10 format87.0,124.030.691668,43.744442
B2This is the b2 format1417.0,2004.0499.8861,706.9666
B3This is the b3 format1000.0,1417.0352.77777,499.8861
B4This is the b4 format708.0,1000.0249.76666,352.77777
B5This is the b5 format498.0,708.0175.68333,249.76666
B6This is the b6 format354.0,498.0124.88333,175.68333
B7This is the b7 format249.0,354.087.84167,124.88333
B8This is the b8 format175.0,249.061.73611,87.84167
B9This is the b9 format124.0,175.043.744442,61.73611
CROWN_OCTAVOThis is the Crown Octavo format348.0,527.0122.76667,185.91388
CROWN_QUARTOThis is the Crown Quarto format535.0,697.0188.73611,245.8861
DEMY_OCTAVOThis is the Demy Octavo format391.0,612.0137.9361,215.9
DEMY_QUARTOThis is the Demy Quarto format.620.0,782.0218.72223,275.8722
EXECUTIVEThis is the executive format522.0,756.0184.15,266.7
FLSAThis is the American Foolscap format612.0,936.0215.9,330.2
FLSEThis is the European Foolscap format648.0,936.0228.59999,330.2
HALFLETTERThis is the halfletter format396.0,612.0139.7,215.9
ID_1This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch)242.65,153.085.601524,53.975
ID_2This is the ISO 7810 ID-2 format (A7 rotated)297.0,210.0104.774994,74.083336
ID_3This is the ISO 7810 ID-3 format (B7 rotated)354.0,249.0124.88333,87.84167
LARGE_CROWN_OCTAVOThis is the Large Crown Octavo format365.0,561.0128.76389,197.90833
LARGE_CROWN_QUARTOThis is the Large Crown Quarto format569.0,731.0200.73055,257.88055
LEDGERThis is the ledger format1224.0,792.0431.8,279.4
LEGALThis is the legal format612.0,1008.0215.9,355.59998
LETTERThis is the letter format612.0,792.0215.9,279.4
NOTEThis is the note format540.0,720.0190.5,254.0
PENGUIN_LARGE_PAPERBACKThis is the Penguin large paparback format.365.0,561.0128.76389,197.90833
PENGUIN_SMALL_PAPERBACKThis is the Pengiun small paperback format.314.0,513.0110.772224,180.975
POSTCARDThis is the postcard format283.0,416.099.836105,146.75555
ROYAL_OCTAVOThis is the Royal Octavo format.442.0,663.0155.92778,233.89166
ROYAL_QUARTOThis is the Royal Quarto format.671.0,884.0236.7139,311.85556
SMALL_PAPERBACKThis is the small paperback format.314.0,504.0110.772224,177.79999
TABLOIDThis is the tabloid format792.0,1224.0279.4,431.8

表を作るためのソースコード(PageSizeRectangles.java)


import java.lang.reflect.Field;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
 
public class PageSizeRectangles {
 
  public static void main(String[] args) throws Exception{
 
    String[] names = {
      "_11X17", // PageSize._11X17
      "A0",
      "A1",
      "A10",
      "A2",
      "A3",
      "A4",
      "A5",
      "A6",
      "A7",
      "A8",
      "A9",
      "ARCH_A",
      "ARCH_B",
      "ARCH_C",
      "ARCH_D",
      "ARCH_E",
      "B0",
      "B1",
      "B10",
      "B2",
      "B3",
      "B4",
      "B5",
      "B6",
      "B7",
      "B8",
      "B9",
      "CROWN_OCTAVO",
      "CROWN_QUARTO",
      "DEMY_OCTAVO",
      "DEMY_QUARTO",
      "EXECUTIVE",
      "FLSA",
      "FLSE",
      "HALFLETTER",
      "ID_1",
      "ID_2",
      "ID_3",
      "LARGE_CROWN_OCTAVO",
      "LARGE_CROWN_QUARTO",
      "LEDGER",
      "LEGAL",
      "LETTER",
      "NOTE",
      "PENGUIN_LARGE_PAPERBACK",
      "PENGUIN_SMALL_PAPERBACK",
      "POSTCARD",
      "ROYAL_OCTAVO",
      "ROYAL_QUARTO",
      "SMALL_PAPERBACK",
      "TABLOID",
    };
    
    String[] descs = {
      "This is the 11x17 format",
      "This is the a0 format",
      "This is the a1 format",
      "This is the a10 format",
      "This is the a2 format",
      "This is the a3 format",
      "This is the a4 format",
      "This is the a5 format",
      "This is the a6 format",
      "This is the a7 format",
      "This is the a8 format",
      "This is the a9 format",
      "This is the archA format",
      "This is the archB format",
      "This is the archC format",
      "This is the archD format",
      "This is the archE format",
      "This is the b0 format",
      "This is the b1 format",
      "This is the b10 format",
      "This is the b2 format",
      "This is the b3 format",
      "This is the b4 format",
      "This is the b5 format",
      "This is the b6 format",
      "This is the b7 format",
      "This is the b8 format",
      "This is the b9 format",
      "This is the Crown Octavo format",
      "This is the Crown Quarto format",
      "This is the Demy Octavo format",
      "This is the Demy Quarto format.",
      "This is the executive format",
      "This is the American Foolscap format",
      "This is the European Foolscap format",
      "This is the halfletter format",
      "This is the ISO 7810 ID-1 format (85.60 x 53.98 mm or 3.370 x 2.125 inch)",
      "This is the ISO 7810 ID-2 format (A7 rotated)",
      "This is the ISO 7810 ID-3 format (B7 rotated)",
      "This is the Large Crown Octavo format",
      "This is the Large Crown Quarto format",
      "This is the ledger format",
      "This is the legal format",
      "This is the letter format",
      "This is the note format",
      "This is the Penguin large paparback format.",
      "This is the Pengiun small paperback format.",
      "This is the postcard format",
      "This is the Royal Octavo format.",
      "This is the Royal Quarto format.",
      "This is the small paperback format.",
      "This is the tabloid format",
    };
    
    System.out.println("<table border=\"1\">");
    System.out.println(
      "<tr><th>" + "定数名" +
      "</th><th>" + "説明" +
      "</th><th>" + "サイズ(ピクセル)" + 
      "</th><th>" + "サイズ(ミリメートル)" +
      "</th></tr>");
    
    for(int i=0; i<names.length; i++){
      out(names[i], descs[i]);
    }
    
    System.out.println("</table>");
  }
 
  private static void out(String name, String desc) throws Exception{
    
    // わざわざリフレクションでフィールドを求める(^_^;
    Field field = PageSize.class.getDeclaredField(name);
    Rectangle size = (Rectangle)field.get(null);
    
    System.out.println(
      "<tr><td>" + name +
      "</td><td>" + desc +
      "</td><td>" + size.getWidth() + "," + size.getHeight() +
      "</td><td>" + pixel2mm(size.getWidth()) + "," + pixel2mm(size.getHeight()) +
      "</td></tr>");
  }
  
  public static float pixel2mm(float pixel) {
    final float dpi = 72.0f;
    return pixel * 25.4f / dpi;
  }  
}

tags: zlashdot Java Java PDF iText

Posted by NI-Lab. (@nilab)