码迷,mamicode.com
首页 > Windows程序 > 详细

C#生成二维码pdf文件

时间:2016-07-06 13:23:32      阅读:393      评论:0      收藏:0      [点我收藏+]

标签:

using CrystalDecisions.CrystalReports.Engine;
using System.Configuration;
using CrystalDecisions.Shared;
using Gma.QrCodeNet.Encoding.Windows.Render;
using Gma.QrCodeNet.Encoding;
using System.IO;
using Gma.QrCodeNet.Encoding.Windows.Forms;

private void button1_Click(object sender, EventArgs e)

{

dt.Columns.Add("A",typeof(byte[]));            

dt.Columns.Add("B");            

dt.Columns.Add("C");

           

for (int i = 0; i < 2; i++)            

{                

DataRow dr = dt.NewRow();                           

dr["B"] = "1111111111dafadfasdfadsfsdfasdfasdfasdfjlasdfjasl;dfjasdfl;asjdfasl;jdflsadfjsdfaasdfasdf--13123123-adsfasdfkljsdf^sadfsdasadfasdfasdfsadf" + i.ToString();                

dr["C"] = "2222222222" + i.ToString();                

dr["A"] = GenQrCode(dr["B"].ToString());                

dt.Rows.Add(dr);            

}

 document = new ReportDocument();            

string reportPath = @"D:\Prj\DEV\Barcode\20160610\PrintReportSvr\PrintReportSvr\OrderReport\ReportTest.rpt";            

document.Load(reportPath);            

document.SetDataSource(dt);

document.ExportToDisk(ExportFormatType.PortableDocFormat, pdfPath + @"\" + pdfName);

}

 

public byte[] GenQrCode(string barcodeContent)        

{            

byte[] bt = null;            

Color _lightModule = Color.White;//Color.FromArgb(220, 100, 203, 50);                    

Color _darkModule = Color.Black;//Color.FromArgb(170, 20, 250, 220);            

QrCodeImgControl qrControl = new QrCodeImgControl();            

qrControl.ErrorCorrectLevel = ErrorCorrectionLevel.M;            

qrControl.QuietZoneModule = Gma.QrCodeNet.Encoding.Windows.Render.QuietZoneModules.Two;            

qrControl.DarkBrush = new SolidBrush(_darkModule);            

qrControl.LightBrush = new SolidBrush(_lightModule);            

qrControl.Width = 100;            

qrControl.Height = 100;

qrControl.Text = barcodeContent;                        

//qrControl.Image.Save(@"C:\1111\1123.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);            

bt = GetByteImage(qrControl.Image);            

return bt;        

}        

public byte[] GetByteImage(Image img)        

{            

byte[] bt = null;            

if (!img.Equals(null))            

{                

  using (MemoryStream mostream = new MemoryStream())                

  {                    

    Bitmap bmp = new Bitmap(img);                    

    bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Jpeg);//将图像以指定的格式存入缓存内存流                    

    bt = new byte[mostream.Length];                    

    mostream.Position = 0;//设置留的初始位置                    

    mostream.Read(bt, 0, Convert.ToInt32(bt.Length));                

  }            

}            

return bt;        

}

C#生成二维码pdf文件

标签:

原文地址:http://www.cnblogs.com/smTiger/p/5646452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!