IIS PDF上没有显示Adobe PDF [英] Adobe PDF not showing on IIS7
问题描述
我在下面的代码中使用本地(使用源代码)
完全正常。但是当我在 IIS7
上发布它时, PDF
不再显示..是否存在IIS问题? 。 。 。我花了很多天来解决这个问题。
I got this code below working on local (using source code)
perfectly fine. But when I published it on IIS7
the PDF
is not showing anymore.. Is there a problem with the IIS or ?. . . I spent many days on this problem.
Dim strPath = Server.MapPath("~\Reports\GeneratedReport.pdf")
my_rpt.ExportToDisk(ExportFormatType.PortableDocFormat, strPath)
Dim file = New System.IO.FileInfo(strPath)
Dim Process = New Process()
If file.Exists Then
Process.StartInfo.UseShellExecute = True
Process.StartInfo.FileName = strPath
Process.Start()
Else
'No Report found
End If
如下图所示,您看到AdobeReader正在运行,但是不在我的屏幕上显示。
As you can notice in the picture below you see the AdobeReader is running but its not displaying on my screen.
< img src =https://i.stack.imgur.com/qX7Gg.pngalt =在此处输入图像说明>
推荐答案
当你说没有显示时,我假设您希望在客户端而不是服务器上打开PDF。通常,您会将文件发送到浏览器。 Process.Start()
将启动进程服务器端,因此即使允许AppPool启动进程,它也只会在服务器上打开pdf。
以下是将文件从服务器发送到客户端的方法。
When you say "not showing" I am assuming you want the PDF to be opened on the client, not the server. Normally you would send the file to the browser. Process.Start()
will start a process server-side, so even if the AppPool is allowed to start a process, it will only open the pdf on the server.
Below is how you send a file from the server to the client.
string strPath = Server.MapPath("~/reports/GeneratedReport.pdf");
//read the file from disk and convert to a byte array
byte[] bin = File.ReadAllBytes(strPath);
//clear the buffer stream
Response.ClearHeaders();
Response.Clear();
Response.Buffer = true;
//set the correct contenttype
Response.ContentType = "application/pdf";
//set the correct length of the data being send
Response.AddHeader("content-length", bin.Length.ToString());
//set the filename for the file
Response.AddHeader("content-disposition", "attachment; filename=\"GeneratedReport.pdf\"");
//send the byte array to the browser
Response.OutputStream.Write(bin, 0, bin.Length);
//cleanup
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
VB
Dim strPath As String = Server.MapPath("~/reports/GeneratedReport.pdf")
'read the file from disk and convert to a byte array
Dim bin() As Byte = File.ReadAllBytes(strPath)
'clear the buffer stream
Response.ClearHeaders
Response.Clear
Response.Buffer = true
'set the correct contenttype
Response.ContentType = "application/pdf"
'set the correct length of the data being send
Response.AddHeader("content-length", bin.Length.ToString)
'set the filename for the file
Response.AddHeader("content-disposition", "attachment; filename=""GeneratedReport.pdf"""")", send the byte array to the browser, Response.OutputStream.Write(bin, 0, bin.Length))
'cleanup
Response.Flush
HttpContext.Current.ApplicationInstance.CompleteRequest
这篇关于IIS PDF上没有显示Adobe PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!