C # generate a QR code PDF file

Source: Internet
Author: User

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);//Storing the image in the specified format in the cache memory stream

BT = new Byte[mostream. Length];

Mostream. Position = 0;//Set the initial position of the left

Mostream. Read (BT, 0, Convert.ToInt32 (BT). Length));

}

}

Return BT;

}

C # generate a QR code PDF file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.