国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#生成PDF文件流

2020-01-24 00:42:55
字體:
供稿:網(wǎng)友

本文實例為大家分享了C#生成PDF文件流的具體代碼,供大家參考,具體內(nèi)容如下

1、設(shè)置字體

static BaseFont FontBase = BaseFont.CreateFont("C://WINDOWS//FONTS//STSONG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);    static iTextSharp.text.Font bodyFont = new iTextSharp.text.Font(FontBase, 12);    static iTextSharp.text.Font titleFont = new iTextSharp.text.Font(FontBase, 18);    static iTextSharp.text.Font paragraphFont = new iTextSharp.text.Font(FontBase, 15);    static iTextSharp.text.Font linkFont = new iTextSharp.text.Font(FontBase, 12, Font.UNDERLINE, BaseColor.BLUE);

2.生成PDF文件流返回byte數(shù)組

public byte[] DocCreate(System.Drawing.Image image, List<TreeNodes> list)    {      MemoryStream file = new MemoryStream();      string fileName = string.Empty;      Rectangle page = PageSize.A4;      float y = page.Height;      Document document = new Document(page, 15, 15, 30, 30);      float docWidth = page.Width - 15 * 2;      float docHeight = page.Height - document.BottomMargin - document.TopMargin;      PdfWriter writer = PdfWriter.GetInstance(document, file);      writer.CloseStream = false;      writer.Open();      PdfContentByte cb = writer.DirectContent;      document.Open();      //標(biāo)題      Paragraph title = new Paragraph(new Chunk("標(biāo)題", titleFont));      title.Alignment = Element.ALIGN_CENTER;      document.Add(title);      //圖片      iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(image, ImageFormat.Png);      float widthSzie = (page.Width - 30) / img.Width;      if (widthSzie < 1)      {        img.ScalePercent(widthSzie * 100);      }      document.Add(img);      //文獻出處      Paragraph p2 = new Paragraph(new Chunk("出處", paragraphFont));      p2.IndentationLeft = indentationLeft;      document.Add(p2);      InitData(list);//初始化業(yè)務(wù)數(shù)據(jù)      CreateSteps(list, document, list.FirstOrDefault(it => it.PID == 0));//添加業(yè)務(wù)數(shù)據(jù)      ////添加印章      //iTextSharp.text.Image whyz = iTextSharp.text.Image.GetInstance(whyzPath);      //whyz.ScalePercent(50);      //whyz.PaddingTop = 100;      //whyz.Alignment = Element.ALIGN_RIGHT;      //document.Add(whyz);      //添加日期      Paragraph createtime = new Paragraph(new Chunk(DateTime.Now.ToLongDateString().ToString(), bodyFont));      createtime.Alignment = Element.ALIGN_RIGHT;      //createtime.SpacingBefore = -80;      createtime.PaddingTop = 200;      document.Add(createtime);      document.Close();      file.Position = 0;      MemoryStream newfile = SetWaterMark(file, "水印內(nèi)容", docWidth, docHeight);//添加水印,見另外一篇博客      newfile.Position = 0;//重置流指針位置      byte[] bytes = new byte[newfile.Length];      newfile.Read(bytes, 0, bytes.Length);      return bytes;    }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 开封市| 绥德县| 襄城县| 玉田县| 墨竹工卡县| 六安市| 古蔺县| 临朐县| 通海县| 永济市| 山阳县| 昭通市| 都昌县| 漳州市| 河间市| 贞丰县| 双鸭山市| 盘山县| 郯城县| 高阳县| 临朐县| 安多县| 宿松县| 福清市| 紫阳县| 科尔| 松阳县| 宜阳县| 改则县| 宜章县| 探索| 囊谦县| 大方县| 沙洋县| 南京市| 怀化市| 鹤山市| 旺苍县| 凤山县| 理塘县| 云龙县|