Welcome Guest Search | Active Topics | Sign In | Register

ConvertURL and View in IE8/9 Options
LegionArclight
Posted: Wednesday, October 5, 2011 4:58:54 PM
Rank: Newbie
Groups: Member

Joined: 10/5/2011
Posts: 7
Hi,

I am trying to use the ConvertURL function according to your example project in C# and display the content directly into IE8/9. When the page is loaded on IE8/9, it will display a bunch of gibberish/rubbish codes (I think they are the binary content of the PDF file). The following is the code following your example:


protected void Button1_Click(object sender, EventArgs e)
{
//Set the response header
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearHeaders();
response.ContentType = "application/pdf";

//Convert to the output stream
EO.Pdf.HtmlToPdf.ConvertUrl(your_page_url, response.OutputStream);

response.End();
}

How do I display the PDF file correctly in IE8/9?

Thanks.
eo_support
Posted: Wednesday, October 5, 2011 5:06:36 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

This most likely is because you do not have a PDF Viewer plug-in installed/registered for your IE (or you have one but disabled it). The server just sends the PDF file down to IE and tells IE that this is a PDF file (by setting the ContentType to "application/pdf"). Whether the browser can show it would be something up to your browser. You may want to put a static PDF file on your server and verifies whether your IE can show it or not.

Thanks!
LegionArclight
Posted: Wednesday, October 5, 2011 5:08:48 PM
Rank: Newbie
Groups: Member

Joined: 10/5/2011
Posts: 7
Hi,

I am sure that my IE8/9 has a PDF Viewer plug-in installed and running because if I were to navigate to this URL https://www.kln.gov.my/ekonsular_on9/skb_english/topdf/apps/print2.php, I will be able to see the PDF file itself in my IE8/9.

Any other suggestions/ideas?
LegionArclight
Posted: Wednesday, October 5, 2011 5:11:01 PM
Rank: Newbie
Groups: Member

Joined: 10/5/2011
Posts: 7
I am sorry, the previous link was a bad example, this link to a PDF will be displayed in IE8/9: http://www.airasiainsure.com/pdf/Malaysia%20-%20One%20Way%20Domestic.pdf
eo_support
Posted: Wednesday, October 5, 2011 5:24:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
It can still be some problems with your IE plug-in configuration. The difference between the two cases is when you dynamically create a PDF file, the extension is not .pdf. So the browser will have to rely on the "ContentType" header to determine which application to load. When you load a static .pdf file, the browser does not have to rely on the "ContentType" header at all. The plug-in supposes to register that it can handle this particular "ContentType" and fire up accordingly. If that part is corrupt, then your browser won't load the plug-in when it sees the corresponding content type.

I would recommend you to change your code to load a static Pdf file on your server and then send it to the client. The code will be something like this:

Code: C#
//Set up the header
response.Clear();
response.ClearHeaders();
response.ContentType = "application/pdf";

//Load the pdf data from a file
byte[] pdfData = File.ReadAllBytes(a_pdf_file_on_your_server);

//Send the raw bytes down to the browser
response.OutputStream.Write(pdfData, 0, pdfData.Length);

response.End();


If even this does not work, then the problem definitely has to do with your IE. You may want to reinstall Adobe Reader to get it working.

If this works but when you call ConvertUrl it does not work, then change your code to the following:

Code: C#
//Get the raw bytes of the pdf document
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(your_url, doc);
MemoryStream ms = new MemoryStream();
doc.Save(ms);
byte[] pdfData = ms.ToArray();


Now you should come to the same scenario with your “working scenario” because in both cases you are sending the raw bytes down to the browser directly.

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.