ITEXT学习手册——设置页面大小、方向

创建document时,设置pageSize,和距离四周的距离,设置页面。

如果没有传入参数,默认是A4大小

Rectangle pageSize = new Rectangle(216f,720f);
            Document doc = new Document(pageSize,30,30,50,50);//设置页面的大小

完整代码如下:

/// <summary>
        /// 自定义页面大小
        /// </summary>
        public static void CreatePDF()
        {
            Stream str = System.IO.File.OpenWrite(@"d:\helloworld.pdf");//创建一个PDF文件
            Rectangle pageSize = new Rectangle(216f,720f);
            Document doc = new Document(pageSize,30,30,50,50);//设置页面的大小
            PdfWriter.GetInstance(doc, str);//将pdf文档写入文件
            doc.Open();
            doc.Add(new Paragraph("Hello World"));//在文档上写“Hello World”
            doc.Close();
        }

执行效果:

image

ITEXT已经为我们定义了一套标准的页面大小:

image

Document doc = new Document(PageSize.A5,30,30,50,50);//使用ITEXT提供的类库设置页面的大小

我们在定义的页面后面加上rotate方法,可以使页面翻转90度

image

在创建document以后,可以通过setPageSize,setMargins,setMarginMirroring,setMarginMirroringTopBottom设置页面大小,页边距等:

doc.SetPageSize(PageSize.A5);
doc.SetMarginMirroringTopBottom(true);

注意,页面长宽的单位是pt

image

posted @ 2014-01-10 17:15  争世不悔  阅读(11683)  评论(0编辑  收藏  举报