Welcome Guest Search | Active Topics | Sign In | Register

ConvertUrl file extension Options
Biz
Posted: Wednesday, September 3, 2014 8:01:28 PM
Rank: Member
Groups: Member

Joined: 8/26/2014
Posts: 20
When I use ConvertUrl to convert a local HTML file, I get an error if the file's extension is not htm. Is there a work around for this?
eo_support
Posted: Wednesday, September 3, 2014 8:24:06 PM
Rank: Administration
Groups: Administration

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

You can use something like this:

Code: C#
//Get the HTML text
string html = File.ReadAllText(filePath);

//This line is important if your HTML file uses other resources
//such as images, JavaScript, etc. Replace "c:/somepath" with
//the real folder of the HTML file
HtmlToPdf.Options.BaseUrl = "file:///c:/somepath/";

//Use ConvertHtml instead of ConvertUrl
HtmlToPdf.ConvertHtml(html, result_pdf_file);


Thanks!
Biz
Posted: Thursday, September 4, 2014 5:57:08 PM
Rank: Member
Groups: Member

Joined: 8/26/2014
Posts: 20
So, that function requires the URL to have a htm extension? What other extensions are allowed? Thanks.
eo_support
Posted: Thursday, September 4, 2014 6:34:25 PM
Rank: Administration
Groups: Administration

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

It supports common known file types such as txt, htm, xml, jpg, etc. The reason that file extension is important is it determines the "mime" type of the page. For example, for the same HTML content if it has a "htm" extension then the browser will display it as HTML, but if it has a "txt" extension then the browser will display it as plain text without interpreting any HTML tags. When a page is loaded through HTTP, the web server sends the mime type in the HTTP header, so the extension does not matter. When a page is loaded from a file, the file extension is the only hint that can be used to derive the mime type. In this case, when your file has an unrecognized extension or no extension, the browser engine can not derive the mime type of the contents thus refuses to load it.

Thanks!


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.