Hi, I would like to take a screenshot of a page. My main goal is to send this screenshot in order to print it with "goolge chrome print".
The page that I have to print use some parameter in the php session (I can't send the url to chrome) and it generates a ticket.
Here the script:
Code: C#
public void newwindowEvt(object sender, NewWindowEventArgs e)
{
string url = e.TargetUrl.ToString();
if (!checkMaxTab(url)) return;
Application.Current.Dispatcher.Invoke(new Action(() =>
{
WebControl wctr= new WebControl();
EO.Wpf.TabItem newtab = new EO.Wpf.TabItem();
e.WebView.CertificateError += webview_CertificateError;
e.WebView.BeforeContextMenu += new BeforeContextMenuHandler(WebView_BeforeContextMenu);
e.WebView.BeforePrint += new BeforePrintHandler(printhand);
newtab.Content = wctr;
newtab.Header = url;
if (!url_txt.IsFocused)
{
url_txt.Text = url;
}
wctr.WebView = e.WebView;
wcSelected = wctr;
myWV.Add(wctr);
tabCtrl.Items.Add(newtab);
tabCtrl.SelectedItem = newtab;
}));
e.Accepted = true;
}
void screenshot()
{
EO.WebBrowser.WebView wb=null;
try
{
wb = wcSelected.WebView;
wb.ZoomFactor = 0.6f; //this in order to get the whole page
System.Drawing.Image img=null;
System.Drawing.Size s = wb.GetPageSize();
System.Threading.Thread.Sleep(200);
wb = wcSelected.WebView;
img = wb.Capture();
s = wb.GetPageSize();
System.Drawing.Bitmap bmSnapshot = new System.Drawing.Bitmap(img);
bmSnapshot.Save(pathPrintFile, ImageFormat.Png);
printChrome(pathPrintFile);
}
catch (Exception e) {
MessageBox.Show(e.Message);
}
wb.ZoomFactor = mylocalConfiguration.zoom/100;
}
The screenshot function is linked to a button. It works with every page but it doesn't if the page comes from a newwindowEvt event.
The error says:
"reference to an object not set on an object instance" on this line "img = wb.Capture();"