Manual:
SnapUrl(String strUrl, String
strPicFile);
Description: the main function to convert html to image
strUrl: The URL of the web page
to be taken snapshot.
strPicFile: The local image file to be
saved. It should be a valid file name. For example, c:\1.jpg or c:\1.bmp
etc. Currently the component supports jpg, bmp, gif, tiff and png format.
It will convert html to image in the format given by the file
extension.
For advanced users: If
you don't want to save the image to file, set strPicFile to "*". For
example,
snap.SnapUrl("www.example.com",
"*") Handle hBmp =
snap.GetBitmapHandle()
You can get the bitmap handle in memory when
the html is successfully converted to image. SnapHtmlString(String strHtml,
String strPicFile); Description: strUrl: A html string strPicFile: The local
image file to be saved.
SetRenderEngine(LONG engine)
Description: 1 is for firefox rendering engine, 0 for IE rendering engine (default)
Htmlsnapshot now supports using firefox to render html to image on Windows. The steps are:
1. Install Htmlsnapshot
2. Install Firefox Addon for HtmlSnapshot
3. In your code, call SetRenderEngine to enable firefox like this:
snap.SetRenderEngine 1
Note, Firefox engine doesn't supports converting html to vector image.
GetThumbnailImage(String strInputFile, String
strOutputFile, Long cx, Long cy, Long bRemainRatio) Description: strInputFile : The input image
file strOutputFile : The thumbnail
image file to be saved cx, cy : The dimension of the
thumbnail image. bRemainRatio: If bRemainRation is
0, the thumbnail image will be exactly the size of cx, cy; else then remain the
original image's aspect ratio. ReduceColor(String
strInputFile, String strOutputFile, Long nColors) Description: Reduce the
color number in input image. nColors is in
[8-256]. MakeGrayImage(String strInputFile, String strOutputFile,
Long bGrayOrBW) Description: convert a
color image to gray or black white only. If bGrayOrBW = 0 then, the
result image is black white only, else it is gray. SetCode(String strCode) Description: strCode : Set the registration
code to eliminate the limitation in trial version. SetTimeOut(Long nTimeOut) Description: nTimeOut : The time out value in
milliseconds for SnapUrl. Using this to avoid hang. The default TimeOut value
is 30000 SetDelayTime(Long nDelayTime) Description: nDelayTime: The time value
in milliseconds to wait after a html document is
downloaded. Sometimes, a page contains ActiveX like flash, which takes
some time to initialize. This method can be used to control the timing to
capture the content of the dynamic embeded objects. Default nDelayTime
value is 1000.
SetProxy(String proxyHost, String userName, String passWord, LONG autoConfig)
Description: allow to set custom proxy for IE
ProxyHost: could be an IP:port pair. Like this 127.0.0.1 or 127.0.0.1:3128
Username: username required by the proxy server
passWord: password required by the proxy server
autoConfig: indicate if the proxy is an automatic configuration script. 0 is for no, 1 is for yes.
Example:
snap.SetProxy "www.proxyserver.com", "username", "password", 0
SetAsync(BOOL bAsync)
Description: bAsync : If set to True, SnapUrl
function will work asynchronously, which means it will return immediately
without waiting for the results. Application can use the event to determine if
the operation is done. If set to False, SnapUrl will wait until the operation
is done or the time is out.
EnableActiveX(BOOL bEnable) Description: bEnable : Determine if ActiveX is
enabled on the html page EnableJava(BOOL bEnable) Description: bEnable : Determine if Java is
enabled on the html page EnableScript(BOOL bEnable) Description: bEnable : Determine if Script is
enabled on the html page SetSnapDimension(long cx, long
cy) Description: Set the width and
height of the web browser window. The browser window size will affect the html
document size in some way. EnableSnapDimensionAsImageSize(BOOL
bVal) Description: Force the captured
image size to be the dimension set by SetSnapDimension. If the dimension is
larger than that of the html document, the gap will be filled with background
color of the page. The default value is FALSE.
SetPostData(String
postData) Description: Set the data to be
posted to the URL. Use this function for some urls protected by forms.
SetJPEGQuality (long n) Description: Set the quality of
JPEG Compression. n is between 0 and 100 SetDither(long n) Description: Set the dither method when converting to 1bpp image. 0: None; 1: Floyd dithering; 2:Ordered dithering
SetTIFFEncoder(long
n) Description: Set the
compression method of TIFF image. 0: LZW; 1: CCITT3; 2:CCITT4; 3: RLE; 5:
None. SetThreshold(long
n) Description: Set the
threshold value (0-255) when converting image
to monochrome. StringArray GetLinks() Description: Return an array of
links on the webpage. Call this function after SnapUrl
StringArray GetFrames() Description: Return an array of
frame urls on the webpage. Call this function after SnapUrl
String GetTitle() Description: Return the title of
the webpage. Call this function after SnapUrl
String GetSource() Description: Return the html
source of the webpage. Call this function after SnapUrl
String GetText() Description: Return the
text of the webpage. Call this function after SnapUrl LONG GetImageWidth() Description: Return
the image width. Call this function after SnapUrl.
LONG GetImageHeight() Description: Return
the image width. Call this function after SnapUrl.
HBITMAP GetBitmapHandle()
Description: Return
the bitmap handle to the image (the whole image or the clip
rect) in memory. Call this function after SnapUrl. Note: you need to
free the bitmap handle with DeleteObject Win32 API.
SetClipRect(long x, long y, long
w, long h) Description: Set clip rect to
the image. Call this function after SnapUrl. This method
affects GetBitmapHandle and SaveImage. Call this function if you want to
get/save portion of the image. SetClipRect(0, 0, 0, 0) will clear the clip
rect. SaveImage(String
strPicFile) Description: Save the clip rect
in the image to file . Call this function after SnapUrl.
SaveMultipageTiff(String
strPicFile, LONG Height)
Description: Save the clip rect
in the image to multiple page TIFF file. The height is the page height of the TIFF file. See Demo\VBScript\multipage-tifftest.vbs
SetSmoothingMode(LONG nSmooth)
Description: Set smoothing mode of resizing. Could have below values.
HtmlSnapSmoothingModeDefault = 0,
HtmlSnapSmoothingModeHighSpeed = 1,
HtmlSnapSmoothingModeHighQuality = 2,
HtmlSnapSmoothingModeNone = 3,
HtmlSnapSmoothingModeAntiAlias = 4
SetInterpolationMode(LONG nInterpolation)
Description: Set interpolation mode of resizing. Could have below values.
HtmlSnapInterpolationModeDefault = 0,
HtmlSnapInterpolationModeLowQuality = 1,
HtmlSnapInterpolationModeHighQuality = 2,
HtmlSnapInterpolationModeBilinear = 3,
HtmlSnapInterpolationModeBicubic = 4,
HtmlSnapInterpolationModeNearestNeighbor = 5,
HtmlSnapInterpolationModeHighQualityBilinear = 6,
HtmlSnapInterpolationModeHighQualityBicubic = 7
String
GetCookie()
Description: Get cookie of
current URL. Call this function after SnapUrl. SetCookie(String
strURL, String strName, String strData) Description: Set cookie for the
URL. GetCookie2(String
strURL) Description: Get cookie for the
URL. IDispatch
GetHtmlDocument() Description: Get html document's
IDispatch interface. Call this after calling SnapUrl. With this method,
you can access the DOM tree of html document, and even change the document. ReSnap Description: Capture the
image again after calling SnapUrl. This function will refresh the image
in the memory, then you can call SaveImage or GetBitmapHandle to get the new
image.
SetZoom(Double zoomRatio)
Description: Set the zoom ratio of the html page when doing snapshot. This can result in image with larger DPI.
zoomRatio: the zoon ratio of the page. it is between 1 and 5
SetDPI(LONG xDPI, LONG yDPI)
Description: Set the image resolution on x, y axis. Some image formats like TIFF support DPI information.
GetImageBytes(String imageType)
Description: Get the in memory compressed image bytes. In this way, you can convert html to image in memory. See blob.vbs for detail
imageType: the file format such as *.jpg, *.gif etc
GetThumbImageBytes(String imageType, LONG cx, LONG cy, LONG bRemainRatio)
Description: Get the in memory compressed thumbnail image bytes. In this way, you can get the thumbnail images of the html page in memory. See blob.vbs for detail
imageType: the file format such as *.jpg, *.gif etc
cx, cy: the desired width and height of the thumbnail
bRemainRatio: if nozero, the thumbnail image will has the same aspect ratio with large image.
LONG GetErrorCode
Description: Return the status code of last snap action. See OnStatus section below for the meaning of the error code
Clear
Description: Release the resources allocated when doing SnapUrl or SnapHtmlString.
SetLogonUser(String userName, String domainName, String passwd)
Description: This method will set the user name and password. SnapUrl will do impersonation with the specified user name and convert html to image under that user account. This method is useful for using html snapshot in IIS with ASP or ASP.Net etc.
SetForceSnap(LONG bForceSnap)
Description: This method will make the component to capture the browser image even the time is out in some case.
SnapWebBrowser(WebBrowswer browserObject, String strFile)
Description: This method will capture the content in existing web browser window into image files like jpg, tiff, png, gif etc. browserObject is a IDispatch pointer to the browser object. strFile is similar to the file name in calling SnapUrl
SetSnapUrlWorkingMode(LONG nMethod)
Description: Set the working mode of SnapUrl. 0 is the normal method. 1 is to use the method as SnapWebBrowser
DrawTxt(LONG x, LONG y, String strText, LONG nFontSize, LONG nColor, String strFontName)
Description: draw watermark text on the snapped image at the specificed position with the given size, color and font
SetAuthUserAndPasswd(String userName, String password)
Description: set http authentication user name and password so that SnapUrl can bypass the autentication dialog automacically.
IsGoodUrlForSnap(String strUrl)
Description: return 1 if the strURL's content type is text/html, else return 0
Events:
void OnProgress(LONG nPos) Description: This event tells the downloading progress of the
webpage by the Web Browser. Just like what is seen in the Internet Explorer
itself. nPos is between 0 and 100. void OnStatus(String strStatus, LONG nCode) Description: This event tells the state of the HTML Snapshot
control. strStatus is the string description of the state. nCode is the state
code, it can has the following value: 0: The normal state. 1: The snapshot is successfully taken. -1: Fail to take the snapshot of the page. -2: Fail to save to file. -3: Fail to open the URL.
-4: Time is out before taking a snapshot
Applications can use the above code to do
correspondent actions. Redistribution: The files that need to redistribute HTML Snapshot
Component with applications are:
HtmlSnap2.dll: the component
itself. It needs to be registered as ActiveX by regsvr32 or setup program.
gdiplus.dll: gdiplus.dll: the GDI+ runtime from Microsoft. It may be needed on the Windows version lower
than Windows XP.
Once registered, you can
redistribute HtmlSnapshot ActiveX royalty-freely. (For details about
redistribution, please refer to the license agreement). |