Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
string fileName = @"C:\Users\test1.pdf";
byte[] buff = null;
FileStream fs = new FileStream(fileName,              
             FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long numBytes = new FileInfo(fileName).Length;
buff = br.ReadBytes((int) numBytes);
MemoryStream stream = new MemoryStream(buff);
webBrowser1.DocumentStream = stream;
webBrowser1.Show();
Posted
Updated 5-Oct-18 5:12am
v2
Comments
arkoleini 30-Aug-15 15:37pm    
WebBrowser.DocumentStream does not show pdf from stram and could not understand it
Sergey Alexandrovich Kryukov 30-Aug-15 16:03pm    
You cannot count in direct support of PDF, it's not covered by any W3 standards.
—SA

Try this..

byte[] yourByteData = .. assign your pdf data here ....
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Content-Type","application/pdf");
Response.AddHeader("Content-Length",yourByteData.Length.ToString());
Response.AddHeader("Content-Disposition","inline; filename=sample.pdf");
Response.BinaryWrite(yourByteData);
Response.Flush();
Response.End();
 
Share this answer
 
Comments
arkoleini 31-Aug-15 10:59am    
I think there is a confusion about web browser, it's WinForm control
webBrowser1.DocumentStream and need to load some how from byte[] or MemoryStream the
content of Pdf file.
This line is important
inline; filename
 
Share this answer
 
Comments
Richard Deeming 9-Oct-18 13:58pm    
You didn't read the question, did you?

Or the existing solution, and the OP's response to it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900