(二)设置PDF纸张并在指定位置添加文字

来源:互联网 发布:郑伯编程 编辑:程序博客网 时间:2024/05/16 05:35

代码如下:

    // 创建指定纸张的PDF        public void CreatePDF2()        {            Document document = new Document(PageSize.A5.Rotate());            PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));            document.Open();            for (int i = 0; i < 5; i++)                document.Add(new Phrase("Hello,World!"));            document.Close();          }        // 在PDF指定位置添加段落        public void CreatePDF3()        {            Document document = new Document(PageSize.A5, 36, 72, 108, 100);            PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));            document.Open();            Paragraph paragraph = new Paragraph();            paragraph.Alignment = Element.ALIGN_BOTTOM;            for(int i=0;i<20;i++)            {                paragraph.Add("Hello World!");            }            document.Add(paragraph);            document.Close();        }


 

原创粉丝点击