• 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
  • 相关阅读:
    Swift
    UIWindow 详解及使用场景
    点击状态栏回到顶部的功能失效的解决办法
    iOS
    从经典问题来看 Copy 方法
    从汇编层面深度剖析C++虚函数
    数值的整数次方
    求整数二进制中1的个数
    C++中的位运算总结
    嵌入在C++程序中的extern "C"
  • 原文地址:https://www.cnblogs.com/yansc/p/6077342.html
Copyright © 2020-2023  润新知