Quantcast
Channel: 質問!ITmedia 新着質問(Java/253)
Viewing all articles
Browse latest Browse all 2439

JSPでPDFテーブルセル出力文字垂直位置について

$
0
0
動作環境 OS:WindowsXP Home Edition SP3 Browser:IE8 OpenSoftWare:Tomcat6.0.29 Framework:Struts2.2.1 Tool:Eclipse3.2.0 MySQL:5.1.46 itext:5.3.4 JavaファイルからPDFのTABLEのセルに文字値を出力してます。 出力させる事は、出来るのですが、セル上の垂直調整で文字位置を、中央にする事が、出来ません。 ※画像添付ファイル参照 ネット上で、検索しても、解決出来ません。 ご指導願います。 ■事象例 1.「test.java」実行 package test; import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class test { public void test(){ FileOutputStream out = null; BufferedOutputStream bout = null; PdfWriter writer = null; Document doc = null; int intFontSize=10; try { //ファイル名 out = new FileOutputStream("test.pdf"); bout = new BufferedOutputStream(out); //レイアウト doc = new Document(PageSize.A4.rotate(),5,5,5,5); writer = PdfWriter.getInstance(doc, bout); doc.open(); //タイトル Font kaku = new Font(BaseFont.createFont("HeiseiKakuGo-W5","UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED),intFontSize); doc.add(new Paragraph("テスト", kaku)); //テーブル定義 Table table = new Table(3); int[] intFileldsWidth = {3, 3, 3}; table.setWidths(intFileldsWidth); table.setWidth(10); table.setDefaultVerticalAlignment(Element.ALIGN_CENTER); //※setDefaultVerticalAlignmentに取消し線が、入り、使えない。 //1行目、1列目 Cell cell1_1=new Cell(p("1",intFontSize)); cell1_1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1_1.setVerticalAlignment(Element.ALIGN_CENTER); //※VerticalAlignmentを使用しても、変更無し。 //※VerticalAlignmentにElement.ALIGN_MIDDLEを使用しても、変更無し。 table.addCell(cell1_1); //1行目、2列目 Cell cell1_2=new Cell(p("中",intFontSize)); cell1_2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell1_2); //1行目、3列目 Cell cell1_3=new Cell(p("3",intFontSize)); cell1_3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell1_3); doc.add(table); doc.close(); } catch (Exception e) { System.out.println(e.getMessage()); } public Phrase p(String strChar,int intFontSize) { BaseFont bf = null; com.lowagie.text.Font font = null; Phrase ph=null; try { bf = BaseFont.createFont("HeiseiKakuGo-W5","UniJIS-UCS2-HW-H",false); font = new com.lowagie.text.Font(bf,intFontSize); ph = new Phrase(strChar, font); } catch(Exception e) { System.out.println(e.getMessage()); } return ph; } }

Viewing all articles
Browse latest Browse all 2439

Trending Articles