|
1 | 1 | --- |
2 | 2 | layout: post |
3 | | -title: Save PDF To AAD in EJ2 ASP.NET MVC PDF Viewer | Syncfusion |
4 | | -description: Learn here all about How to Save Pdf To AAD in ASP.NET MVC PDF Viewer component of Syncfusion Essential JS 2 and more. |
| 3 | +title: Save PDF files to Azure Active Directory (AAD) in ASP.NET MVC PDF Viewer | Syncfusion |
| 4 | +description: Learn how to load and save PDF files with Azure Active Directory (AAD) using the Syncfusion ASP.NET MVC PDF Viewer component and a server-backed web service. |
5 | 5 | platform: document-processing |
6 | | -control: Save PDF To AAD |
| 6 | +control: PDF Viewer |
7 | 7 | publishingplatform: ASP.NET MVC |
8 | 8 | documentation: ug |
9 | 9 | --- |
10 | 10 |
|
11 | | -# Save PDF To Azure Active Directory in Viewer |
| 11 | +# Save PDF files to Azure Active Directory (AAD) |
12 | 12 |
|
13 | 13 | ### **Overview** |
14 | 14 |
|
15 | | -The Syncfusion PDF Viewer allows you to load and save PDF files directly from Azure Active Directory (AAD). Below are the steps to securely load and store PDF documents from and to AAD using the PDF Viewer. |
| 15 | +The ASP.NET MVC PDF Viewer component supports loading and saving PDF files with Azure Active Directory (AAD). The following steps describe how to securely load and store PDF documents using a server-backed web service. |
16 | 16 |
|
17 | | -### **Steps to Open the PDF File from Azure Active Directory** |
| 17 | +### **Step 1: Register an application in Azure Active Directory (AAD)** |
18 | 18 |
|
19 | | ---- |
20 | | - |
21 | | -### **Step 1: Register an Application in Azure Active Directory (AAD)** |
22 | | - |
23 | | -1. **Go to the Azure Portal**: |
| 19 | +1. **Go to the Azure portal**: |
24 | 20 | - Navigate to [Azure Portal](https://portal.azure.com). |
25 | 21 |
|
26 | | -2. **Register your Application**: |
| 22 | +2. **Register the application**: |
27 | 23 | - In the Azure portal, go to **Azure Active Directory** > **App registrations** > **New registration**. |
28 | 24 | - Register your application and note down the **Application (client) ID** and **Directory (tenant) ID**. |
29 | 25 |
|
30 | 26 |  |
31 | 27 |
|
32 | | -3. **Create a Client Secret**: |
| 28 | +3. **Create a client secret**: |
33 | 29 | - In the registered application, go to **Certificates & secrets**. |
34 | 30 | - Click **New client secret**. |
35 | 31 | - Provide a description and set an expiration period. |
36 | 32 | - Click **Add**. |
37 | 33 | - Copy the client secret value immediately, as it will be hidden later. Store it securely. |
38 | 34 |
|
39 | | -  |
40 | | - |
41 | | ---- |
| 35 | +  |
42 | 36 |
|
43 | | -### **Step 2: Create the Azure Storage Account** |
| 37 | +### **Step 2: Create the Azure Storage account** |
44 | 38 |
|
45 | | -1. **Create a Storage Account**: |
| 39 | +1. **Create a storage account**: |
46 | 40 | - In the Azure portal, use the search bar to search for **Storage accounts**. |
47 | 41 | - Create a new storage account by filling in the required details (e.g., name, location, resource group, etc.). |
48 | 42 |
|
49 | | -  |
50 | | - |
51 | | ---- |
| 43 | +  |
52 | 44 |
|
53 | | -### **Step 3: Assign Role to the Application** |
| 45 | +### **Step 3: Assign a role to the application** |
54 | 46 |
|
55 | | -1. **Go to your Storage Account**: |
| 47 | +1. **Go to the storage account**: |
56 | 48 | - Navigate to **Access control (IAM)** > **Add role assignment** in your Azure Storage Account. |
57 | 49 |
|
58 | | -2. **Assign Role**: |
| 50 | +2. **Assign a role**: |
59 | 51 | - Assign the **Storage Blob Data Contributor** role to your registered application. |
60 | 52 | - In the **Assign access to** dropdown, select **User, group, or service principal**. |
61 | 53 | - Click on **Select members** and search for your registered application by name or client ID. |
62 | 54 | - Select your application and click **Select**. |
63 | 55 | - Click **Review + assign** to finalize the role assignment. |
64 | 56 |
|
65 | | -  |
66 | | ---- |
| 57 | +  |
67 | 58 |
|
68 | | -### **Step 4: Upload the PDF Document to the Azure Storage Account** |
| 59 | +### **Step 4: Upload the PDF document to Azure Storage** |
69 | 60 |
|
70 | | -1. **Navigate to Data Storage**: |
| 61 | +1. **Navigate to Data storage**: |
71 | 62 | - In the Azure portal, go to **Data storage** > **Containers**. |
72 | 63 |
|
73 | | -2. **Upload the PDF File**: |
| 64 | +2. **Upload the PDF file**: |
74 | 65 | - Create a new container and upload the PDF document you want to access in the PDF Viewer. |
75 | 66 |
|
76 | | -  |
77 | | ---- |
| 67 | +  |
| 68 | + |
| 69 | +### **Step 5: Server-side configuration** |
| 70 | + |
| 71 | +1. **Configure server-side code**: |
| 72 | + - Open the server-side application (e.g., ASP.NET MVC) and configure the following details in the `PdfViewerController` file: |
| 73 | + - `tenantId` (your Azure AD tenant ID), |
| 74 | + - `clientId` (your registered application client ID), |
| 75 | + - `clientSecret` (your registered application client secret), |
| 76 | + - `blobServiceEndpoint` (your storage account blob service URL), |
| 77 | + - `containerName` (your container name in Azure Blob Storage). |
78 | 78 |
|
79 | | -### **Step 5: ASP.NET MVC PDF Viewer Control Configuration** |
80 | | -1. Follow the steps provided in the [link](https://help.syncfusion.com/document-processing/pdf/pdf-viewer/asp-net-mvc/getting-started/-with-server-backed) to create a simple PDF Viewer sample. |
| 79 | +2. **Run the web service**: |
| 80 | + - After configuring the necessary details, run the web service to make it accessible. |
81 | 81 |
|
82 | | -2. Add the following code snippet in `HomeController.cs`. |
| 82 | +### **Client-side configuration** |
| 83 | + |
| 84 | +1. **Run the ASP.NET MVC sample**: |
| 85 | + - Start the ASP.NET MVC (Razor) sample that includes the Syncfusion PDF Viewer. |
| 86 | + |
| 87 | +2. **Load a PDF from AAD**: |
| 88 | + - When the user clicks the **Load from AAD** button, the client-side JavaScript will make an HTTP request to the server-side API to fetch the PDF from Azure Blob Storage. |
| 89 | + - The server will retrieve the PDF from Azure, convert it to a Base64 string, and return it to the client. |
| 90 | + |
| 91 | +3. **Display the PDF in the PDF Viewer**: |
| 92 | + - Once the Base64 string is received, the PDF Viewer will load the PDF using the `viewer.load()` method. |
| 93 | + |
| 94 | +### **Save the PDF document to Azure** |
| 95 | + |
| 96 | +1. Save PDF to AAD: |
| 97 | + - The user can click the **Save to AAD** button to upload any modifications to the PDF back to Azure Blob Storage. |
| 98 | + - This action sends the modified PDF to the server, where it is converted into a byte array and saved to the specified Azure Blob container. |
| 99 | + |
| 100 | +### **Server-side code snippets** |
83 | 101 |
|
84 | 102 | {% tabs %} |
85 | 103 | {% highlight c# tabtitle="~/HomeController.cs" %} |
@@ -135,15 +153,7 @@ public async Task<ActionResult> SaveToAAD(jsonObjects responseData) |
135 | 153 | {% endhighlight %} |
136 | 154 | {% endtabs %} |
137 | 155 |
|
138 | | -3. Configure Server-Side Code: |
139 | | - - Open the server-side application (e.g., ASP.NET Core) and configure the following details in the `PdfViewerController` file: |
140 | | - - `tenantId` (your Azure AD tenant ID), |
141 | | - - `clientId` (your registered application client ID), |
142 | | - - `clientSecret` (your registered application client secret), |
143 | | - - `blobServiceEndpoint` (your storage account blob service URL), |
144 | | - - `containerName` (your container name in Azure Blob Storage). |
145 | | - |
146 | | -4. Add the following code snippet in `Index.cshtml`. |
| 156 | +### **Client-side code snippets** |
147 | 157 |
|
148 | 158 | {% tabs %} |
149 | 159 | {% highlight c# tabtitle="~/Index.cshtml" %} |
@@ -196,15 +206,4 @@ public async Task<ActionResult> SaveToAAD(jsonObjects responseData) |
196 | 206 | {% endhighlight %} |
197 | 207 | {% endtabs %} |
198 | 208 |
|
199 | | -5. Run the Application |
200 | | - - Build and run your MVC application. The PDF Viewer will be displayed with Load from AAD and Save to AAD buttons. |
201 | | - |
202 | | -6. Load PDF from AAD |
203 | | - - Click the Load from AAD button. |
204 | | - - The server fetches the PDF from Azure Blob Storage and loads it into the Syncfusion PDF Viewer. |
205 | | - |
206 | | -7. Save PDF to AAD |
207 | | - - Click the Save to AAD button. |
208 | | - - The server uploads the modified PDF back to Azure Blob Storage. |
209 | | - |
210 | | -[View sample in GitHub](https://github.com/SyncfusionExamples/open-save-pdf-documents-in-aad). |
| 209 | +[View sample in GitHub](https://github.com/SyncfusionExamples/open-save-pdf-documents-in-aad). |
0 commit comments