user3279790
user3279790

Reputation: 27

How to open PDF that retrived from database to a specific page in MVC C#

I have been search similar posts for this question for few days, but still did not find any thing that meets my requirements.

This is my requirement: open a PDF in binary format to a specific page when user clicks on a hyperlink in a web grid.

This is my approach:

Step 1. PDFs are saved in database in binary format. The PDFs are retrieved by unique key that can be passed by the hyperlink click. I have code working for this already.

Step 2. The page number is determined when the PDF is retrieved and text-searched. I have code working for this already.

Step 3. Open the PDF using parameter page by directing user to http://example.org/doc.pdf#page=3 (example). Because the page number can not be passed in the first hyperlink click, Now I don't know how to take user to a new page without another user interaction or create an URL ends with #page=pageNumber in Controller redirect.

I really appreciate it you could provide me any help!

Upvotes: 0

Views: 557

Answers (1)

Hien Nguyen
Hien Nguyen

Reputation: 18975

You can do like this

@{
  var yourpdfcontent = "get from your DB"
}
<object data="data:application/pdf;base64,@Convert.ToBase64String(yourpdfcontent)" type="application/pdf" width="500px">
<embed src="data:application/pdf;base64, @Convert.ToBase64String(yourpdfcontent)" type="application/pdf" />
</object>

Refer this link Pdf file from database to view in asp.net mvc

Upvotes: 0

Related Questions