Created
March 24, 2021 17:20
-
-
Save krishnaanaril/7f76df427ddf30536eb76f2b48894452 to your computer and use it in GitHub Desktop.
Snippet for generating image from a html element using puppeteer-sharp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var t = Task.Run(async () => | |
{ | |
_ = await new BrowserFetcher().DownloadAsync("848005"); | |
var url = "file:///C:/KrishnaMohan/Learning/tailwind/tailwind-npm/banner/banner.html"; | |
var outputFile = ".\\somepage02.png"; | |
var browser = await Puppeteer.LaunchAsync(new LaunchOptions | |
{ | |
Headless = true, | |
DefaultViewport = | |
{ | |
Width = 1920, | |
Height = 800, | |
DeviceScaleFactor = 1 | |
} | |
}); | |
var page = await browser.NewPageAsync(); | |
await page.GoToAsync(url); | |
var element = await page.QuerySelectorAsync(".container"); | |
await element.ScreenshotAsync(outputFile); | |
}); | |
t.Wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment