- PR -

PDF作成での表の開始位置とフォーマットについて

1
投稿者投稿内容
karei
常連さん
会議室デビュー日: 2004/06/01
投稿数: 20
投稿日時: 2004-07-29 14:00
いつもお世話になります。

JSPの中でPDFファイルを作成しました。
この作成したロジックで、表を作成していて、
下記の2つの問題が分からず悩んでいます。

1.表全体の開始位置を、特定することはできますか?
  例えば、表の左上の角を、X方向で100、Y方向で200
  の位置から始めるとかです。

2.現在、PDFのフォーマットをA4にしていますが
  デフォルトで縦向きになっています。
  横向きにできますか?

※環境
  Eclipse(2.1.1)
  TOMCAT(ver4.1.27)
  PDFライブラリ(iText.jar、iTextAsian.jar)

素人質問で申し訳ないですが、分かる方がいっらしゃれば
宜しく御願いします。

===== Sample356.jsp =====

<%@ page contentType="text/html;charset=Shift_JIS" %>
<%@ page import="java.io.*" %>
<%@ page import="com.lowagie.text.*" %>
<%@ page import="com.lowagie.text.pdf.PdfWriter" %>
<%@ page import="com.lowagie.text.pdf.PdfContentByte" %>
<%@ page import="com.lowagie.text.pdf.BaseFont" %>
<%@ page import="java.awt.*" %>
<%!
public Phrase p(String str)
{
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,12);
ph=new Phrase(str,font);
}catch(Exception e){}
return ph;
}
%>
<%
Document document=new Document(PageSize.A4,72,72,35,35);
PdfWriter.getInstance(document,(new FileOutputStream("../webapps/myapp/sample356.pdf")));
document.open();
//表の基本部分
Table table=new Table(3);
table.setBorderWidth(1);
table.setBorderColor(new Color(0, 0, 255));
table.setPadding(5);
table.setSpacing(5);
//ヘッダー部分
Cell cell=new Cell(p("ヘッダー"));
cell.setHeader(true);
cell.setColspan(3);
table.addCell(cell);
table.endHeaders();
//2行目、1列
cell=new Cell(p("データ1"));
cell.setRowspan(2);
cell.setBorderColor(new Color(255, 0, 0));
table.addCell(cell);
//2行目、2,3列、 3行目、2,3列
table.addCell("A");
table.addCell("B");
table.addCell("C");
table.addCell("D");
//4行目、1列
table.addCell(p("データ2"));
//4行目、2列
cell=new Cell(p("大きなセル"));
cell.setRowspan(2);
cell.setColspan(2);
table.addCell(cell);
//5行目
table.addCell(p("データ3"));

document.add(table);
document.close();
%>
<html><head>
<title>Sample356</title>
<meta http-equiv="Expires" content="0">
</head><body>
<embed src="sample356.pdf" width="100%" height="100%">
</body></html>

あいつー
ベテラン
会議室デビュー日: 2004/05/20
投稿数: 89
投稿日時: 2004-07-29 16:01
あいつーです。

http://www.lowagie.com/iText/docs.html

ここのChapter 1に1.&2.共に書いてありますね。
karei
常連さん
会議室デビュー日: 2004/06/01
投稿数: 20
投稿日時: 2004-07-29 18:15
有難う御座います。
試してみます。
1

スキルアップ/キャリアアップ(JOB@IT)