2012-07-05 46 views
0

我使用wkhtmltopdf到HTML文件转换成PDF文档的链接按钮 http://code.google.com/p/wkhtmltopdf/与wkhtmltopdf.exe路径问题HTML文件转换成PDF

当如用户点击运行下面的代码链接按钮在传递文件路径下面的代码作为参数ProcessStartInfo。此代码工作正常在下列情况下,只有

考虑到网站上域http://www.xyz.net/

  1. 托管当我提到路径http://demo.XYZ.net/它工作正常
  2. 当我提到路径http://www.XYZ.net/它不工作
  3. 套内本地主机的正常工作,如果路径是http://localhost:51005/XYZ/http://web:8080/

为了这个正常工作,我们需要给网站的完全信任级别&我不知道为什么代码不运行,我给它同样的域路径,如果我创建如果我创建一个子域,然后它将正常工作PrintArticle.aspx。我NOST知道这是一个安全问题,或者什么

下面的代码

protected void lnkbtnDownload_Click(object sender, EventArgs e) 
{ 
    //ConvertURLToPDF(); 
    try 
    { 
     string url = "PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"]; 

     //string args = string.Format("\"{0}\" - ", "http://demo.XYZ.net/" + url); //Works 
     //string args = string.Format("\"{0}\" - ", "http://www.xyz.net/" + url); Doesnt work 
     //string args = string.Format("\"{0}\" - ", url); 

     string args = string.Format("\"{0}\" - ", "http://localhost:51005/XYZ/" + url); //Works 

     var startInfo = new ProcessStartInfo(Server.MapPath("bin\\wkhtmltopdf.exe"), args) 
     { 
      UseShellExecute = false, 
      CreateNoWindow = true, 
      RedirectStandardOutput = true 
     }; 
     var proc = new Process { StartInfo = startInfo }; 
     proc.Start(); 

     string output = proc.StandardOutput.ReadToEnd(); 
     byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output); 
     proc.WaitForExit(); 
     proc.Close(); 
     Response.ContentType = "application/pdf"; 
     Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf"); 
     Response.BinaryWrite(buffer); 
     Response.End(); 
    } 
    catch (Exception ex) 
    { 
     throw ex; 
    } 
} 

错误消息的情况下,文件是在同一个域中

服务器错误“/”应用。无法找到该资源。

描述:HTTP 404.您正在查找的资源(或其中一个 依赖项)可能已被删除,名称已更改,或者 暂时不可用。请查看以下网址并确保 拼写正确。 请求的网址:/PrintArticle.aspx

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.272

回答

0

我用下面的语句

var url = Request.Url.GetLeftPart(UriPartial.Authority) + "/PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"]; 

现在它工作正常我不知道解决这个问题是什么时,我指定这是行不通的文件路径。

0

输出变量包含空字符串 我的代码如下: 尝试 { 串URL = Request.Url.GetLeftPart(UriPartial.Authority)+ “?/ PrintQuickPrescription.aspx DoctorId =” + DoctorID +“& DispnID = “+ DispnID +”& ApptID =“+ ApptID +”& PatientID =“+ PatientID; System.Diagnostics.Process process = new System.Diagnostics.Process();

 string args = string.Format("\"{0}\" - ", "http://localhost:50013/DPMNewWeb/"+url); 
     //string args="http://localhost:50013/DPMNewWeb/PrintQuickPrescription.aspx"; 

     var startInfo = new ProcessStartInfo(Server.MapPath("~\\Bin\\wkhtmltopdf.exe"), args) 
     { 
      UseShellExecute = false, 
      CreateNoWindow = true, 
      RedirectStandardOutput = true 
     }; 
     var proc = new Process { StartInfo = startInfo }; 
     proc.Start(); 

     string output = proc.StandardOutput.ReadToEnd(); 

     byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output); 
     proc.WaitForExit(); 
     proc.Close(); 
     Response.ContentType = "application/pdf"; 
     Response.BinaryWrite(buffer); 
     Response.End(); 



     //byte[] fileContent = GeneratePDFFile(); 
     //GeneratePDFFile(); 
     //if (fileContent != null) 
     //{ 
     // Response.Clear(); 
     // Response.ContentType = "application/pdf"; 
     // Response.AddHeader("content-length", fileContent.Length.ToString()); 
     // Response.BinaryWrite(fileContent); 
     // Response.End(); 
     //} 
    } 
    catch 
    { 
    }