コード例 #1
0
        /// <summary>
        /// Creates a PageRenderer asynchronously, and fires the 'onReady' parameter when the PageRenderer is ready to render pages.
        /// Due to the fact the PageRenderer uses PuppeteerSharp in the background, it's possible that there may be a significant
        /// delay when using this method for the first time. Chrome has to be available in the current application's path, and if it
        /// is not, it will be downloaded. Subsequent calls of 'CreateAsync' will be much faster.
        /// </summary>
        /// <param name="onReady">A callback action which fires when the PageRenderer is ready.</param>
        /// <returns>The PageRenderer object.</returns>
        public async static Task <PageRenderer> CreateAsync(Action onReady, string browserPath = "")
        {
            if (string.IsNullOrEmpty(browserPath))
            {
                await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
            }
            else
            {
                await new BrowserFetcher(new BrowserFetcherOptions()
                {
                    Path = browserPath
                }).DownloadAsync(BrowserFetcher.DefaultRevision);
            }

            var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = true
            });

            var page = await browser.NewPageAsync();

            await page.SetRequestInterceptionAsync(true);

            PageRenderer pR = new PageRenderer(browser, page, onReady);

            return(pR);
        }
コード例 #2
0
ファイル: PageRenderer.cs プロジェクト: Pody2015/PDF2IMG.NET
        /// <summary>
        /// Creates a PageRenderer asynchronously, and fires the 'onReady' parameter when the PageRenderer is ready to render pages.
        /// Due to the fact the PageRenderer uses PuppeteerSharp in the background, it's possible that there may be a significant
        /// delay when using this method for the first time. Chrome has to be available in the current application's path, and if it
        /// is not, it will be downloaded. Subsequent calls of 'CreateAsync' will be much faster.
        /// </summary>
        /// <param name="onReady">A callback action which fires when the PageRenderer is ready.</param>
        /// <returns>The PageRenderer object.</returns>
        public async static Task <PageRenderer> CreateAsync(Action onReady)
        {
            await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);

            var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless = true
            });

            var page = await browser.NewPageAsync();

            await page.SetRequestInterceptionAsync(true);

            PageRenderer pR = new PageRenderer(browser, page, onReady);

            return(pR);
        }