|
| 1 | +--- |
| 2 | +title: Convert HTML to PDF on the Windows Server | Syncfusion |
| 3 | +description: Learn how to convert HTML to PDF on a Windows Server using IIS Manager with clear and simple guidance. |
| 4 | +platform: document-processing |
| 5 | +control: PDF |
| 6 | +documentation: UG |
| 7 | +keywords: create pdf on windows server, generate pdf on windows server, syncfusion html to pdf, host pdf converter in iis |
| 8 | +--- |
| 9 | + |
| 10 | +# Convert HTML to PDF on the Windows Server using IIS Manager |
| 11 | + |
| 12 | +The Syncfusion<sup>®</sup> HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. Using this library, convert HTML to PDF document on the Windows Server using IIS Manager. |
| 13 | + |
| 14 | +## Steps to convert HTML to PDF on the windows server using IIS manager |
| 15 | + |
| 16 | +Step 1: Create a new C# ASP.NET Web Application (.NET Framework) project. |
| 17 | + |
| 18 | + |
| 19 | +Step 2: In the Create a new ASP.NET Web Application window, choose the MVC template and click Next to proceed. |
| 20 | + |
| 21 | + |
| 22 | +Step 3: Install [Syncfusion.HtmlToPdfConverter.Net.Windows](https://www.nuget.org/packages/Syncfusion.HtmlToPdfConverter.Net.Windows) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org/). |
| 23 | + |
| 24 | + |
| 25 | +Step 4: Include the following namespaces in the HomeController.cs file. |
| 26 | + |
| 27 | +{% highlight c# tabtitle="C#" %} |
| 28 | + |
| 29 | +using Syncfusion.Pdf; |
| 30 | +using Syncfusion.HtmlConverter; |
| 31 | +using System.IO; |
| 32 | + |
| 33 | +{% endhighlight %} |
| 34 | + |
| 35 | +Step 5: Add a new button in the Index.cshtml as shown below. |
| 36 | + |
| 37 | +{% highlight c# tabtitle="C#" %} |
| 38 | + |
| 39 | +@{Html.BeginForm("ExportToPDF", "Home", FormMethod.Post); |
| 40 | + { |
| 41 | + <div> |
| 42 | + <input type="submit" value="Convert PDF" style="width:150px;height:27px" /> |
| 43 | + </div> |
| 44 | + } |
| 45 | + Html.EndForm(); |
| 46 | + } |
| 47 | + |
| 48 | +{% endhighlight %} |
| 49 | + |
| 50 | +Step 6: Add a new action method named ExportToPDF in HomeController.cs and include the below code example to convert HTML to PDF document using [Convert](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html#Syncfusion_HtmlConverter_HtmlToPdfConverter_Convert_System_String_) method in [HtmlToPdfConverter](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.HtmlToPdfConverter.html) class. |
| 51 | + |
| 52 | +{% highlight c# tabtitle="C#" %} |
| 53 | + |
| 54 | +//Initialize HTML to PDF converter. |
| 55 | +HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); |
| 56 | +//Convert URL to PDF document. |
| 57 | +PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); |
| 58 | +//Create memory stream. |
| 59 | +MemoryStream stream = new MemoryStream(); |
| 60 | +//Save the document to memory stream. |
| 61 | +document.Save(stream); |
| 62 | +document.Close(true); |
| 63 | +return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTML-to-PDF.pdf"); |
| 64 | + |
| 65 | +{% endhighlight %} |
| 66 | + |
| 67 | +Step 7: Run the project and verify that the HTML‑to‑PDF conversion functions correctly in the local environment. |
| 68 | + |
| 69 | +## Publish the project to a Windows Server using IIS |
| 70 | + |
| 71 | +Step 1: Publish the project to a local folder by right‑clicking the project, selecting **Publish**, choosing the **Folder** option, and clicking **Next**. |
| 72 | + |
| 73 | + |
| 74 | +Step 2: Provide the folder path where the project should be published. |
| 75 | + |
| 76 | + |
| 77 | +Step 3: After creating the publish profile, Visual Studio opens the Publish dashboard. Review the target location, configuration, and other settings, and adjust them if necessary. Once everything looks correct, click **Publish** to deploy the application to the selected destination. |
| 78 | + |
| 79 | + |
| 80 | +Step 4: It will generate and publish all necessary files to the local publish directory. |
| 81 | + |
| 82 | + |
| 83 | +Step 5: Copy the published output folder to the server and host the application in IIS. |
| 84 | +i.Open **IIS Manager** on the server and create a new website. |
| 85 | + |
| 86 | +ii.Enter a **site name** and select the **physical path** that points to the published output folder on the server. |
| 87 | + |
| 88 | + |
| 89 | +iii. Obtain the server’s IP address after adding the website in the local IIS server. |
| 90 | + |
| 91 | +iv. From your local computer, browse the website using the server’s IP address and port number. Once the site loads successfully, export the webpage to PDF. |
| 92 | + |
| 93 | + |
| 94 | +A complete working sample is available for download from [GitHub](https://github.com/SyncfusionExamples/html-to-pdf-csharp-examples/tree/master/ASP.NET%20Core). |
| 95 | + |
| 96 | +Click the button to convert the Syncfusion<sup>®</sup> webpage into a PDF document. The generated PDF will appear as shown below. |
| 97 | + |
0 commit comments