iText的创建与不平等的页面大小的文件 [英] iText create document with unequal page sizes

查看:168
本文介绍了iText的创建与不平等的页面大小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个利用iText具有不平等的页面大小的PDF文件。 我有两个矩形:

I want to create a pdf file using itext that has unequal page sizes. I have these two rectangles:

Rectangle one=new Rectangle(70,140);
 Rectangle two=new Rectangle(700,400);

和我写的PDF格式是这样的:

and i am writing to the pdf like this :

Document document = new Document();
  PdfWriter writer=  PdfWriter.getInstance(document, new FileOutputStream(("MYpdf.pdf")));

当我创建的文档,我必须指定页面大小的选择,但我想不同的页面大小为我的PDF不同的页面。 是否有可能这样做吗?

when I create the document, I have the option to specify the page size , but I want different page sizes for different pages in my pdf. Is it possible to do that ?

例如。的第一页将具有矩形一个作为页面大小,而第二页面将具有矩形2作为页面大小。

Eg. The first page will have rectangle one as the page size, and the second page will have rectangle two as the page size.

推荐答案

我创建了一个 UnequalPages 下面为大家这说明它是如何工作的:

I've created an UnequalPages example for you that shows how it works:

Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
Rectangle one = new Rectangle(70,140);
Rectangle two = new Rectangle(700,400);
document.setPageSize(one);
document.setMargins(2, 2, 2, 2);
document.open();
Paragraph p = new Paragraph("Hi");
document.add(p);
document.setPageSize(two);
document.setMargins(20, 20, 20, 20);
document.newPage();
document.add(p);
document.close();

它改变页面大小(和利润)的的页面初始化是非常重要的。第一页是初始化时,的open()文件,所有下面的页面时, NEWPAGE()时初始化。新页面可以明确地被触发(使用 NEWPAGE()方法在code)或隐式(由iText的,当一个页面是满的,一个新的页面需要)。

It is important to change the page size (and margins) before the page is initialized. The first page is initialized when you open() the document, all following pages are initialized when a newPage() occurs. A new page can be triggered explicitly (using the newPage() method in your code) or implicitly (by iText, when a page was full and a new page is needed).

这篇关于iText的创建与不平等的页面大小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆