[PrintToPdfStream] This example prints the Pdf data of the current page to a stream.
| 1393 | //! [PrintToPdfStream] |
| 1394 | // This example prints the Pdf data of the current page to a stream. |
| 1395 | bool AppWindow::PrintToPdfStream() |
| 1396 | { |
| 1397 | wil::com_ptr<ICoreWebView2_16> webView2_16; |
| 1398 | CHECK_FAILURE(m_webView->QueryInterface(IID_PPV_ARGS(&webView2_16))); |
| 1399 | |
| 1400 | wil::unique_cotaskmem_string title; |
| 1401 | CHECK_FAILURE(m_webView->get_DocumentTitle(&title)); |
| 1402 | |
| 1403 | // Passing nullptr for `ICoreWebView2PrintSettings` results in default print settings used. |
| 1404 | CHECK_FAILURE(webView2_16->PrintToPdfStream( |
| 1405 | nullptr, |
| 1406 | Callback<ICoreWebView2PrintToPdfStreamCompletedHandler>( |
| 1407 | [title = std::move(title), this](HRESULT errorCode, IStream* pdfData) -> HRESULT |
| 1408 | { |
| 1409 | DisplayPdfDataInPrintDialog(pdfData); |
| 1410 | |
| 1411 | std::wstring message = |
| 1412 | L"Printing " + std::wstring(title.get()) + L" document to PDF Stream " + |
| 1413 | ((errorCode == S_OK && pdfData != nullptr) ? L"succedded" : L"failed"); |
| 1414 | |
| 1415 | AsyncMessageBox(message, L"Print to PDF Stream"); |
| 1416 | |
| 1417 | return S_OK; |
| 1418 | }) |
| 1419 | .Get())); |
| 1420 | return true; |
| 1421 | } |
| 1422 | //! [PrintToPdfStream] |
| 1423 | |
| 1424 | //! [Start] |
nothing calls this directly
no test coverage detected