zoukankan      html  css  js  c++  java
  • 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%;  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
  • 相关阅读:
    HDU 1150 Machine Schedule(二分匹配最小点覆盖)
    CodeForces 748F Santa Clauses and a Soccer Championship
    CodeForces 748E Santa Claus and Tangerines(二分)
    CodeForces 748D Santa Claus and a Palindrome (贪心+构造)
    POJ 3657 Haybale Guessing(二分+并查集)
    【JZOJ5773】简单数学题【数论,数学】
    【洛谷P4085】Haybale Feast【分块】
    【洛谷P4085】Haybale Feast【分块】
    【洛谷P4085】Haybale Feast【分块】
    【洛谷P4212】外太空旅行【随机】【贪心】
  • 原文地址:https://www.cnblogs.com/yansc/p/6077342.html
Copyright © 2011-2022 走看看