Welcome Guest Search | Active Topics | Sign In | Register

ASPXToPDF reference image and css problem Options
hamh
Posted: Monday, October 30, 2017 2:50:10 AM
Rank: Newbie
Groups: Member

Joined: 10/30/2017
Posts: 5
Hi, I'm having problem showing images and css style on a page which I use ASPXToPDF to convert the page into a pdf file.

If I comment out the RenderAsPDF line, the page can be shown with the image and css style without no problem on the browser. However, if I convert it to PDF with the RenderAsPDF method, then the image will be broken, and the css style doesn't apply.

To give you the background of this page:

it is hosted under the following structure:

/ is the root of the host
/dev/Schools/hamtest1.aspx is the page I'm talking about
/dev/Schools/images/ATA_header.jpg is an image I need to reference in the page
/dev/Schools/Styles/Sitepdf.css is the css stylesheet I need to use on the page, thus the resulting pdf
when I try to get the HtmlToPdf.Options.BaseUrl in the BeforeRender event handler, the value is "https://www.aed-technical-assessments.com/dev/schools/"

With the information above, I've put the css style and image tags as follow:
<link href="Styles/Sitepdf.css" rel="stylesheet" type="text/css" />
<img src="images/ATA_header.jpg" alt="" />

But the problem still exists and I can't see the image and style in the rendered pdf, can someone from the support team help please?

The page is located at:
To see it in plain html:
https://www.aed-technical-assessments.com/dev/schools/hamtest1.aspx
To see it rendered in pdf:
https://www.aed-technical-assessments.com/dev/schools/hamtest1.aspx?pdf=true

Note: I just use the querystring to toggle if the RenderToPdf method will execute or not.
eo_support
Posted: Monday, October 30, 2017 8:21:53 AM
Rank: Administration
Groups: Administration

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

Please try to access exactly the same Url without "pdf=true" from within your server. For example, you can use Windows Remote Desktop to connect to your web server, then open any browser (Google Chrome preferred) on your web server and access the Url to see if all images/styles are rendered OK. If they do not render OK, then you may have a DNS problem, which is the most common cause for such problems. See here for more details:

https://www.essentialobjects.com/doc/web/aspxtopdf/troubleshoot.aspx

If the problem still occurs, try to handle the ASPXToPDF's BeforeRender event and check HtmlToPdf.Options.BaseUrl value to see if that makes sense to you. If it is not correct (it can happen if you have something in the middle such as a load balancer), you can explicitly override it with code in your BeforeRender handler.

Thanks!
hamh
Posted: Monday, October 30, 2017 12:29:09 PM
Rank: Newbie
Groups: Member

Joined: 10/30/2017
Posts: 5
I'll have to check with the hosting company, the thing is, we don't own the server, and we are only using a hosting space from them.

In case if the hosting company don't allow such DNS change, is there any other option?

On a related topic, if I move the website to Azure PaaS App Service, will I see the same problem? Because there is no server setup as well.
eo_support
Posted: Monday, October 30, 2017 1:06:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
In case you do not have control over the server, you would just check the BaseUrl from your BeforeRender event handler and override the default value if needed. The key here is ASPXToPDF runs on your server, not on the client machine. So the same Url that is perfectly accessible from the client machine may not be accessible from within your web server. For example, while Url "http://www.yoursite.com/styles.css" is perfectly accessible from outside of your webserver, the same Url may not work from within your server because www.yoursite.com can point to an outside IP address that is not reachable from your web server.

Your goal is to fix this problem. The two options you have is:

1. Configure your server properly so that the same Url is accessible from within your server. For example, in the above case you can configure "www.yoursite.com" to point to "localhost" on your web server and make it reachable;
2. Override the default BaseUrl so that the converter would use an alternative Url to access the same resource. For example, the default base Url for the above case would be "http://www.yoursite.com", if you change it to "localhost", then the converter engine will look for "http://localhost/styles.css" instead, which can resolve the issue for you;

Note that here I gave you "localhost" is only for an example. Your host company may have different values so you may need to contact them to find out. The goal is to have the resources accessible from within your web server.


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.