2017-04-07 1 views
1

J'ai obtenu ce code ci-dessous en travaillant sur (using source code) local parfaitement bien. Mais quand je l'ai publié sur IIS7 le PDF ne montre plus .. Y at-il un problème avec l'IIS ou? . . J'ai passé plusieurs jours sur ce problème. Comme vous pouvez le constater sur l'image ci-dessous, AdobeReader est en cours d'exécution mais ne s'affiche pas sur mon écran.Adobe PDF ne s'affiche pas sur IIS7

enter image description here

Répondre

1

Quand vous dites « ne pas montrer » Je suppose que vous voulez que le PDF soit ouvert sur le client, pas le serveur. Normalement, vous enverriez le fichier au navigateur. Process.Start() démarrera un processus côté serveur, donc même si AppPool est autorisé à démarrer un processus, il ouvrira uniquement le pdf sur le serveur. Voici comment vous envoyez un fichier du serveur au 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 
+0

Bonjour, je n'utiliserai plus mon code? – KiRa

+0

Pas si vous voulez télécharger un fichier du serveur sur le client. – VDWWD

+0

J'ai testé votre code et fonctionne très bien .. Mais son téléchargement le PDF .. Y at-il une autre façon de 'Response.Flush'? Tout comme l'afficher – KiRa

0

Si vous souhaitez afficher un PDF sur votre site, voici quelques outils javascript vous pouvez utiliser qui peut vous aider à accomplir cette tâche:

http://viewerjs.org/

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

Personnellement, je n'ai pas utilisé ei de ces outils, mais ils semblent être suffisants pour ce que vous essayez d'accomplir.