Welcome Guest Search | Active Topics | Sign In | Register

ASPXToPDF1 not converting image. Options
mhorrell
Posted: Thursday, October 16, 2014 9:59:25 AM
Rank: Member
Groups: Member

Joined: 11/2/2011
Posts: 10
Good Morning,
I am loving this program, but I just cant figure out why my logo is now showing up.. I have a page that I am generating and then using the aspxtopd to create a pdf on our server. It creates it fine but just no logo....

EO.Pdf.HtmlToPdf.Options.PageSize = New System.Drawing.SizeF(8.5F, 11.0F)
EO.Pdf.HtmlToPdf.Options.OutputArea = New System.Drawing.RectangleF(0.5F, 0.5F, 7.5F, 10.0F)
EO.Pdf.HtmlToPdf.Options.BaseUrl = "https://xxx.casemgntpro.com/"

ASPXToPDF1.RenderAsPDF(False)
end sub

Protected Sub ASPXToPDF1_AfterRender(ByVal sender As Object, ByVal e As EventArgs)
Dim result As HtmlToPdfResult = CType(ASPXToPDF1.Result, HtmlToPdfResult)


Dim directoryPath As String = Server.MapPath("~/Casefiles/Monthly/" & " " & Month(Me.txtEndDate.Text) & "-" & Day(Me.txtEndDate.Text) & "-" & Year(Me.txtEndDate.Text) & ".pdf")
result.PdfDocument.Save(directoryPath)


End Sub

<td class="style19" rowspan="5">
<asp:Image ID="Image1" runat="server" AlternateText="GJR" Height="122px"
ImageUrl="~/Images/logo.jpg" Width="266px" />
</td>
eo_support
Posted: Thursday, October 16, 2014 11:10:01 AM
Rank: Administration
Groups: Administration

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

This very often is a DNS issue. See here for more details:

http://www.essentialobjects.com/doc/4/web/troubleshoot.aspx

Thanks!
mhorrell
Posted: Thursday, October 16, 2014 11:49:10 AM
Rank: Member
Groups: Member

Joined: 11/2/2011
Posts: 10
I am having our IT guy look at this.. But Before I waste his time, Here is the question.
This is the documentation I found
EO.Pdf.HtmlToPdf.Options.BaseUrl = "http://www.essentialobjects.com/images/";
EO.Pdf.HtmlToPdf.ConvertHtml("<img src='logo.gif' />", "eo_logo.pdf");

I actually changed my base url from above to
EO.Pdf.HtmlToPdf.Options.BaseUrl = "https://xxx.casemgntpro.com/images/"
I am not creating the pdf file until the afterrender event
I am calling Sub ASPXToPDF1_AfterRender
I am not sure if I am coding this Statement correct??? How does it know which image I want to use to set the logo.jpg file to?? what if I had image1 and image2 on my page?? And is this the final pdf file that I would be creating. I am saving this file on my server in the afterRender event... Should I be setting that before the after render event??
EO.Pdf.HtmlToPdf.ConvertHtml("<img src='logo.gif' />", "eo_logo.pdf")

Sorry to be stupid.....

I am
eo_support
Posted: Thursday, October 16, 2014 1:25:40 PM
Rank: Administration
Groups: Administration

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

Usually you do not need to explicitly set BaseUrl when you use ASPXToPDF because ASPXToPDF would automatically set the BaseUrl for you based on the current page request. For example, if your page Url is http://yourserver/app1/page1.aspx", then it will automatically set BaseUrl to "http://yourserver/app1". The HTML to PDF converter engine then use this base Url value to expand partial Urls in your page into full Urls. For example, it would expand "logo.gif" into "http://yourserver/app1/logo.gif" in this case.

However this may not work sometimes. Particularly, if the Url "http://yourserver/app1/logo.gif" is only reachable from outside of the server but not from inside the server, then the converter will still be unable to load and convert the image. The link we provided above is about this situation.

To resolve the issue, you can either configure your server properly so that the Url is reachable both from inside and outside of the server, or you can override BaseUrl by setting it yourself. When you do so, you MUST set BaseUrl inside the ASPXToPDF's BeforeRender event handler. This is the key step. The reason is because ASPXToPDF will automatically set BaseUrl immediately before raising BeforeRender event. So if you set BaseUrl too early, then your value will be overwritten by ASPXToPDF.

Obviously the purpose of setting BaseUrl is to provide an alternative Url to the converter so that the converter will get a Url that is reachable from within the server. In the above case, if Url "http://yourserver/app1/logo.gif" is not reachable from within your server, then it obviously it would help at all even if you explicitly set BaseUrl to "http://yourserver/app1" since that does not change the full Url the converter will get and the converter will not be able to load that image.

As such you must find a reachable Url. For example, "http://localhost/app1/logo.gif" might be an reachable Url that would point to exactly the same resource as "http://yourserver/app1/logo.gif" as access from outside of the server. So if that's the case, you can set BaseUrl to "http://localhost/app1".

Even if you set an alternative BaseUrl to allow the resource to be loaded, you might still face other problems. For example, your Web server might treat the two requests "http://yourserver/app1/logo.gif" and "http://localhost/app1/logo.gif" as requests from different IIS applications, thus introducing issues related to application domain, sessions, etc. As such fixing the network issue would be the recommended method to resolve this issue.

Hope this gives you enough background information. Please let us know if you still have any questions.

Thanks!
mhorrell
Posted: Thursday, October 16, 2014 3:19:05 PM
Rank: Member
Groups: Member

Joined: 11/2/2011
Posts: 10
Thanks so much for your help, I really appreciate it...

Do I need to do anything with EO.Pdf.HtmlToPdf.ConvertHtml("<img src='logo.gif' />", "eo_logo.pdf") ??
Or do I just need to set the base url set the image as usual in the page like this
<asp:Image ID="Image1" runat="server" AlternateText="GJR" Height="107px"
ImageUrl="logo.jpg" Width="205px" />
</td>

THanks again.
eo_support
Posted: Friday, October 17, 2014 5:54:43 AM
Rank: Administration
Groups: Administration

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

I believe our previous reply has already clearly explained everything relating to BaseUrl to you. You will need to understand the logic behind it and make your own decision on what to do.

Thanks!
mhorrell
Posted: Friday, October 17, 2014 4:28:08 PM
Rank: Member
Groups: Member

Joined: 11/2/2011
Posts: 10
Your reply does not mention anything about :
EO.Pdf.HtmlToPdf.ConvertHtml("<img src='logo.gif' />", "eo_logo.pdf") ??
eo_support
Posted: Friday, October 17, 2014 9:40:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
mhorrell wrote:
Your reply does not mention anything about :
EO.Pdf.HtmlToPdf.ConvertHtml("<img src='logo.gif' />", "eo_logo.pdf") ??


The whole reply is about how BaseUrl affects the process of expanding partial "logo.gif" into full path such as "http://yourserver/app1/logo.gif", and what issues you will run into. It's exactly about this and nothing else.


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.