Open PDF in web page of ASP.NET

I want to open PDF in ASP.NET aspx page. I dont want to export a pdf file.

Need just write pdf file in ASPX page same as we are writing bytes into Image control.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I got the answer , it is too simple.

I have answered here.

Response.Clear();
string filePath = "myfile.pdf";
Response.contentType = "application/pdf";
Response.WriteFile(filePath);
Response.End();

Method 2

Place the pdf document in an IFrame in your page.

Method 3

Try below code:
Here FullPath is full path of file with file name

Dim f1 As New FileStream(FullPath, FileMode.Open)
Dim m1(f1.Length) As Byte
f1.Read(m1, 0, f1.Length)
f1.Close()
File.Delete(FullPath)
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.Clear()
Response.OutputStream.Write(m1, 0, m1.GetLength(0))

Method 4

to Create PDF-Files you can use a library like pdfsharp
http://pdfsharp.com/

you can easily create PDFs with that. Example Code:

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
...

and then save it on your Server

document.Save(filename);

then just link to it via an a-href or in an iframe.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x