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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM