Welcome Guest Search | Active Topics | Sign In | Register

EO.Pdf Garbled PDF Options
Grant Szabo
Posted: Saturday, February 18, 2012 4:17:04 PM
Rank: Newbie
Groups: Member

Joined: 1/4/2011
Posts: 6
I'm a licensed user of the EO Web tools for more than 2 years now. I currently have a project that is requiring PDF export of HTML formatted content.

On my ASP.NET page, there is a Label Control that I write the contents of an HTML file to. This is an actual HTML file on disk that has customer information merged into it (like a mail merge) prior to assigning it to the Text property of the Label control. This way the user see's the information on the screen. Above this Label Control, I place a link button control that says "Export To PDF".

I have tried ASPXToPDF as well as HtmlToPdf.ConvertHtml (outputting to the Response.OutputStream) and have had a mixed bag with both. Currently, I'm focused on just getting this to work with HtmlToPdf.ConvertHtml and forgetting about ASPXToPDF.

Here is the html source of a test ASPX page that I set up to try to get this working:

Quote:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pdfTest.aspx.cs" Inherits="pdfTest" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<asp:LinkButton ID="lnkExportPDF" runat="server" Text="Export As PDF"
onclick="lnkExportPDF_Click"></asp:LinkButton> &nbsp;|&nbsp;
<a href="javascript:window.print()">Print Page</a>


<hr />

<asp:Label ID="lblDisplayDoc" runat="server"></asp:Label>

</form>
</body>
</html>



Here is the code-behind:

Quote:

public partial class pdfTest : System.Web.UI.Page
{
private Family oFamily = new Family();

protected void Page_Load(object sender, EventArgs e)
{
RenderDocument();
}

private void RenderDocument()
{
EmailInfo eInfo = new EmailInfo(463);
eInfo.GetMergeFieldInfo();

this.lblDisplayDoc.Text = oFamily.ImportScheduleFile(oFamily.GetFamilyEnum(2), eInfo).ToString();
}

protected void lnkExportPDF_Click(object sender, EventArgs e)
{
HtmlToPdf.ConvertHtml(this.lblDisplayDoc.Text, Response.OutputStream);
}
}


In IE9, this causes the PDF to appear right in the browser and it looks great. The only problem is that for whatever reason the BACK button on the IE9 browser is disabled and I cannot backup. This is a problem because ultimately there are more than one document that the customer may wish to export.

But, the bigger problem really is that the PDF only renders in IE correctly. If I try this in Chrome or Firefox (both latest versions), the PDF comes out all garbled. I've taken a screen capture and put the image here for you to see what I am talking about: http://www.hydeparksoftware.com/garbled_chrome.jpg

Whether I am using the DLL's that are in the root of
C:\Program Files (x86)\Essential Objects\EO.Pdf 2011.2 or
C:\Program Files (x86)\Essential Objects\EO.Web Controls 2011
the outcome is the same.

These are the versions of the files from my project's bin directory:

EO.Web.dll : Version 9.0.20.2
EO.Pdf.dll: Version 3.0.61.2 (1.07mb) (in this case, the one that comes with EO.Web, not EO.Pdf)
EO.Pdf.dll: Version 3.0.61.2 (13.8mb) (in this case, the one that comes with EO.Web, no EO.Pdf)

If I swap out EO.PDF.dll and EO.Html.dll with the ones from EO.Pdf 2011.2 the versions are:

EO.Pdf.dll: Version 3.0.104.2 (15.1mb)
EO.Html.dll: Version 2.0.67.2 (13.8mb)

Again, as I said, it doesn't seem to make any difference which set of DLL's are in use.

Perhaps this is a problem with the HTML file? The HTML that is being sent to the Label Control is a well-formed HTML document (as it is normally emailed as the body of an email message). It includes embedded style elements and an HTML table. It is reasonably long, here is just the top portion of it:

Quote:

<html>
<head>
<style>
body { font-family: arial; font-size: 13;}
table {font-family: arial; font-size: 13;}
.address{margin-left:25px;}
.bold {font-weight:bold}
.bolditalic {font-weight:bold; font-style:italic}
.header {font-weight:bold; font-variant:small-caps; margin:auto}
.center {text-align:center}
</style>
</head>
<body>

<table width="600">
<tr>
<td>


Thank you for any guidance you can provide.
eo_support
Posted: Saturday, February 18, 2012 6:31:04 PM
Rank: Administration
Groups: Administration

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

This has nothing to do with EO.Pdf. The file is correctly generated. The image you posted actually shows the correct PDF file in binary form. So the root of the problem is your browser can't display PDF file.

There are two possible scenarios:

1. You did not set the content type correctly in your code when you send the generated PDF file to the browser;
2. Your browser is not configured correctly thus it can not display PDF file;

In any case, the PDF file is generated correctly so this is neither an issue with HtmlToPdf.ConvertHtml nor an issue with your HTML file.

Thanks
Grant Szabo
Posted: Sunday, February 19, 2012 10:54:12 AM
Rank: Newbie
Groups: Member

Joined: 1/4/2011
Posts: 6
Thanks so much. I adjusted the Click Event Handler as follows and that took care of the problem:

Quote:

protected void lnkExportPDF_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
HtmlToPdf.ConvertHtml(this.lblDisplayDoc.Text, Response.OutputStream);
}
eo_support
Posted: Sunday, February 19, 2012 11:48:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Thanks for the update. That makes perfect sense.


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.