itext

1.
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
   int marginLeft,
   int marginRight,
   int marginTop,
   int marginBottom);



2.
Normally, you don't have to worry about creating this rectangle, since you can use one of the statics in class PageSize.java . These are the pagesizes that are provided: A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA and FLSE.
Most these pageSizes are in PORTRAIT-format. If you want them to be in LANDSCAPE , all you have to do is rotate() the Rectangle :
Document document = new Document(PageSize.A4.rotate());
Check out example Chap0103.java and its result .

3.
When creating a document, you can also define left, right, upper and lower margins:
Document document = new Document(PageSize.A5, 36, 72, 108, 180);

Measurements
When creating a rectangle or choosing a margin, you might wonder what measurement unit is used: centimeters, inches or pixels. In fact, the default measurement system roughly corresponds to the various definitions of the typographic unit of measurement known as the point. There are 72 points in 1 inch.
If you want to create a rectangle in PDF that has the size of an A4-page, you have to calculate the number of points:
   21 cm / 2.54 = 8.2677 inch
   8.2677 * 72 = 595 points
   29.7 cm / 2.54 = 11.6929 inch
   11.6929 * 72 = 842 points
The default border of 36 points corresponds with half an inch.


Remark: if you change the page size, this only has effect on the next page (see page initialisations). If you change the margins, this has an immediate effect, so be careful!


4.
Once our document is created, we can create one or more instances of writers that listen to this document. All writers should be derived from the abstract class com.lowagie.text.DocWriter .
For the moment there are two possibilities: you can use com.lowagie.text.pdf.PdfWriter to generate documents in the Portable Document Format, or you can use com.lowagie.text.html.HtmlWriter to generate documents in HTML. If for instance you want to generate TeX-documents as well, you could write a package: com.lowagie.text.TeX.TeXWriter.

5.
The constructor of these writer-classes is made private. You can only create an instance with the following method:
public static xxxWriter getInstance(Document document, OutputStream os) throws DocumentException
(xxx being Pdf or Html)
You can create an instance this way:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Chap01xx.pdf"));
but you will hardly ever need the object writer (except if you want to create Advanced PDF or if you want to use some very specific functionalities such as ViewerPreferences or Encryption ). So it's sufficient to just get the instance:
PdfWriter.getInstance(document, new FileOutputStream("Chap01xx.pdf"));


6.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值