2017-04-07 5 views
1

Ich habe diesen Code unten auf lokale (using source code) völlig in Ordnung. Aber wenn ich es auf IIS7 veröffentlichte, wird die PDF nicht mehr angezeigt .. Gibt es ein Problem mit dem IIS oder?. . . Ich habe viele Tage mit diesem Problem verbracht.Adobe PDF nicht auf IIS7

Wie Sie auf dem Bild unten sehen können, sehen Sie, dass der AdobeReader läuft, aber nicht auf meinem Bildschirm angezeigt wird.

enter image description here

Antwort

1

Wenn Sie sagen, „nicht angezeigt“ Ich gehe davon aus Sie die PDF wollen auf dem Client geöffnet werden, nicht der Server. Normalerweise würden Sie die Datei an den Browser senden. startet einen Prozess serverseitig. Selbst wenn der AppPool einen Prozess starten darf, wird nur das PDF auf dem Server geöffnet. Unten sehen Sie, wie Sie eine Datei vom Server an den Client senden.

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 
+0

Hallo, ich werde meinen Code nicht mehr verwenden ?. – KiRa

+0

Nicht, wenn Sie eine Datei vom Server auf den Client herunterladen möchten. – VDWWD

+0

Ich habe Ihren Code getestet und funktioniert gut .. Aber es ist das Herunterladen der PDF .. Gibt es alternative Möglichkeit von "Response.Flush"? Genau wie das Anzeigen – KiRa

0

Wenn Sie eine PDF-Datei auf Ihrer Website zeigen wollen, hier sind ein paar Javascript-Tools Sie verwenden können, können Sie dies zu erreichen helfen:

http://viewerjs.org/

https://github.com/mozilla/pdf.js/

Persönlich habe ich nicht verwendet diese Werkzeuge, aber sie scheinen, als wären sie ausreichend für das, was Sie erreichen möchten.

Verwandte Themen