The issue that you are hitting is that you instantiate the web browser, and immediately attempt to call PrintToPdf. At this point, the browser is still loading. The browser exposes an
[
^]IsBrowserInitializedChanged event that is fired when the browser is initialized. A word of caution - this event is raised on a CEF thread, so you may need to dispatch back to the main thread if you are using this in a screen based application.
Note, as you are attempting to print the current page to a PDF, you need to wait for the page to finish loading. You need to handle this event
LoadingStateChanged Event[
^] which is fired twice, the first time when the page starts loading, and then a second time when the page load completes. There is every possibility that the load page could fail, so you need to validate that it has completed successfully before you actually attempt to print the page out.