Skip to content

Commit 7f3fb50

Browse files
author
QZQ
authored
Merge pull request #1467 from MicrosoftEdge/api-pdf-toolbar-customization
API Review: HiddenPdfToolbarItems.md
2 parents 623787d + 172c6ec commit 7f3fb50

1 file changed

Lines changed: 147 additions & 0 deletions

File tree

specs/HiddenPdfToolbarItems.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Background
2+
When opening a PDF file in Edge, there will be a toolbar at the top. The toolbar provides functionality like print, save and adding annotations.
3+
This PDF viewer is also available in WebView2. And we provide this new API to enable end developers to customize the PDF toolbar.
4+
5+
6+
# Description
7+
We add a new `HiddenPdfToolbarItems` property in `CoreWebView2Settings`. This API allows end developers to hide buttons on the PDF toolbar.
8+
Currently, this API can hide the _save button_, _save as button_, and _print button_.
9+
By default, `HiddenPdfToolbarItems` is equal to `None` which means no button will be hidden.
10+
11+
# Examples
12+
## C++
13+
14+
```cpp
15+
wil::com_ptr<ICoreWebView2> webView;
16+
void SettingsComponent::ToggleHidePdfToolbarButtons()
17+
{
18+
// Get webView's current settings
19+
wil::com_ptr<ICoreWebView2Settings> coreWebView2Settings;
20+
CHECK_FAILURE(webView->get_Settings(&coreWebView2Settings));
21+
22+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS hiddenPdfToolbarItems;
23+
CHECK_FAILURE(coreWebView2Settings->get_HiddenPdfToolbarItems(&hiddenPdfToolbarItems));
24+
25+
if (hiddenPdfToolbarItems == COREWEBVIEW2_PDF_TOOLBAR_ITEMS::COREWEBVIEW2_PDF_TOOLBAR_ITEMS_NONE)
26+
{
27+
CHECK_FAILURE(coreWebView2Settings->put_HiddenPdfToolbarItems(
28+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS::COREWEBVIEW2_PDF_TOOLBAR_ITEMS_PRINT |
29+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS::COREWEBVIEW2_PDF_TOOLBAR_ITEMS_SAVE));
30+
}
31+
else
32+
{
33+
CHECK_FAILURE(coreWebView2Settings->put_HiddenPdfToolbarItems(
34+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS::COREWEBVIEW2_PDF_TOOLBAR_ITEMS_NONE));
35+
}
36+
}
37+
```
38+
39+
## C#
40+
```c#
41+
private WebView2 _webView;
42+
void ToggleHidePdfToolbarButtons(object target, ExecutedRoutedEventArgs e)
43+
{
44+
var coreWebView2Settings = _webView.CoreWebView2.Settings;
45+
if(coreWebView2Settings.HiddenPdfToolbarItems.HasFlag(CoreWebView2PdfToolbarItems.Save | CoreWebView2PdfToolbarItems.Print))
46+
{
47+
WebViewSettings.HiddenPdfToolbarItems = CoreWebView2PdfToolbarItems.None;
48+
}
49+
else
50+
{
51+
WebViewSettings.HiddenPdfToolbarItems = CoreWebView2PdfToolbarItems.Save;
52+
}
53+
}
54+
```
55+
56+
# API Notes
57+
See [API Details](#api-details) section below for API reference.
58+
59+
# API Details
60+
## Win32 C++
61+
```c#
62+
/// Specifies the PDF toolbar item types used for the `ICoreWebView2StagingSettings::put_HiddenPdfToolbarItems` method.
63+
[v1_enum]
64+
typedef enum COREWEBVIEW2_PDF_TOOLBAR_ITEMS {
65+
66+
/// No item
67+
68+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS_NONE = 0x0,
69+
70+
/// The save button
71+
72+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS_SAVE = 0x0001,
73+
74+
/// The print button
75+
76+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS_PRINT = 0x0002,
77+
78+
/// The save as button
79+
80+
COREWEBVIEW2_PDF_TOOLBAR_ITEMS_SAVE_AS = 0x0004,
81+
82+
83+
} COREWEBVIEW2_PDF_TOOLBAR_ITEMS;
84+
cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(COREWEBVIEW2_PDF_TOOLBAR_ITEMS);")
85+
86+
[uuid(183e7052-1d03-43a0-ab99-98e043b66b39), object, pointer_default(unique)]
87+
interface ICoreWebView2Settings6 : ICoreWebView2Settings5 {
88+
/// `HiddenPdfToolbarItems` is used to customize the PDF toolbar items. By default, it is COREWEBVIEW2_PDF_TOOLBAR_ITEMS_NONE and so it displays all of the items.
89+
/// Changes to this property apply to all CoreWebView2s in the same environment and using the same profile.
90+
/// Changes to this setting apply only after the next navigation.
91+
/// \snippet SettingsComponent.cpp ToggleHidePdfToolbarItems
92+
93+
[propget] HRESULT HiddenPdfToolbarItems([out, retval] COREWEBVIEW2_PDF_TOOLBAR_ITEMS* hidden_pdf_toolbar_items);
94+
95+
[propput] HRESULT HiddenPdfToolbarItems([in] COREWEBVIEW2_PDF_TOOLBAR_ITEMS hidden_pdf_toolbar_items);
96+
}
97+
98+
```
99+
100+
101+
## .NET and WinRT
102+
103+
```c#
104+
namespace Microsoft.Web.WebView2.Core
105+
{
106+
//
107+
// Summary:
108+
// Specifies the PDF toolbar item types used for the <see cref="CoreWebView2Settings.HiddenPdfToolbarItems"/>
109+
[Flags]
110+
public enum CoreWebView2PdfToolbarItems
111+
{
112+
//
113+
// Summary:
114+
// No item. By default the `CoreWebView2Settings.HiddenPdfToolbarItems` equal to this value.
115+
None = 0,
116+
117+
//
118+
// Summary:
119+
// The save button on PDF toolbar.
120+
Save = 1,
121+
122+
//
123+
// Summary:
124+
// The print button on PDF toolbar.
125+
Print = 2,
126+
127+
//
128+
// Summary:
129+
// The save as button on PDF toolbar.
130+
SaveAs = 4
131+
}
132+
}
133+
134+
namespace Microsoft.Web.WebView2.Core
135+
{
136+
public partial class CoreWebView2Settings
137+
{
138+
//
139+
// Summary:
140+
// Used to customize the PDF toolbar items.
141+
//
142+
// Remarks:
143+
// By default, it equal to `CoreWebView2PdfToolbarItems.None` which means displays all of the items.
144+
public CoreWebView2PdfToolbarItems HiddenPdfToolbarItems { get; set; }
145+
}
146+
}
147+
```

0 commit comments

Comments
 (0)