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

来源:互联网 发布:linux ioremap 编辑:程序博客网 时间:2024/05/20 05:09

代码如下:

[csharp] view plain copy
  1. // 创建指定纸张的PDF  
  2.     public void CreatePDF2()  
  3.     {  
  4.         Document document = new Document(PageSize.A5.Rotate());  
  5.         PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));  
  6.         document.Open();  
  7.         for (int i = 0; i < 5; i++)  
  8.             document.Add(new Phrase("Hello,World!"));  
  9.         document.Close();    
  10.     }  
  11.     // 在PDF指定位置添加段落  
  12.     public void CreatePDF3()  
  13.     {  
  14.         Document document = new Document(PageSize.A5, 36, 72, 108, 100);  
  15.         PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/PDF/Hello.pdf"), FileMode.Create));  
  16.         document.Open();  
  17.         Paragraph paragraph = new Paragraph();  
  18.         paragraph.Alignment = Element.ALIGN_BOTTOM;  
  19.         for(int i=0;i<20;i++)  
  20.         {  
  21.             paragraph.Add("Hello World!");  
  22.         }  
  23.         document.Add(paragraph);  
  24.         document.Close();  
  25.     }  


阅读全文
0 0
原创粉丝点击