diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 3f7c9e7bfb..b7e6bca9aa 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -3445,6 +3445,9 @@
  • Mac
  • +
  • + Web API +
  • Console
  • diff --git a/Document-Processing/Data-Extraction/NET/ocr-processor/overview.md b/Document-Processing/Data-Extraction/NET/ocr-processor/overview.md index fa050f0c11..ea243df8d3 100644 --- a/Document-Processing/Data-Extraction/NET/ocr-processor/overview.md +++ b/Document-Processing/Data-Extraction/NET/ocr-processor/overview.md @@ -11,7 +11,7 @@ keywords: Assemblies Optical character recognition (OCR) is a technology used to convert scanned paper documents in the form of PDF files or images into searchable and editable data. -The [Syncfusion® OCR processor library](https://www.syncfusion.com/document-processing/pdf-framework/net/pdf-library/ocr-process) has extended support to process OCR on scanned PDF documents and images with the help of Google’s [Tesseract](https://github.com/tesseract-ocr/tesseract) Optical Character Recognition engine. +The [Syncfusion® OCR processor library](https://www.syncfusion.com/document-sdk/net-pdf-library/ocr-process) has extended support to process OCR on scanned PDF documents and images with the help of Google’s [Tesseract](https://github.com/tesseract-ocr/tesseract) Optical Character Recognition engine. An inbuilt `image preprocessor` has been added to the OCR to prepare images for optimal recognition. This step ensures cleaner input and reduces OCR errors. The preprocessor supports the following enhancements: diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Web-API.md b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Web-API.md new file mode 100644 index 0000000000..dcdbb7aae1 --- /dev/null +++ b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/Convert-HTML-to-PDF-in-Web-API.md @@ -0,0 +1,100 @@ +--- +title: Convert HTML to PDF in ASP.NET Core Web API | Syncfusion +description: Learn here about how to convert HTML to PDF in in ASP.NET Core Web API with easy steps using Syncfusion .NET PDF library without depending on Adobe +platform: document-processing +control: PDF +documentation: UG +keywords: pdf, aspnet core, web api, csharp, html +--- + +# Convert HTML to PDF file in ASP.NET Core Web API + +The Syncfusion® [HTML to PDF converter](https://www.syncfusion.com/document-sdk/net-pdf-library/html-to-pdf) is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. Using this library, **convert HTML to PDF document in ASP.NET Core Web API**. + +To include the .NET HTML-to-PDF library in your ASP.NET Core Web API, please refer to the [NuGet Package](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/nuget-packages-required) Required' or [Assemblies Required](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/assemblies-required) documentation. + +## Steps to convert HTML to PDF in ASP.NET Core Web API + +Step 1: Create a new C# ASP.NET Core Web API project. +![Convert HTMLToPDF Web API Step1](htmlconversion_images/Web-API-1.png) + +Step 2: In the project configuration windows, name your project and click Create. +![Convert HTMLToPDF Web API Step2](htmlconversion_images/Web-API-2.png) + +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/). +![NuGet package installation](htmlconversion_images/Console-4.png) + +N> Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add "Syncfusion.Licensing" assembly reference and include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. + +Step 4: Add a new API controller empty file in the project. +![Add new class](htmlconversion_images/Web-API-4.png) + +Step 5: Include the following namespaces in the *Program.cs*. + +{% tabs %} +{% highlight c# tabtitle="C#" %} + +using Syncfusion.Drawing; +using Syncfusion.HtmlConverter; +using Syncfusion.Pdf; + +{% endhighlight %} +{% endtabs %} + +Step 6: Include the following code sample in *Program.cs* 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. The HTML content will be scaled based on the given [ViewPortSize](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html#Syncfusion_HtmlConverter_BlinkConverterSettings_ViewPortSize) property of [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class. + +{% tabs %} +{% highlight c# tabtitle="C#" %} + +[HttpGet("/api/Pdf")] +public IActionResult ConvertHTMLtoPDF() +{ + try + { + const string fileDownloadName = "Output.pdf"; + const string contentType = "application/pdf"; + var stream = ExportWeatherForecastToPdf(); + stream.Position = 0; + return File(stream, contentType, fileDownloadName); + } + catch (Exception ex) + { + return BadRequest($"Error occurred while creating PDF file: {ex.Message}"); + } +} + +private MemoryStream ExportWeatherForecastToPdf() +{ + var forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }).ToList(); + + //Initialize HTML to PDF converter. + HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + //Set Blink viewport size. + blinkConverterSettings.ViewPortSize =new Size(1280, 0); + //Assign Blink converter settings to HTML converter. + htmlConverter.ConverterSettings = blinkConverterSettings; + //Convert URL to PDF document. + PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + //Create memory stream. + MemoryStream stream = new MemoryStream(); + //Save the document to memory stream. + document.Save(stream); + return new MemoryStream(stream.ToArray()); +} + +{% endhighlight %} +{% endtabs %} + +Step 7: Navigate to the `Swagger UI`, expand the `GET /api/Pdf` API, click `Execute`, and then download the response output. +![Swagger UI](htmlconversion_images/Web-API-5.png) + +By executing the program, you will get the PDF document as follows. +![HTML to PDF output document](htmlconversion_images/IIS-Output.png) + +A complete working sample can be downloaded from Github. \ No newline at end of file diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-1.png b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-1.png new file mode 100644 index 0000000000..18c895ac7f Binary files /dev/null and b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-1.png differ diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-2.png b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-2.png new file mode 100644 index 0000000000..25b6446b9f Binary files /dev/null and b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-2.png differ diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-4.png b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-4.png new file mode 100644 index 0000000000..90bac47ba6 Binary files /dev/null and b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-4.png differ diff --git a/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-5.png b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-5.png new file mode 100644 index 0000000000..b6c6e1b5a7 Binary files /dev/null and b/Document-Processing/PDF/Conversions/HTML-To-PDF/NET/htmlconversion_images/Web-API-5.png differ diff --git a/Document-Processing/PDF/PDF-Library/NET/Create-PDF-document-in-Web-API.md b/Document-Processing/PDF/PDF-Library/NET/Create-PDF-document-in-Web-API.md index 07a0747868..500979b994 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Create-PDF-document-in-Web-API.md +++ b/Document-Processing/PDF/PDF-Library/NET/Create-PDF-document-in-Web-API.md @@ -50,60 +50,23 @@ Add the following code sample in ``PdfController`` class which illustrates how t {% highlight c# tabtitle="C#" %} [HttpGet("/api/Pdf")] -public IActionResult CreatePdfDocument() +public IActionResult ConvertHTMLtoPDF() { - try - { - const string fileDownloadName = "Output.pdf"; - const string contentType = "application/pdf"; - var stream = ExportWeatherForecastToPdf(); - stream.Position = 0; - return File(stream, contentType, fileDownloadName); - } - catch (Exception ex) - { - return BadRequest($"Error occurred while creating PDF file: {ex.Message}"); - } -} - -private MemoryStream ExportWeatherForecastToPdf() -{ - var forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }).ToList(); - - using (PdfDocument pdfDocument = new PdfDocument()) - { - int paragraphAfterSpacing = 8; - int cellMargin = 8; - PdfPage page = pdfDocument.Pages.Add(); - PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); - PdfTextElement title = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black); - PdfLayoutResult result = title.Draw(page, new PointF(0, 0)); - PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); - PdfTextElement content = new PdfTextElement("This component demonstrates fetching data from a service and exporting the data to a PDF document using Syncfusion .NET PDF library.", contentFont, PdfBrushes.Black); - PdfLayoutFormat format = new PdfLayoutFormat - { - Layout = PdfLayoutType.Paginate - }; - result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format); - PdfGrid pdfGrid = new PdfGrid(); - pdfGrid.Style.CellPadding.Left = cellMargin; - pdfGrid.Style.CellPadding.Right = cellMargin; - pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); - pdfGrid.DataSource = forecasts; - pdfGrid.Style.Font = contentFont; - pdfGrid.Draw(page, new PointF(0, result.Bounds.Bottom + paragraphAfterSpacing)); - - using (MemoryStream stream = new MemoryStream()) - { - pdfDocument.Save(stream); - return new MemoryStream(stream.ToArray()); - } - } + //Initialize HTML to PDF converter. + HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); + BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings(); + //Set Blink viewport size. + blinkConverterSettings.ViewPortSize = new Size(1280, 0); + //Assign Blink converter settings to HTML converter. + htmlConverter.ConverterSettings = blinkConverterSettings; + //Convert URL to PDF document. + PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com"); + //Create memory stream. + MemoryStream stream = new MemoryStream(); + //Save the document to memory stream. + document.Save(stream); + stream.Position = 0; + return File(stream, "application/pdf", "Output.pdf"); } {% endhighlight %} diff --git a/Document-Processing/PDF/PDF-Library/NET/Create-PDF-file-in-C-Sharp-VB-NET.md b/Document-Processing/PDF/PDF-Library/NET/Create-PDF-file-in-C-Sharp-VB-NET.md index 9ab9bfb9d5..5ef3dbd9b8 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Create-PDF-file-in-C-Sharp-VB-NET.md +++ b/Document-Processing/PDF/PDF-Library/NET/Create-PDF-file-in-C-Sharp-VB-NET.md @@ -1023,5 +1023,4 @@ finalDoc.Close(True) {% endtabs %} N> You can also explore our [.NET PDF library](https://document.syncfusion.com/demos/pdf/default#/tailwind) demo that shows how to create and modify PDF files from C# with just five lines of code. - N> Looking for the full .NET PDF Library overview, features, pricing, and documentation? Visit the [.NET PDF Library](https://www.syncfusion.com/document-sdk/net-pdf-library) page. diff --git a/Document-Processing/PDF/PDF-Library/NET/Overview.md b/Document-Processing/PDF/PDF-Library/NET/Overview.md index 6aa2338858..d439e5c9e0 100644 --- a/Document-Processing/PDF/PDF-Library/NET/Overview.md +++ b/Document-Processing/PDF/PDF-Library/NET/Overview.md @@ -53,5 +53,4 @@ The following list shows the key features available in the Essential® 1. Starting with v20.1.0.x, if you reference Syncfusion® HTML converter or OCR processor assemblies from trial setup or from the NuGet feed, you also have to include a license key in your projects. Please refer to this [link](https://help.syncfusion.com/common/essential-studio/licensing/overview) to know about registering Syncfusion® license key in your application to use our components. - N> Looking for the full .NET PDF Library overview, features, pricing, and documentation? Visit the [.NET PDF Library](https://www.syncfusion.com/document-sdk/net-pdf-library) page.