I have a PDF that was generated by ASPose as a byte array, and I want to render that PDF inside of a component on a web page.
using (MemoryStream docStream = new MemoryStream())
{
doc.Save(docStream, Aspose.Words.SaveFormat.Pdf);
documentStream = docStream.ToArray();
}
I thought it would just be a simple variation on assigning the byte array to the data attribute in the code behind. Below is the setup, and some of the variations that I tried. What can I do to render that array of bytes as a visible sub-component of my web page?
HtmlGenericControl pTag = new HtmlGenericControl("p");
pTag.InnerText = "No Letter was Generated.";
pTag.ID = "errorMsg";
HtmlGenericControl objTag = new HtmlGenericControl("object");
objTag.Attributes["id"] = "pdf_content";
objTag.Attributes["height"] = "400";
objTag.Attributes["width"] = "500";
String base64EncodedPdf = System.Convert.ToBase64String(pdfBytes);
//1-- Brings up the "No Letter was Generated" message
objTag.Attributes["data"] = "data:application/pdf;base64," + base64EncodedPdf.ToString();
//2-- Brings up the gray PDF background and NO initialization bar.
objTag.Attributes["type"] = "application/pdf";
objTag.Attributes["data"] = "data:application/pdf;base64," + base64EncodedPdf.ToString();
//3-- Brings up the gray PDF background and the initialization bar, then stops.
objTag.Attributes["type"] = "application/pdf";
objTag.Attributes["data"] = pdfBytes.ToString();
//4-- Brings up a white square of the correct size, containing a circle with a slash in the top left corner.
objTag.Attributes["data"] = "application/pdf" + pdfBytes.ToString();
objTag.Controls.Add(pTag);
pdf.Controls.Add(objTag);