Report report1 = new Report();
report1.Load(templatePath + "CTMR1.frx");
report1.RegisterData(ds);
((PictureObject)report1.FindObject("Picture1")).ImageLocation = qrCodepath;
//report1.Show();
report1.Prepare();
PDFExport export = new PDFExport();
string tagertFolderUrl = Server.MapPath(Server.UrlDecode(Server.UrlDecode(@"/ReportFiles"))).TrimEnd('\\') + "\\";
string tagertPathUrl = tagertFolderUrl + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
report1.Export(export, tagertPathUrl);
System.Diagnostics.Process.Start(tagertPathUrl);
report1.Dispose();
注意点: System.Diagnostics.Process.Start(tagertPathUrl); 是打开pdf文件,即在本地启动AdobeReader,属于开启一个进程,但在服务器上无反应,因为客户端没有服务器的权限。
解决方法:return Json(Url.Content("/ReportFiles/" + reportName), JsonRequestBehavior.AllowGet);在浏览器中预览PDF,返回结果是ActionResult,其中路径要写位虚拟路径
二维码:
public string GetQRImage(string content)
{
string timeStr = DateTime.Now.ToFileTime().ToString();
Bitmap bitmap = QRCodeEncoderContent(content);
string filePath = Server.MapPath(Server.UrlDecode(Server.UrlDecode(@"/ReportFiles"))).TrimEnd('\\') + "\\" + "Images" + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
bitmap.Save(filePath+timeStr + ".jpg");
string getPath = filePath + timeStr + ".jpg";
return getPath;
}
public Bitmap QRCodeEncoderContent(string content)
{
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
qrCodeEncoder.QRCodeVersion = 0;
Bitmap bitmap = qrCodeEncoder.Encode(content, Encoding.UTF8);
return bitmap;
}
jquery实现二维码
引入jquery库文件
引入二维码js文件jquery.qrcode.min.js
js方法:
$(function () {
$("#erwei").qrcode("wwwwww");
})
一个div:
div id = "erwei"
注意,如果是mvc,需要在App_Start\BundleConfig.cs中解除绑定的其他js文件,否则会js冲突,报错:不支持qrcode属性或方法