backup1

 1 string _imgpath1 = WebConfigurationManager.AppSettings["IMGPATH1"].ToString();
 2 
 3 string outputPath = Server.MapPath(Request.ApplicationPath + "/output");
 4 string file = Guid.NewGuid().ToString() + ".pdf";
 5 string desFile = Path.Combine(outputPath, file);
 6 
 7 string relativepath = "output/" + file;
 8 
 9 //转义
10 //System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312");
11 //string encodeFilePath = _imgpath1 + HttpUtility.UrlEncode(_imgpath2 + genre, gb2312).Replace("%2f", "/").Replace("%5c", "/").Replace("+", "%20");
12 
13 
14 
15 
16 
17 private void DownloadFile(string userName, string password, string ftpSourceFilePath, string localDestinationFilePath)
18 {
19   int bytesRead = 0;
20   byte[] buffer = new byte[2048];
21 
22   FtpWebRequest request = CreateFtpWebRequest(ftpSourceFilePath, userName, password, true);
23   request.Method = WebRequestMethods.Ftp.DownloadFile;
24 
25   Stream reader = request.GetResponse().GetResponseStream();
26   FileStream fileStream = new FileStream(localDestinationFilePath, FileMode.Create);
27 
28   while (true)
29   {
30     bytesRead = reader.Read(buffer, 0, buffer.Length);
31 
32     if (bytesRead == 0)
33       break;
34 
35     fileStream.Write(buffer, 0, bytesRead);
36   }
37   fileStream.Close();
38 }
39 private FtpWebRequest CreateFtpWebRequest(string ftpDirectoryPath, string userName, string password, bool keepAlive = false)
40 {
41   FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(ftpDirectoryPath));
42 
43   //Set proxy to null. Under current configuration if this option is not set then the proxy that is used will get an html response from the web content gateway (firewall monitoring system)
44   request.Proxy = null;
45 
46   request.UsePassive = true;
47   request.UseBinary = true;
48   request.KeepAlive = keepAlive;
49 
50   request.Credentials = new NetworkCredential(userName, password);
51 
52   return request;
53 }
54 
55 
56 
57 
58 
59 try
60 {
61 string template = Server.MapPath(Request.ApplicationPath + "/reporttemplate/国有土地使用证.mrt");
62 string outputPath = Server.MapPath(Request.ApplicationPath + "/output");
63 //删除过期的临时PDF文件
64 List<FileInfo> toDeleteFiles = new List<FileInfo>();
65 Directory.GetFiles(outputPath, "*.pdf").ToList().ForEach(i => {
66 if ((new FileInfo(i)).CreationTime < DateTime.Now)
67 toDeleteFiles.Add(new FileInfo(i));
68 });
69 Task task = new Task(() =>
70 {
71 for (int i = toDeleteFiles.Count - 1; i >= 0; i--)
72 { toDeleteFiles[i].Delete(); }
73 });
74 task.Start();
75 
76 StiReport report = new StiReport();
77 report.Load(template);
78 report.RegBusinessObject("land", "cer", cer);
79 report.Compile();
80 report.Render(true);
81 string file = Guid.NewGuid().ToString() + ".pdf";
82 string relativepath = "/output/" + file;
83 string fullpath = Path.Combine(outputPath, file);
84 report.ExportDocument(StiExportFormat.Pdf, fullpath);
85 
86 
87 return View(new PdfEntity() { Filename = fullpath, RelativeFilename = relativepath });
88 }
89 catch (Exception ex)
90 {
91 return View("Error", new HandleErrorInfo(ex, "CerController转换为PDF文件时发生异常", "Index"));
92 }
View Code
@model LandRegQueryWeb.Models.PdfEntity
@{
    Layout = null;
}

<html>
<body style="background-color: rgb(38,38,38); height: 100%; width: 100%; overflow: hidden; margin: 0">

    <embed width="100%" height="100%"
           name="plugin" id="plugin"
           src="@Model.Filename#toolbar=0&navpanes=0&scrollbar=0"
           type="application/pdf" internalinstanceid="3" title="">

</body>
</html>
View Code

 

posted on 2016-11-18 13:02 Anders' Yan 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yansc/p/6077342.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值