zoukankan      html  css  js  c++  java
  • iTextSharp中中文显示实例

          //字体设定,c:\windows\fonts\kaiu.ttf,中文楷体
                BaseFont bfchinese = BaseFont.CreateFont(@"c:\windows\fonts\kaiu.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                Font ChFont = new Font(bfchinese, 12);
                Font ChFont_blue = new Font(bfchinese, 40, Font.NORMAL, new BaseColor(51, 0, 153));
                Font ChFont_msg = new Font(bfchinese, 12, Font.ITALIC, BaseColor.RED);

      
                string filename =HttpRuntime.AppDomainAppPath+"pdf/"+DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
                Document document = new Document(PageSize.A4.Rotate());
                PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
                //加密
                //pdfWriter.SetEncryption(PdfWriter.STRENGTH128BITS, "1234", "1244", PdfWriter.ALLOW_COPY | PdfWriter.AllowPrinting);
                document.Open();
                document.AddAuthor("zero");
                document.Add(new Paragraph("放大是否飒飒的",ChFont_blue));//调用重载函数 public Paragraph(string str, Font font);将字体传进去
                Image img = Image.GetInstance(HttpRuntime.AppDomainAppPath + "img/1.jpg");
                document.Add(img);
                //Header footer = new Header();
                document.AddHeader("footer", "this is footer");
                //pdfWriter.Dispose();
                //pdfWriter.Close();
                document.Dispose();
                document.Close();
                context.Response.Write(filename);

  • 相关阅读:
    深度学习学习总结
    线性回归学习总结
    机器学习常用算法总结
    2020年,给自己立个flag
    与博客添网易云外钟墯之坑
    给博客添加网易云外链时掉的坑
    BEGINNING
    【华为云技术分享】程序员真香定律:源码即设计
    【华为云技术分享】【DevCloud · 敏捷智库】如何利用核心概念解决估算常见问题
    差点被祭天!狂欢618,且看研发人如何绝地求生
  • 原文地址:https://www.cnblogs.com/beyond1983/p/2845829.html
Copyright © 2011-2022 走看看