MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Samples / PrintToPdfStream

Method PrintToPdfStream

SampleApps/WebView2APISample/AppWindow.cpp:1395–1421  ·  view source on GitHub ↗

[PrintToPdfStream] This example prints the Pdf data of the current page to a stream.

Source from the content-addressed store, hash-verified

1393//! [PrintToPdfStream]
1394// This example prints the Pdf data of the current page to a stream.
1395bool 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]

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected