See the following code:
Controller:
public ActionResult GetPDF()
{
byte[] pdf = GetPdfFromDatabase();
return new FileContentResult(reportData, "application/pdf");
}
View:
<iframe src="@Url.Action("GetPDF","Account")" width="600" height="500"></iframe>
Javascript Console:
Each time you load a page, show this warning !!!
An iframe requests the resource mentioned in src attribute with a content type text/html. So this message only says "I requested html but server responded with pdf"
For who come across this topic. (Me too.) For best solution is you need to create HTML page to act as iframe landing page to show PDF content.
This is example html. I just extract from chrome.
<html><body style="background-color: rgb(38, 38, 38); height: 100%; width: 100%; overflow: hidden; margin: 0px;"><embed width="100%" height="100%" name="plugin" id="plugin" src="your_pdf_url" type="application/pdf"></body></html>
Just replace your_pdf_url
to your real url. I just add this html as middleware in Laravel and show this HTML so Chrome will not warning anymore. You can use this html as base and create better pdf landing page such as custom loading.
I believe the warning can't be ignored.
An alternative I found to this problem, use the object tag, like this:
<object data="your-data-base-64" type="application/pdf"></object>
and if you using angularJS, to prevent error on console do:
<object ng-attr-data="your-data-base-64" type="application/pdf"></object>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With