Hi i have a big problem. I have a byte[] receveid from a Wcf service. The byte array represents a pdf file. In the Controller, i would like to do this:
PDFDto pdfDTO = new PDFDTO();
pdfDTO.pdfInBytes = pdfInBytes; //the byte array representing pdf
return PartialView("PopupPDF,pdfDTO);
in the View i would like to do this:
<object data="@Model.pdfInBytes" width="900" height="600" type="application/pdf"> </object>
but it seems uncorrect. I've searched in all the internet, there are a lot of posts about this problem but no one matches perfectly my situation. Have you got any ideas?Thanks a lot!
I would recommend creating another action on the controller designed specifically for rendering the PDF data. Then it's just a matter of referencing it within your data
attribute:
data="@Url.Action("GetPdf", "PDF")"
I'm not sure you can dump raw PDF data within the DOM without hitting some kind of encoding issue. You may be able to do like images, though I've never tried. But, for demo's sake and image would look like:
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
So, assuming the same could be done it would probably look like the following:
@{
String base64EncodedPdf = System.Convert.ToBase64String(Model.pdfInBytes);
}
@* ... *@
<object data="data:application/pdf;base64,@base64EncodedPdf"
width="900" height="600" type="application/pdf"></object>
I still stand by my original response to create a new action however.
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