Welcome Guest Search | Active Topics | Sign In | Register

EO.WebBrowser Print to PDF Options
crenzi
Posted: Wednesday, December 3, 2014 8:49:38 AM
Rank: Member
Groups: Member

Joined: 11/13/2014
Posts: 13
Is there a way to print to a PDF file built into EO.WebBrowser?
eo_support
Posted: Wednesday, December 3, 2014 10:40:13 AM
Rank: Administration
Groups: Administration

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

No. EO.WebBrowser does not have that feature. However if you have a "Virtual PDF Printer" installed on your system, it can print into that "printer" as if it printed into a real printer.

To convert a web page to PDF without a virtual PDF printer, you will need to use our EO.Pdf product. EO.Pdf can convert any web page into a PDF file.

Thanks!
crenzi
Posted: Wednesday, December 3, 2014 10:45:05 AM
Rank: Member
Groups: Member

Joined: 11/13/2014
Posts: 13
Is there any way to use EO.PDF with the EO.WebBrowser. For example, some way to override the WebBrowser.Print() method and take its contents and use EO.PDF to print to a file?
eo_support
Posted: Wednesday, December 3, 2014 11:11:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Yes. You can follow these steps:

1. Call WebView.GetHtml() to get the current page HTML;
2. Call WebView.EvalScript("document.URL") to get the current page Url;
3. Get the base Url of the Url you get on step 2. The code will be something like this:

Code: C#
//"Normalize" the Url
Uri uri = new Uri(full_url);
string baseUrl = string.Format("{0}://{1}{2}",
	uri.Scheme, uri.Authority, uri.AbsolutePath);
if (baseUrl.LastIndexOf("/") ==
	baseUrl.LastIndexOf("://") + 2)
	baseUrl = baseUrl + "/";

//Now remove the page part
int nPos = baseUrl.LastIndexOf("/");
baseUrl = baseUrl.Substring(0, nPos + 1);


4. Set HtmlToPdf.Options.BaseUrl to the base Url value you get in step 3:

Code: C#
HtmlToPdf.Options.BaseUrl = baseUrl;


5. Call HtmlToPdf.ConvertHtml with the HTML you get on step 1:

Code: C#
//Convert HTML to a PDF file
HtmlToPdf.ConvertHtml(html, your_pdf_file_name);


This will produce a PDF file based on your current HTML. Alternatively, you can do:

Code: C#
//Convert HTML to a PdfDocument object
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertHtml(html, doc);


This will produce a PdfDocument object, which you can use it for other purpose: for example, you can save it into a MemoryStream to get a byte array, then email the byte array as an attachment; Or you can add another "cover page" to it before you finally save it as a file, etc. You can take a look of the EO.Pdf samples to see all the features available there.

Hope this helps. Please feel free to let us know if there is anything else.

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.