|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
When setting the HtmlToPdf.Options.BaseUrl to "file:///c:\images\" and using the HtmlToPdf.ConvertHtml to build a pdf, the local image files in the "c:\images\" directory are not loaded properly because the url in the html is "/content/client/logos/logo.png". I had to flip the forward slashes in the html to backward slashes (and also remove the leading forward slash) in order for the images on the file server to appear properly on the pdf. When my image src attribute is "content\client\logos\logo.png" then the image will load properly in the pdf.
Please add a solution so I can use "file:///c:\images\" as the BaseUrl and the img src attribute be "/content/client/logos/logo.png".
|
|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
I am using version 17.2.92
|
|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
It also looks like I am not able to load images in CSS using the background-image property (when referencing the images locally).
background-image: url('/content/client/logos/logo.png') -> this fails to load properly
I also tried flipping the slashes so,
background-image: url('content\client\logos\logo.png') -> this also fails to load properly
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,225
|
Hi,
The path handling is done by the Chromium browser engine that is embedded inside our DLL. We can not modify the behavior of the browser engine since it can cause other problems.
BaseUrl for local file works very different than BaseUrl for a regular Url resource. The key difference for local file is the host part is empty. So for a Url "c:/images/1.jpg", The components of the Url is as follow:
protocol: file:// host name: empty path: /c:/images/1.jpg
The implication for this is the root path "/" alone has no meaning for a local file Url. A root path points to the first "/" before drive letter "c:" in the above path. Unless you have a drive letter immediately after it, it is not valid and has no meaning. So you should avoid using root path such as "/content/client/logos.png" and use relative path only (without the leading "/").
Additionally, if your background image is specified in a CSS file, then the image path should be relative to the CSS file, not the BaseUrl you specified.
Hope this helps.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
When using BaseUrl = "file://c:/images/" the url for images will work when only omitting the leading forward slash -> "content/client/logos.png" (will load the image properly). When using the image url as "/content/client/logos.png" then the image fails to load properly.
Is there anyway to get this scenario without modifying the html image urls (being able to use "/content/client/logos.png" as the url) ?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,225
|
I have already explained to you in my previous reply that you should use relative path, not absolute path with local file. We have also gave you detailed explanation why absolute path for local Url doesn't work. Yet you still ask us how to get the absolute path work. Is there any part in our previous reply that is not clear to you?
|
|
Rank: Member Groups: Member
Joined: 2/21/2013 Posts: 12
|
Okay we will have to parse the html we are rendering and remove the leading slashes. Thanks.
|
|