Skip to content

Commit 4db6290

Browse files
Merge pull request #1719 from syncfusion-content/839921-ug
839921-ug: Converted HTML to PDF using Blink in Amazon ECS using AWS Fargate.
2 parents 31007b7 + 38c4bef commit 4db6290

File tree

17 files changed

+147
-3
lines changed

17 files changed

+147
-3
lines changed

Document-Processing-toc.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,9 @@
26132613
<li>
26142614
<a href="/document-processing/pdf/conversions/html-to-pdf/net/Convert-HTML-to-PDF-in-AWS-Elastic-Beanstalk">AWS Elastic Beanstalk</a>
26152615
</li>
2616+
<li>
2617+
<a href="/document-processing/pdf/conversions/html-to-pdf/net/Convert-HTML-to-PDF-in-Amazon-ECS-with-Fargate">AWS Fargate (ECS)</a>
2618+
</li>
26162619
</ul>
26172620
</li>
26182621
<li>
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: Convert HTML to PDF in Amazon ECS with Fargate | Syncfusion
3+
description: Learn how to convert HTML to PDF in Amazon ECS with Fargate using Syncfusion .NET HTML converter library.
4+
platform: document-processing
5+
control: PDF
6+
documentation: UG
7+
---
8+
9+
# Convert HTML to PDF file in Amazon ECS with Fargate
10+
11+
The Syncfusion<sup>&reg;</sup> [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 using Blink in Amazon ECS with Fargate**.
12+
13+
## Steps to convert HTML to PDF using Blink in Amazon ECS with Fargate
14+
15+
Step 1: Create a new C# ASP.NET Core Web Application project.
16+
![AWS ECS Step1](htmlconversion_images/AWS_Elastic_Beanstalk1.png)
17+
18+
Step 2: In configuration windows, name your project and select **Next**.
19+
![AWS ECS Step2](htmlconversion_images/AWS_ECS_2.png)
20+
21+
![AWS ECS Step2.1](htmlconversion_images/AWS_ECS_3.png)
22+
23+
Step 3: Install the [Syncfusion.HtmlToPdfConverter.Net.Linux](https://www.nuget.org/packages/Syncfusion.HtmlToPdfConverter.Net.Linux) NuGet package as a reference to your AWS Elastic Beanstalk project from [NuGet.org.](https://www.nuget.org/).
24+
![AWS ECS Step3](htmlconversion_images/AWS_ECS_4.png)
25+
26+
Step 4: Include the following commands in the Docker file to install the dependent packages in the docker container.
27+
28+
{% highlight c# tabtitle="C#" %}
29+
30+
RUN apt-get update && \
31+
apt-get install -yq --no-install-recommends \
32+
libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
33+
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
34+
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
35+
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
36+
libnss3 libgbm1
37+
38+
{% endhighlight %}
39+
40+
![AWS ECS Step4](htmlconversion_images/AWS_ECS_5.png)
41+
42+
Step 5: A default controller named **HomeController.cs** gets added to create the ASP.NET Core MVC project. Include the following namespaces in that HomeController.cs file.
43+
44+
{% highlight c# tabtitle="C#" %}
45+
46+
using Syncfusion.Pdf;
47+
using Syncfusion.HtmlConverter;
48+
using System.IO;
49+
50+
{% endhighlight %}
51+
52+
Step 6: Add a new button in **index.cshtml** as follows.
53+
54+
{% highlight c# tabtitle="C#" %}
55+
56+
@{
57+
Html.BeginForm("BlinkToPDF", "Home", FormMethod.Get);
58+
{
59+
<div>
60+
<input type="submit" value="HTML To PDF" style="width:150px;height:27px" />
61+
<br />
62+
<div class="text-danger">
63+
@ViewBag.Message
64+
</div>
65+
</div>
66+
}
67+
Html.EndForm();
68+
}
69+
70+
{% endhighlight %}
71+
72+
Step 7: Add a new action method named BlinkToPDF in HomeController.cs and include the following code example to convert HTML to PDF document using the Convert 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 the [BlinkConverterSettings](https://help.syncfusion.com/cr/document-processing/Syncfusion.HtmlConverter.BlinkConverterSettings.html) class.
73+
74+
{% highlight c# tabtitle="C#" %}
75+
76+
public IActionResult BlinkToPDF()
77+
{
78+
//Initialize HTML to PDF converter.
79+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
80+
BlinkConverterSettings settings = new BlinkConverterSettings();
81+
//Set Blink viewport size.
82+
settings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0);
83+
//Assign Blink settings to the HTML converter.
84+
htmlConverter.ConverterSettings = settings;
85+
//Convert URL to PDF document.
86+
PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");
87+
//Create the memory stream.
88+
MemoryStream stream = new MemoryStream();
89+
//Save the document to the memory stream.
90+
document.Save(stream);
91+
//Close the document
92+
document.Close(true);
93+
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "BlinkLinuxDockerAWSBeanstalk.pdf");
94+
}
95+
96+
{% endhighlight %}
97+
98+
N> Starting from **version 29.2.4**, it is no longer necessary to manually add the following command-line arguments when using the Blink rendering engine:
99+
N> ```csharp
100+
N> settings.CommandLineArguments.Add("--no-sandbox");
101+
N> settings.CommandLineArguments.Add("--disable-setuid-sandbox");
102+
N> ```
103+
N> These arguments are only required when using **older versions** of the library that depend on Blink in sandbox-restricted environments.
104+
105+
## Publish the ASP.NET Core application to Amazon ECS with Fargate using AWS Toolkit.
106+
107+
Step 8: Click the **Publish Container to AWS (Legacy)…** option by right-clicking the project to
108+
publish the application.
109+
![AWS ECS Step5](htmlconversion_images/AWS_ECS_6.png)
110+
111+
Step 9: Select the AWS account profile and region to use for deployment. Ensure **Service on an ECS Cluster** is selected as the Deployment Target then click the **Next** button.
112+
![AWS ECS Step6](htmlconversion_images/AWS_ECS_7.png)
113+
114+
Step 10: Choose **Create an empty cluster** for the ECS Cluster and provide a name for the cluster and Launch Type should be set to **FARGATE** in the Launch Configuration window.
115+
![AWS ECS Step7](htmlconversion_images/AWS_ECS_8.png)
116+
117+
Step 11: Choose **Create New** for the service and provide a name for your service in the service Configuration window.
118+
![AWS ECS Step8](htmlconversion_images/AWS_ECS_9.png)
119+
120+
Step 12: Select the Configure Application Load Balance and Choose **Create New** in the load balancer drop-down and provide a name for your load balancer from the Application Load Balancer Configuration window.
121+
![AWS ECS Step9](htmlconversion_images/AWS_ECS_10.png)
122+
123+
Step 13: Choose **Create New** for the task definition and enter a name for the task. Select an **Task Role** to provide AWS credentials to your application to access AWS services in the Task Definition window and Select **Publish**.
124+
![AWS ECS Step10.1](htmlconversion_images/AWS_ECS_11.png)
125+
![AWS ECS Step10.2](htmlconversion_images/AWS_ECS_12.png)
126+
127+
Step 14: Once the deployment process completed, the toolkit will open a view onto the cluster. Click the Load Balance **URL link** to launch the application once the Load Balance status changed to Active.
128+
![AWS ECS Step11](htmlconversion_images/AWS_ECS_13.png)
129+
130+
Now, the webpage will open in the browser. Click the button to convert the webpage to a PDF document.
131+
![AWS ECS Step12](htmlconversion_images/AWS_ECS_14.png)
132+
133+
By executing the program, you will get a PDF document as follows.
134+
![AWS ECS Step13](htmlconversion_images/AWS_Ecs_15.png)
135+
136+
A complete working sample for converting an HTML to PDF using Blink in Amazon ECS using AWS Fargate can be downloaded from [GitHub](https://github.com/SyncfusionExamples/html-to-pdf-csharp-examples/tree/master/AWS/NetCoreAWSFargate).
137+
138+
Click [here](https://www.syncfusion.com/document-sdk/net-pdf-library/html-to-pdf) to explore the rich set of Syncfusion Essential PDF features.
139+
140+
An online sample link to [convert HTML to PDF document](https://ej2.syncfusion.com/aspnetcore/PDF/HtmltoPDF#/material3) in ASP.NET Core.

Document-Processing/PDF/Conversions/HTML-To-PDF/NET/aws.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ The Syncfusion<sup>&reg;</sup> [HTML to PDF converter](https://www.syncfusion.co
1919

2020
## Convert HTML to PDF in AWS Lambda
2121

22-
<<<<<<< HEAD
2322
HTML to PDF converter .NET library supports conversion in AWS Lambda. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda) section for more information about HTML to PDF conversion in AWS Lambda.
2423

2524
## Convert HTML to PDF in AWS Lambda with NET 6 container image
2625

27-
HTML to PDF converter .NET library supports conversion in AWS Lambda with NET 6 container image. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda-with-net6-container-image) section for more information about HTML to PDF conversion in AWS Lambda with NET 6 container image.
26+
HTML to PDF converter .NET library supports conversion in AWS Lambda with NET 6 container image. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-lambda-with-net-6-container-image) section for more information about HTML to PDF conversion in AWS Lambda with NET 6 container image.
2827

29-
## Convert HTML to PDF in AWS Elastic Beanstalk.
28+
## Convert HTML to PDF in AWS Elastic Beanstalk
3029

3130
HTML to PDF converter .NET library supports conversion in AWS Elastic Beanstalk. Refer to [this](https://help.syncfusion.com/document-processing/pdf/conversions/html-to-pdf/net/convert-html-to-pdf-in-aws-elastic-beanstalk) section for more information about HTML to PDF conversion in AWS Elastic Beanstalk.
3231

32+
## Convert HTML to PDF in Amazon ECS with Fargate
3333

34+
HTML to PDF converter .NET library supports conversion in Amazon ECS with Fargate. Refer to this section for more information about HTML to PDF conversion in Amazon ECS with Fargate.
51.1 KB
Loading
45.1 KB
Loading
59 KB
Loading
59.6 KB
Loading
34.8 KB
Loading
62.2 KB
Loading
29.6 KB
Loading

0 commit comments

Comments
 (0)