Snap functions | |
Functions to take snapshots. | |
| HtmlCaptureResult | SnapUrl (string strUrl) |
| Take a snapshot for the specified URL. | |
| HtmlCaptureResult | SnapHtmlString (string strHtml) |
| Take a snapshot for html text. | |
| HtmlCaptureResult | ReSnap () |
| Repeat the last Snap operation (SnapUrl() or SnapHtmlString()). | |
| HtmlCaptureResult | SnapWebBrowser (IDispatch *pWebBrowser) |
| Take snapshot for an existing web browser. | |
| void | Stop () |
| Cancel the snap job. | |
Image access functions | |
Functions to access the resulting image. | |
| bool | SaveImage (string strFileName) |
| Save the snap's resulting image to a local file (image or PDF) after a snap function succeeds. | |
| byte[] | GetImageBytes (string strFormat) |
| Get the in-memory image bytes after a snap function succeeds. | |
| long | GetBmpHandle () |
Get the HBITMAP handle to the resulting image. | |
| long | GetEmfHandle () |
Get the HENHMETAFILE handle to the resulting image. | |
| bool | SaveMultiPageTiff (string strFileName, long nPageHeight) |
| Save the snap's resulting image to multi-page TIFF file after a snap function succeeds. | |
| void | GetImageSize (long *pWidth, long *pHeight) |
| Get the size of resulting image. | |
| void | CreatePDF (string strFileName) |
| Create a PDF document for adding snapshot image to. | |
| void | AddImageToPDF () |
| Add snap result to the PDF document created by CreatePDF() as a new page after a successful snap. | |
| void | ClosePDF () |
| Save and close the PDF document created by CreatePDF(). | |
| void | CreateTiff (string strFileName) |
| Create a Tiff document for adding snapshot image to. | |
| void | AddImageToTiff (bool bLastPage) |
| Add snap result to the TIFF document created by CreateTiff() as a new page after a successful snap. | |
| void | CloseTiff () |
| Close the Tiff document created by CreateTiff(). | |
Snap options | |
Get/set options that affects snap. | |
| long | GetTimeOut () |
| Get the time out value in milliseconds for snap functions. | |
| void | SetTimeOut (long nTimeOut) |
| Set the time out value in milliseconds for snap functions. | |
| long | GetDelayTime () |
| Get the time value in milliseconds to wait for after a html document is downloaded. | |
| void | SetDelayTime (long nDelayTime) |
| Set the time value in milliseconds to wait for after a html document is downloaded. | |
| float | GetZoomRatio () |
| Get the zoom ratio of the html page when taking snapshot. | |
| void | SetZoomRatio (float fZoomRatio) |
| Set the zoom ratio of the html page when taking snapshot. | |
| bool | GetActiveXEnabled () |
| Get if ActiveX is enabled (visible) on a web page. | |
| void | SetActiveXEnabled (bool bEnabled) |
| Set if ActiveX is enabled (visible) on a web page. | |
| bool | GetImageEnabled () |
| Get if images are enabled (visible) on a web page. | |
| void | SetImageEnabled (bool bEnabled) |
| Set if images are enabled (visible) on a web page. | |
| bool | GetJavaEnabled () |
| Get if java applets are enabled on a web page. | |
| void | SetJavaEnabled (bool bEnabled) |
| Set if java applets are enabled on a web page. | |
| bool | GetScriptEnabled () |
| Get if scripts are enabled (can be executed) on a web page. | |
| void | SetScriptEnabled (bool bEnabled) |
| Set if scripts are enabled (can be executed) on a web page. | |
| bool | GetVideoEnabled () |
| Get if videos are enabled (visible) on a web page. | |
| void | SetVideoEnabled (bool bEnabled) |
| Set if videos are enabled (visible) on a web page. | |
| void | GetMinBrowserSize (long *pWidth, long *pHeight) |
| Get the minimum size of the hidden web browser window. | |
| void | SetMinBrowserSize (long nWidth, long nHeight) |
| Set the minimum size of the hidden web browser window. | |
| string | GetStartupScript () |
| Get the JScript code to be executed before each Snap (after document downloaded). | |
| void | SetStartupScript (string strScript) |
| Set the JScript code to be executed before each Snap (after document downloaded). | |
| string | GetCookies () |
| Get the cookies of the webpage just snapped. | |
| void | SetCookies (string strUrl, string strCookies) |
| Set cookie(s) for the specified url. | |
| void | ClearCustomCookies () |
| Clear all the cookies set by SetCookies() call. | |
| void | SetAccessCredential (string strUsername, string strPassword) |
| Set user name and password for snap requests to secure webpages. | |
| void | GetAccessCredential (string *strUsername, string *strPassword) |
| Get the credential information currently set. | |
| void | SetProxy (string strHost, LONG nPort, string strUsername, string strPassword) |
| Set up proxy server information. | |
| void | GetProxy (string *strHost, LONG *nPort, string *strUsername, string *strPassword) |
| Get current proxy settings. | |
| void | SetPostData (string strPostData) |
| Set post data. | |
| string | GetPostData () |
| Get the post data currently set. | |
| void | SetReferer (string strReferer) |
| Set the REFERER HTML Header for snap requests. | |
| string | GetReferer () |
| Get the current REFERER HTML Header. | |
| void | SetUserAgent (string strUserAgent) |
| Set USER AGENT string for HtmlCapture. | |
| string | GetUserAgent () |
| Get the USER AGENT string currently set. | |
| void | SetCustomHeaders (string strHeaders) |
| Set custom HTTP headers for snap requests. | |
| string | GetCustomHeaders () |
| Get the custom HTTP headers currently set. | |
| void | SetRenderingEngine (string strEngine) |
| Set the HTML rendering engine used by HtmlCapture. | |
| string | GetRenderingEngine () |
| Get the HTML rendering engine used by HtmlCapture. | |
Image access options | |
Get/set options that affects image access. | |
| void | GetClipRect (long *pLeft, long *pTop, long *pWidth, long *pHeight) |
| Get the clip rect to the resulting image. | |
| void | SetClipRect (long nLeft, long nTop, long nWidth, long nHeight) |
| Set the clip rect to the resulting image. | |
| void | GetThumbSize (long *pWidth, long *pHeight, bool *pKeepRatio) |
| Get the preset thumbnail image size. | |
| void | SetThumbSize (long nWidth, long nHeight, bool bKeepRatio) |
| Set thumbnail image size. | |
| long | GetBpp () |
| Get color depth of the resulting image. | |
| void | SetBpp (long nBpp) |
| Set color depth of the resulting image. | |
| void | GetDPI (long *pDpiX, long *pDpiY) |
| Get resolution for TIFF, JPEG, PNG and BMP image formats. | |
| void | SetDPI (long nDpiX, long nDpiY) |
| Set resolution for TIFF, JPEG, PNG and BMP image formats. | |
| byte | GetJpegQuality () |
| Get JPEG quality when saving image as JPEG. | |
| void | SetJpegQuality (byte nQuality) |
| Set JPEG quality when saving image as JPEG. | |
| HtmlCaptureTiffEncoder | GetTiffEncoder () |
| Get the TIFF encoder when saving image as TIFF format. | |
| void | SetTiffEncoder (HtmlCaptureTiffEncoder nEncoder) |
| Set the TIFF encoder when saving image as TIFF format. | |
| HtmlCaptureGifEncoder | GetGifEncoder () |
| Get the GIF encoder when saving image as GIF format. | |
| void | SetGifEncoder (HtmlCaptureGifEncoder nEncoder) |
| Set the GIF encoder when saving image as GIF format. | |
| HtmlCaptureDitherMethod | GetDitherMethod () |
| Get the dither method when converting image to B&W. | |
| void | SetDitherMethod (HtmlCaptureDitherMethod nMethod) |
| Set the dither method when converting image to B&W. | |
| long | GetThreshold () |
| Get the threshold value for converting image to B&W. | |
| void | SetThreshold (long nThreshold) |
| Set the threshold value for converting image to B&W. | |
| bool | GetErrorDiffusion () |
| Get if using error diffusion algorithm when decreasing Bpp . | |
| void | SetErrorDiffusion (bool bErrorDiff) |
| Set if using error diffusion algorithm when decreasing Bpp . | |
| bool | GetOptimalPalette () |
| Get if using an optimal palette when decreasing Bpp . | |
| void | SetOptimalPalette (bool bOptimalPal) |
| Set if using an optimal palette when decreasing Bpp . | |
| bool | GetGrayScale () |
| Get if converting resulting image to gray scale in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| void | SetGrayScale (bool bGrayScale) |
| Set if converting resulting image to gray scale in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| bool | GetBlackAndWhite () |
| Get if converting resulting image to B&W in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| void | SetBlackAndWhite (bool bBAndW) |
| Set if converting resulting image to B&W in the next SaveImage(), GetImageBytes() or GetBmpHandle() call. | |
| HtmlCaptureInterpolationMode | GetInterpolationMode () |
| Get the interpolation mode when resizing an image. | |
| void | SetInterpolationMode (HtmlCaptureInterpolationMode nMode) |
| Set the interpolation mode when resizing an image. | |
| void | SetMargins (long nLeft, long nTop, long nRight, long nBottom) |
| Set the extra margins on the output image. | |
| void | GetMargins (long *nLeft, long *nTop, long *nRight, long *nBottom) |
| Get the current extra margins values. | |
| void | SetMarginColor (byte nRed, byte nGreen, byte nBlue) |
| Set the background color of the extra margin area created by SetMargins(). | |
| void | GetMarginColor (byte *nRed, byte *nGreen, byte *nBlue) |
| Get the current margin color value. | |
HTML utility functions | |
Some utility functions to retrieve information about the webpage. | |
| string | GetDocumentTitle () |
| Get the title of the web page just snapped. | |
| string | GetDocumentSource () |
| Get the html source of the web page just snapped. | |
| string[] | GetDocumentLinks () |
| Get the URLs of links on the web page just snapped. | |
| string[] | GetDocumentFrames () |
| Get the URLs of frames on the web page just snapped. | |
| string | GetDocumentText () |
| Get the text content of the web page just snapped. | |
| IDispatch * | GetHtmlDocument () |
| Get WebBrowser's html document dispatch interface. | |
Other functions | |
| | |
| string | SaveOptions () |
| Save all options (snap options and image access options) to a string. | |
| void | RestoreOptions (string strOptions) |
| Restore all options (snap options and image access options) saved by calling SaveOptions(). | |
| variant | GetAttributeValue (string strName) |
| Get a named attribute value. | |
| string | GetReserved (string strIdx) |
| Get reserved properties. | |
| void | SetReserved (string strIdx, string newVal) |
| Set reserved properties. | |
| void | SetRegInfo (string strUserName, string strRegCode) |
| Set registration info. | |
| HtmlCaptureResult SnapUrl | ( | string | strUrl | ) |
Take a snapshot for the specified URL.
The function navigates a hidden WebBrowser to the specified URL and takes a snapshot for the web page. The resulting image can be saved to file or copied to memory. To take a snapshot for a html string, call SnapHtmlString().
| strUrl | The URL of the web page to be taken snapshot. For example, http://www.polestarsoft.com or file:///C:/test.htm |
Sleep() Win32 API, this function runs a message loop to wait. So windows message can still be processed when SnapUrl() is executing. Call Stop() in a message handler to cancel the execution of SnapUrl() and its return value will be HCR_USER_INTERRUPT.| HtmlCaptureResult SnapHtmlString | ( | string | strHtml | ) |
Take a snapshot for html text.
The function is the same as SnapUrl() except that it takes html text as parameter, not URL. It operates entirely in memory, no temporary files used.
| strHtml | The string contains html text. |
| HtmlCaptureResult ReSnap | ( | ) |
Repeat the last Snap operation (SnapUrl() or SnapHtmlString()).
SnapUrl(LASTURL) or SnapHtmlString(LAST_HTML_STRING).| HtmlCaptureResult SnapWebBrowser | ( | IDispatch * | pWebBrowser | ) |
Take snapshot for an existing web browser.
| pWebBrowser | An IWebBrowser2 interface pointer of the existing web browser. |
| void Stop | ( | ) |
Cancel the snap job.
If SnapUrl(), SnapHtmlString() or ReSnap() is called and blocked, Stop() make them return at once.
| bool SaveImage | ( | string | strFileName | ) |
Save the snap's resulting image to a local file (image or PDF) after a snap function succeeds.
| strFileName | The image file name. Since this function uses the extension name to determine image format, it must end with an extension name, for example: "c:\snapshot1.jpg", "d:\snapshot.png", etc. |
true, else false.HBITMAP or an HENHMETAFILE handle, call GetBmpHandle() and GetEmfHandle() respectively. ISnapShooter2 snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { if(snap.SaveImage("c:\\snapshot.png")) MessageBox("Snapshot saved."); }
| byte [] GetImageBytes | ( | string | strFormat | ) |
Get the in-memory image bytes after a snap function succeeds.
In this way, you can convert html to image in memory.
| strFormat | A string that represents the image format. For example: "PNG", "WMF". For a list of image formats supported, see SaveImage. |
| long GetBmpHandle | ( | ) |
Get the HBITMAP handle to the resulting image.
Call this function after a snap function succeeds. The returned bitmap is also affected by those image access options. If you want them to take effects, set them before call this function.
HBITMAP handle. If the function fails, the return value is NULL. NULL, you need to free the returned bitmap handle with DeleteObject Win32 API.HBITMAP handle (a GDI object). It can be used as a normal GDI object. If you want to get a HENHMETAFILE handle, call GetEmfHandle() instead. ISnapShooter2 snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { HBITMAP hbmp = (HBITMAP)snap.GetBmpHandle(); if (hbmp != NULL) { pictureBox.SetBitmap(hbmp); //picture box is a CStatic variable //we need not to call DeleteObject(hbmp), since pictureBox will delete it. } }
| long GetEmfHandle | ( | ) |
Get the HENHMETAFILE handle to the resulting image.
Call this function after a snap function succeeds. The returned meta file is also affected by those image access options. If you want them to take effects, set them before call this function.
HENHMETAFILE handle. If the function fails, the return value is NULL.HENHMETAFILE handle. Since EMF images are vector images, they can shrink and grow with no distortion. If you want to get a raster image handle, call GetBmpHandle() instead. ISnapShooter2 snap; if (snap.SnapUrl("http://www.polestarsoft.com") == HCR_SUCCESS) { HENHMETAFILE hemf = (HENHMETAFILE)snap.GetEmfHandle(); if (hemf != NULL) { CRect rc; GetClientRect(&rc); //get client rect of this window CDC* pDC = GetDC(); //get drawing context PlayEnhMetaFile(pDC->m_hDC, hemf, &rc); //draw it DeleteEnhMetafile(hemf); } }
NULL, you need to free the returned meta file with DeleteEnhMetafile Win32 API.NULL.| bool SaveMultiPageTiff | ( | string | strFileName, | |
| long | nPageHeight | |||
| ) |
Save the snap's resulting image to multi-page TIFF file after a snap function succeeds.
If the resulting image's height is greater than nPageHeight, it will be split into several pages and added to a multi-page TIFF file.
| strFileName | The image file name. | |
| nPageHeight | Max height of a TIFF page. |
true, else false.| void GetImageSize | ( | long * | pWidth, | |
| long * | pHeight | |||
| ) |
Get the size of resulting image.
Call this function after a snap function succeeds.
| pWidth | A pointer to retrieve image width. | |
| pHeight | A pointer to retrieve image height. |
| void CreatePDF | ( | string | strFileName | ) |
Create a PDF document for adding snapshot image to.
| strFileName | Filename of the PDF document |
ISnapShooter2 snap; if (snap.SnapUrl("SiteOne.com") == HCR_SUCCESS) snap.SaveImage("onepage.pdf");
ISnapShooter2 snap; snap.CreatePDF("twopages.pdf"); //create a pdf file if (snap.SnapUrl("SiteOne.com") == HCR_SUCCESS) snap.AddImageToPDF(); //add snap result to pdf as a new page if (snap.SnapUrl("SiteTwo.com") == HCR_SUCCESS) snap.AddImageToPDF(); //add snap result to pdf as a new page snap.ClosePDF(); //save & close the created pdf
| void AddImageToPDF | ( | ) |
Add snap result to the PDF document created by CreatePDF() as a new page after a successful snap.
| void ClosePDF | ( | ) |
Save and close the PDF document created by CreatePDF().
| void CreateTiff | ( | string | strFileName | ) |
Create a Tiff document for adding snapshot image to.
This function operates like CreatePDF() except that it handles TIFF document.
| strFileName | Filename of the TIFF document |
ISnapShooter2 snap; if (snap.SnapUrl("SiteOne.com") == HCR_SUCCESS) snap.SaveImage("onepage.tif");
ISnapShooter2 snap; snap.CreateTiff("twopages.tif"); //create a TIFF file if (snap.SnapUrl("SiteOne.com") == HCR_SUCCESS) snap.AddImageToTiff(false); //add snap result to TIFF as a new page if (snap.SnapUrl("SiteTwo.com") == HCR_SUCCESS) snap.AddImageToTiff(true); //add snap result to TIFF as a new page snap.CloseTiff(); //close the created TIFF file
| void AddImageToTiff | ( | bool | bLastPage | ) |
Add snap result to the TIFF document created by CreateTiff() as a new page after a successful snap.
| void CloseTiff | ( | ) |
Close the Tiff document created by CreateTiff().
| long GetTimeOut | ( | ) |
Get the time out value in milliseconds for snap functions.
TimeOut property can be used to avoid hang.
TimeOut value in milliseconds. The default TimeOut value is 30000. | void SetTimeOut | ( | long | nTimeOut | ) |
Set the time out value in milliseconds for snap functions.
TimeOut property can be used to avoid hang.
| nTimeOut | TimeOut value in milliseconds. A negative value or zero indicates infinite. |
TimeOut milliseconds from its startup. You can call SetTimeOut() with nTimeOut=-1 to disable TimeOut, then snap functions will not return until it completes or fails. | long GetDelayTime | ( | ) |
Get the time value in milliseconds to wait for after a html document is downloaded.
Sometimes, a web page contains ActiveX or java applet, which takes time to initialize.
| void SetDelayTime | ( | long | nDelayTime | ) |
Set the time value in milliseconds to wait for after a html document is downloaded.
Sometimes, a web page contains ActiveX or java applet, which takes time to initialize.
| nDelayTime | Time value in milliseconds to wait for after a html document is downloaded. Default value is 1000 |
| float GetZoomRatio | ( | ) |
Get the zoom ratio of the html page when taking snapshot.
Default value is 1.0.
| void SetZoomRatio | ( | float | fZoomRatio | ) |
Set the zoom ratio of the html page when taking snapshot.
Default value is 1.0.
| fZoomRatio | A float value indicates the zoom ratio. |
| bool GetActiveXEnabled | ( | ) |
Get if ActiveX is enabled (visible) on a web page.
Default value is TRUE.
| void SetActiveXEnabled | ( | bool | bEnabled | ) |
Set if ActiveX is enabled (visible) on a web page.
Default value is TRUE.
If ActiveXEnabled is set to FALSE, then ActiveX controls on a web page will not be downloaded, which is useful to decrease download time, so as to decrease snap time.
| bool GetImageEnabled | ( | ) |
| void SetImageEnabled | ( | bool | bEnabled | ) |
Set if images are enabled (visible) on a web page.
Default value is TRUE.
If ImageEnabled is set to FALSE, images on a web page will not be downloaded and displayed, which is useful to decrease downloading time, so as to decrease snap time.
| bool GetJavaEnabled | ( | ) |
| void SetJavaEnabled | ( | bool | bEnabled | ) |
Set if java applets are enabled on a web page.
Default value is TRUE.
If JavaEnabled is set to FALSE, java applets on a web page will not be downloaded, which is useful to decrease downloading time, so as to decrease snap time.
| bool GetScriptEnabled | ( | ) |
Get if scripts are enabled (can be executed) on a web page.
Default value is TRUE.
| void SetScriptEnabled | ( | bool | bEnabled | ) |
Set if scripts are enabled (can be executed) on a web page.
Default value is TRUE.
ScriptEnabled is set to FALSE, No scripts on a web page will be executed. This may lead to a disordered image. | bool GetVideoEnabled | ( | ) |
| void SetVideoEnabled | ( | bool | bEnabled | ) |
Set if videos are enabled (visible) on a web page.
Default value is TRUE.
If VideoEnabled is set to FALSE, videos on a web page will not be downloaded and displayed, which is useful to decrease downloading time, so as to decrease snap time.
| void GetMinBrowserSize | ( | long * | pWidth, | |
| long * | pHeight | |||
| ) |
Get the minimum size of the hidden web browser window.
| pWidth | A pointer to retrieve minimum width in pixels. Default value is 800. | |
| pHeight | A pointer to retrieve minimum height in pixels. Default value is 600. |
| void SetMinBrowserSize | ( | long | nWidth, | |
| long | nHeight | |||
| ) |
Set the minimum size of the hidden web browser window.
| nWidth | Minimum width in pixels. Default value is 800. | |
| nHeight | Minimum height in pixels. Default value is 600. |
MAX( MinBrowserSize, WebPageSize ). MinBrowserSize to (0, 0) will make MinBrowserSize take no effects.