例子是生成一个pdf格式的证书:

需要引用itextsharp.dll

           //创建Document
  Document document = null;
  //为该Document创建一个Writer实例
  PdfWriter writer = null;
  //段(内容)
  Paragraph p = null;
         //字体
BaseFont baseFont = BaseFont.CreateFont(Server.MapPath("Configuration/STZHONGS.TTF"), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = null;
//内存流
document = new Document(PageSize.A4.Rotate(), , , , ); //为该Document创建一个Writer实例
writer = PdfWriter.GetInstance(document, new FileStream(filepath + strCerId + ".pdf", FileMode.Create));
//writer.SetEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_PRINTING);
//打开
document.Open(); //指定位置添加图片
PdfContentByte pcb1 = writer.DirectContent;
iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(Server.MapPath("Configuration/1.png"));
image1.SetAbsolutePosition(, );
image1.ScaleAbsolute(, );
pcb1.AddImage(image1); font = new Font(baseFont, , Font.BOLD);
p = new Paragraph("\n\n“标题", font);
p.Alignment = Element.ALIGN_CENTER;
document.Add(p); font = new Font(baseFont, , Font.BOLD);
p = new Paragraph("标题", font);
p.Alignment = Element.ALIGN_CENTER;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("\n  正文。", font);
p.Alignment = Element.ALIGN_LEFT;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("\n署名", font);
p.Alignment = Element.ALIGN_RIGHT;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("2016年6月22日", font);
p.Alignment = Element.ALIGN_RIGHT;
document.Add(p);
         //关闭目标文件
document.Close();
writer.Close();
document = null;
//关闭写入流
writer = null;

图片:

最新文章

  1. H5常用代码:适配方案4
  2. Hadoop:Windows 7 32 Bit 编译与运行
  3. String的两个API,判断指定字符串是否包含另一字符串,在字符串中删除指定字符串。
  4. POJ --- 3613 (K步最短路+矩阵快速幂+floyd)
  5. java学习多线程之卖票示例
  6. mysql加入�管理员
  7. 执行计划之CONCATENATION
  8. C#Redis列表List
  9. POP音原因
  10. ActiveMQ基本详解与总结
  11. 安装php扩展 ffmpeg-php
  12. django+mysql的使用
  13. [Swift]LeetCode980. 不同路径 III | Unique Paths III
  14. hibernate框架的简单入门
  15. 版本管理工具小乌龟TortoiseGit的安装和使用(1)
  16. QWaitConditioin的思考1
  17. 函数式编程之 Python
  18. ASP.NET:Forms身份验证和基于Role的权限验证
  19. Hdu1163 Eddy's digitai Roots(九余数定理)
  20. 一段js的思考

热门文章

  1. 大神眼中的React Native--备用
  2. LINUX下安装ORACLE,完全搞定
  3. 我的HttpClients工具
  4. 利用函数索引优化<>
  5. nodejs触发事件的两种方式
  6. Entropy (huffman) 优先队列)
  7. soap协议
  8. [Locked] Smallest Rectangle Enclosing Black Pixels
  9. openStack images
  10. Count the string - HDU 3336(next+dp)