asp.net - Setting the src attribute of an IFrame to data:application/pdf;base64? -


Setting the src attribute of iframe into data: application / pdf; Base 64 is not working for me, no idea why?

Here is the .aspx markup

  & lt;% @ Page language = "C #" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inheritance = "_Default"% & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Head runat = "server" & gt; & Lt; Title & gt; Untitled Page & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function loadIFrameFromHiddenField () {// in the hidden area var xmlDoc = new ActiveXObject ("Microsoft.XMLDOM"), get xml from node containing base64 pdf data; XmlDoc.loadXML (document.getElementById ("pdfData") value.); XmlDoc.setProperty ('SelectLanguage', 'XPath'); Var pdfDataNode = xmlDoc.selectSingleNode ("// PDF"); // If we have found the node (pdfDataNode! = Null) {// Get the data and add it to src content pdfIFrameSrc = "data: application / pdf; base64," + pdfDataNode.text; // Set src attribute document .getElementById ("pdfIFrame"). SetAttribute ("src", pdfIFrameSrc); }} & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" style = "width: 100%; height: 100%;" & Gt; & Lt; Asp: HiddenField id = "pdfData" runat = "server" /> & Lt; Div style = "width: 100%; height: 80%;" & Gt; & Lt; Iframe id = "pdfIFrame" runat = "server" scrolling = "auto" frameboard = "0" margin height = "0" margin width = "0" style = "height: 99.5%; width: 99.5%" /> & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

and the code behind it:

  using the system; Using System.Data; Using System.configuration; Using System.Web; Using System.Web.Security; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Web.UI.WebControls.WebParts; Using System.Web.UI.HtmlControls; Using System.IO; Using System.Text; Using System.Xml; Public Partial Class _Default: System.Web.UI.Page {Secure Sender Page_load (Object Sender, EventArgse E) {// Get Bytes by Our PDF Byte [pdfBytes = File.ReadAllBytes ("c: \\ temp \\ Test. Pdf "); // build xml is submitting our base 64 encoded PDF data and places it in the hidden area pdfData.Value = buildDocumentXML (pdfBytes, "TestDoc"); // iframe string script add js function to add src for text; & Lt; Script type = 'text / javascript' & gt; LoadIFrameFromHiddenField () & lt; / Script & gt; "; ClientScript.RegisterStartupScript (this.GetType ()," loadIFrameFromHiddenField ", script text);} Private string builddowninXML (byte [] PDFBights, string document name) {stringbinder document string = new stringbilder (); XmlWriterSettings documents XmlSettings = new XmlWriterSettings ( ); DocumentsXmlSettings.Indent = false; DocumentsXmlSettings.OmitXmlDeclaration = true; DocumentsXmlSettings.ConformanceLevel = ConfessionsLiv.Fraagment; DocumentsXmlSettings.NewLineHandling = NewLineHandling.None; (XmlWriter documents using XmlWriter = XmlWriter.Create (documentsString, documentsXmlSettings)) {DocumentsXmlWriter.WriteStartElement ("DOCUMENTS"); documentsXmlWriter.WriteStartElement ("FILENAME"); documentsXmlWriter.WriteString (DocumentName); documentsXmlWriter.WriteEndElement (); documentsXmlWriter.WriteStartElement ("PDF"); DocumentsXmlWriter.WriteBase64 (pdfBytes, 0, pdfBytes .Length); documentsXmlWriter.WriteEndElement (); documentsXmlWriter.WriteEndElement (); } Return documents String.ToString (); }}  

Unlike this example, in the actual app, the PDF data is generated on the server side. The reason I am trying to load PDF data clients, I have to do a bit more to do PDF byte data client and I am trying to reduce the examples of this data which is generated and cluttered . Simply paste the above code and markup into a simple one page website in VS2005 and touch any old PDF in c: \ temp \, call it TestDoc.pdf and compile it and run it.

Actually what I see is nothing in the IFrame.

I am using IE 7 so that there is a problem. Data: App / PDF; Base 64 [Base 64 Data] I do not know since precious little information about using syntax.

As far as I know, it does not handle IE data: the URL scheme is at all, therefore I do not know what to pass to the PDF viewer.

Cheers,


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -