1e41f4b71Sopenharmony_ci# Previewing PDF Files
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Web** component provides the capability of previewing PDF files on web pages. The [src](../reference/apis-arkweb/ts-basic-components-web.md#web) parameter of the **Web** component and the [loadUrl()](../reference/apis-arkweb/js-apis-webview.md#loadurl) API can be used to transfer and load PDF files on the application side. Based on the source of PDF files, there are three common scenarios: loading online PDF files, loading local PDF files, and loading in-application resource PDF files.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciWhen preview and load an online PDF file, you need to configure the [ohos.permission.INTERNET](../security/AccessToken/declare-permissions.md) to obtain network access permission.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciIn the following example, the online PDF file **www.example.com/test.pdf** to be loaded by default is specified when the **Web** component is created. Replace the example address with the accessible address when you use it.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci```ts
11e41f4b71Sopenharmony_ci// xxx.ets
12e41f4b71Sopenharmony_ciimport { webview } from '@kit.ArkWeb';
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci@Entry
15e41f4b71Sopenharmony_ci@Component
16e41f4b71Sopenharmony_cistruct WebComponent {
17e41f4b71Sopenharmony_ci  controller: webview.WebviewController = new webview.WebviewController();
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci  build() {
20e41f4b71Sopenharmony_ci    Column() {
21e41f4b71Sopenharmony_ci      Web({ 
22e41f4b71Sopenharmony_ci      	src: 
23e41f4b71Sopenharmony_ci      	"https://www.example.com/test.pdf",                                    // Method 1: Load online PDF Files.
24e41f4b71Sopenharmony_ci      	// "file://" + getContext(this).filesDir + "/test.pdf", // Method 2: Load the PDF files from the local application sandbox.
25e41f4b71Sopenharmony_ci      	// "resource://rawfile/test.pdf",                                              // Method 3: Load the PDF files from application resource 
26e41f4b71Sopenharmony_ci      	// $rawfile('test.pdf'),                                                              // Method 4: Load the PDF files from application resource 
27e41f4b71Sopenharmony_ci      	controller: this.controller 
28e41f4b71Sopenharmony_ci      })
29e41f4b71Sopenharmony_ci        .domStorageAccess(true)
30e41f4b71Sopenharmony_ci    }
31e41f4b71Sopenharmony_ci  }
32e41f4b71Sopenharmony_ci}
33e41f4b71Sopenharmony_ci```
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ciIn the preceding example, whether the side navigation bar is expanded on the PDF preview page is recorded based on user operations using **window.localStorage**. Therefore, you need to enable the DOM Storage API using [domStorageAccess](../reference/apis-arkweb/ts-basic-components-web.md#domstorageaccess).
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci  ```
38e41f4b71Sopenharmony_ci  Web().domStorageAccesss(true)
39e41f4b71Sopenharmony_ci  ```
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciSpecify the PDF file to be loaded by default when the **Web **component is created. When the default PDF file is loaded, if you want to change the PDF file displayed on the **Web** component, you can call the [loadUrl()](../reference/apis-arkweb/js-apis-webview.md#loadurl) API to load the specified PDF file. The address of the first parameter variable *src* of [Web](../reference/apis-arkweb/ts-basic-components-web.md#web) component cannot be dynamically changed through a state variable (for example, *@State*). To change the address, reload the variable using [loadUrl()](../reference/apis-arkweb/js-apis-webview.md#loadurl).
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciThere are three scenarios for loading and previewing PDF files:
44e41f4b71Sopenharmony_ci- Preview and load an online PDF file:
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci  ```
47e41f4b71Sopenharmony_ci  Web({ 
48e41f4b71Sopenharmony_ci    src: "https://www.example.com/test.pdf",
49e41f4b71Sopenharmony_ci    controller: this.controller 
50e41f4b71Sopenharmony_ci  })
51e41f4b71Sopenharmony_ci    .domStorageAccess(true)
52e41f4b71Sopenharmony_ci  ```
53e41f4b71Sopenharmony_ci- Preview and load a  PDF file from the application sandbox:
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci  ```
56e41f4b71Sopenharmony_ci  Web({ 
57e41f4b71Sopenharmony_ci    src: "file://" + getContext(this).filesDir + "/test.pdf",
58e41f4b71Sopenharmony_ci    controller: this.controller 
59e41f4b71Sopenharmony_ci  })
60e41f4b71Sopenharmony_ci    .domStorageAccess(true)
61e41f4b71Sopenharmony_ci  ```
62e41f4b71Sopenharmony_ci- Preview and load a PDF file from the application resource in either of the following ways: The preview parameters described below cannot be specified in the **$rawfile('test.pdf')** format.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci  ```
65e41f4b71Sopenharmony_ci  Web({ 
66e41f4b71Sopenharmony_ci    src: "resource://rawfile/test.pdf" // or $rawfile ('test.pdf')
67e41f4b71Sopenharmony_ci    controller: this.controller 
68e41f4b71Sopenharmony_ci  })
69e41f4b71Sopenharmony_ci    .domStorageAccess(true)
70e41f4b71Sopenharmony_ci  ```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciIn addition, you can set PDF file preview parameters to control the page status when the page is opened.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciCurrently, the following parameters are supported: 
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| Syntax	| Description |
77e41f4b71Sopenharmony_ci| --------- | ---------- |
78e41f4b71Sopenharmony_ci| nameddest=destination 	|  Specifies a naming destination in a PDF file. |
79e41f4b71Sopenharmony_ci| page=pagenum 	| Specifies the page number with an integer. The **pagenum** value of the first page of the file is **1**.|
80e41f4b71Sopenharmony_ci| zoom=scale    zoom=scale,left,top	| Sets the scaling and scrolling coefficients using a floating or integer value. For example, the scaling value **100** indicates 100%. The left and up scrolling values are located in the coordinate system. **0,0** indicates the upper left corner of the visible page, regardless of how the document is rotated. |
81e41f4b71Sopenharmony_ci| toolbar=1 \| 0 	| Opens or closes the top toolbar. |
82e41f4b71Sopenharmony_ci| navpanes=1 \| 0 	| Opens or closes the side navigation pane. |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciURL Example 
86e41f4b71Sopenharmony_ci```
87e41f4b71Sopenharmony_cihttps://example.com/test.pdf#Chapter6  
88e41f4b71Sopenharmony_cihttps://example.com/test.pdf#page=3  
89e41f4b71Sopenharmony_cihttps://example.com/test.pdf#zoom=50  
90e41f4b71Sopenharmony_cihttps://example.com/test.pdf#page=3&zoom=200,250,100  
91e41f4b71Sopenharmony_cihttps://example.com/test.pdf#toolbar=0  
92e41f4b71Sopenharmony_cihttps://example.com/test.pdf#navpanes=0  
93e41f4b71Sopenharmony_ci```
94