screenshotmachine vb
1.0.0
本demo展示如何使用Visual Basic程式語言呼叫線上截圖機API。
首先,您需要在 www.screenshotmachine.com 網站上建立免費/進階帳戶。註冊後,您將在您的用戶個人資料中看到您的客戶金鑰。這裡還保留了秘密短語。當您的 API 呼叫是從公開網站呼叫時,請始終使用秘密短語。
在腳本中設定您的客戶金鑰和秘密短語(如果需要):
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
設定附加選項以滿足您的需求:
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website screenshot API guide for more details
options.Add( "dimension" , "1366x768" ) REM Or "1366xfull" For full length screenshot
options.Add( "device" , "desktop" )
options.Add( "format" , "png" )
options.Add( "cacheLimit" , "0" )
options.Add( "delay" , "200" )
options.Add( "zoom" , "100" )
有關選項的更多資訊可以在我們的網站螢幕截圖 API 中找到。
Imports System.Net
Public Class Client
Public Shared Sub Main(args() As String )
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website screenshot API guide for more details
options.Add( "dimension" , "1366x768" ) REM or "1366xfull" for full length screenshot
options.Add( "device" , "desktop" )
options.Add( "format" , "png" )
options.Add( "cacheLimit" , "0" )
options.Add( "delay" , "200" )
options.Add( "zoom" , "100" )
Dim sm As ScreenshotMachine = New ScreenshotMachine(customerKey, secretPhrase)
Dim apiUrl As String = sm.GenerateScreenshotApiUrl(options)
REM use final apiUrl where needed
Console.WriteLine(apiUrl)
End Sub
End Class
產生的apiUrl
連結可以放置在<img>
標記中或稍後在您的業務邏輯中使用。
如果您需要將擷取的螢幕截圖儲存為影像,只需呼叫:
Dim apiUrl As String = sm.GenerateScreenshotApiUrl(options)
REM or save screenshot directly
Dim client As New WebClient()
Dim output As String = "output.png"
client.DownloadFile(apiUrl, output)
Console.WriteLine( "Screenshot saved as " + output)
擷取的螢幕截圖將作為output.png
檔案保存在目前目錄中。
設定 PDF 選項:
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website to PDF API guide for more details
options.Add( "paper" , "letter" )
options.Add( "orientation" , "portrait" )
options.Add( "media" , "print" )
options.Add( "bg" , "nobg" )
options.Add( "delay" , "2000" )
options.Add( "scale" , "50" )
有關選項的更多資訊可以在我們的 PDF API 網站中找到。
Imports System.Net
Public Class ClientPdf
Public Shared Sub Main(args() As String )
Dim customerKey As String = "PUT_YOUR_CUSTOMER_KEY_HERE"
Dim secretPhrase As String = "" REM leave secret phrase empty, If Not needed
Dim options As New Dictionary( Of String , String )
REM mandatory parameter
options.Add( "url" , "https://www.google.com" )
REM all next parameters are optional, see our website to PDF API guide for more details
options.Add( "paper" , "letter" )
options.Add( "orientation" , "portrait" )
options.Add( "media" , "print" )
options.Add( "bg" , "nobg" )
options.Add( "delay" , "2000" )
options.Add( "scale" , "50" )
Dim sm As ScreenshotMachine = New ScreenshotMachine(customerKey, secretPhrase)
Dim pdfApiUrl As String = sm.GeneratePdfApiUrl(options)
REM save PDF file
Dim client As New WebClient()
Dim output As String = "output.pdf"
client.DownloadFile(pdfApiUrl, output)
Console.WriteLine( "PDF saved as " + output)
End Sub
End Class
捕獲的 PDF 將作為output.pdf
文件保存在當前目錄中。
麻省理工學院許可證 (MIT)