欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

C#生成PDF文件流

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

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

1、設置字體

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();
      //標題
      Paragraph title = new Paragraph(new Chunk("標題", 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è)務數(shù)據(jù)
      CreateSteps(list, document, list.FirstOrDefault(it => it.PID == 0));//添加業(yè)務數(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, "水印內容", docWidth, docHeight);//添加水印,見另外一篇博客
      newfile.Position = 0;//重置流指針位置
      byte[] bytes = new byte[newfile.Length];
      newfile.Read(bytes, 0, bytes.Length);
      return bytes;
    }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:C#連接mysql的方法【基于vs2010】

欄    目:C#教程

下一篇:C# 在PDF中創(chuàng)建和填充域

本文標題:C#生成PDF文件流

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5826.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權所有