微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在使用 CefSharp 将页面打印为 Pdf 之前等待页面加载

如何解决如何在使用 CefSharp 将页面打印为 Pdf 之前等待页面加载

我正在尝试使用 CefSharp 以 pdf 格式导出页面,但即使在线程睡眠之后我也收到未完全加载的页面,是否有任何正确的方法可以在导出页面之前等待页面加载?

    public static int Main(string[] args)
    {
        ///init cefbrowser and pass page for it///
        
        browser.LoadingStateChanged += browserLoadingStateChanged;

        ///close sefbrowser ///
    }

    private static async void browserLoadingStateChanged(object sender,LoadingStateChangedEventArgs e)
    {
        // Check to see if loading is complete - this event is called twice,one when loading starts
        // second time when it's finished
        // (rather than an iframe within the main frame).
        if (!e.IsLoading)
        {
            // Remove the load event handler,because we only want one snapshot of the initial page.
            browser.LoadingStateChanged -= browserLoadingStateChanged;
            Console.WriteLine("Wait");
            Thread.Sleep(12000);
            //Give the browser a little time to render
            // Wait for the screenshot to be taken.
            Console.WriteLine("print");
            await browser.PrintToPdfAsync("D:\\test.pdf");
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。