|
Rank: Newbie Groups: Member
Joined: 5/23/2011 Posts: 6
|
How to get images to show, I don't know what image path to use.
Example:
I'm creating the HTML on the fly, it's not a html document. So I build it and then pass it in to HtmlToPdf.ConvertHtml(sHTML,sFilepathPDF);
Just and example:
string sHTML="<html><head><title></title></head><body>";
sHTML+="Hello here is an image. <img src='" + mylocalfilepath + "' />
The pdf file is created fine and the text shows but the images don't. When I check the output of the sHTML variable in VS 2010 the images display fine with the text.
Thanks
Gafa
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, You will need to set HtmlToPdf.Options.BaseUrl like this:
Code: C#
//Set the "base Url" to the root directory of C drive
HtmlToPdf.Options.BaseUrl = "file:///c:/";
//Convert "c:\abc.gif" to PDF
HtmlToPdf.ConvertHtml("<img src='abc.gif' />");
Note the src in your HTML only specifies the "relative path" against "base Url". Together they points to "c:\abc.gif". This is only necessary for local files. If you are actually open a Url through a Web server, then you usually do not need to set BaseUrl. Hope this helps. Please let us know if it works for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 5/23/2011 Posts: 6
|
Thank you it worked great.
Really like your product, very easy to use.
Gafa
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Glad to hear that! Please feel free to let us know if you have any more questions.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 10/14/2014 Posts: 17
|
I know this is an older thread but I encountered a problem with displaying images. In my case, I was trying to convert several html pages into a single PDF. Each page contained our company logo as an image. I set HtmlToPdf.Options.BaseUrl, looped through my list and created the PDF document. My image only showed up on the first page. After doing some digging, I discovered that the BaseUrl property is cleared right after you call HtmlToPdf.ConvertHtml. The solution was to set the BaseUrl in every iteration of the loop. I would imagine that this is a bug, so hopefully support can have this fixed in future versions. Thank you for such a useful, easy to use product.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi Bob, Thanks for sharing. The behavior you observed is by design and is documented here (the last line): http://www.essentialobjects.com/doc/4/eo.pdf.htmltopdfoptions.baseurl.aspxOur Html to PDF converter does automatically reset certain properties after the conversion is done. The reference section for the corresponding property will tell you whether it is automatically reset or not. Thanks!
|
|
Rank: Member Groups: Member
Joined: 10/14/2014 Posts: 17
|
Ok thanks for the reply - I will have to make sure to read the documentation more carefully next time!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
No problem. Please let us know if there is anything else.
Thanks!
|
|