Converting HTML to PDF using Blink in AWS Elastic Beanstalk
The Syncfusion® HTML to PDF converter enables reliable transformation of HTML webpages into PDF documents using the Blink rendering engine within AWS Elastic Beanstalk. This guide outlines a step-by-step approach to perform accurate and seamless conversions in the AWS environment while preserving the original layout and design of the HTML content.
Steps to convert HTML to PDF using Blink in AWS Elastic Beanstalk
Step 1: Create an ASP.NET Core MVC Application: Initiate a project using ASP.NET Core Model-View-Controller pattern
Step 2: Configure Your Project: On the configuration page, provide a project name and proceed by selecting Next.
Step 3:Install Required Packages: Add the Syncfusion.HtmlToPdfConverter.Net.Aws NuGet package to your project.
Step 4: Set Up Your Controller: In the
HomeController.cs
, include the necessary namespaces
using Syncfusion.Pdf;
using Syncfusion.HtmlConverter;
using System.IO;
Step 5: Create a Button for Conversion: Add a button in index.cshtml
to trigger the conversion
@{
Html.BeginForm("BlinkToPDF", "Home", FormMethod.Get);
{
<div>
<input type="submit" value="HTML To PDF" style="width:150px;height:27px" />
<br />
<div class="text-danger">
@ViewBag.Message
</div>
</div>
}
Html.EndForm();
}
Step 6: Implement the Conversion Logic: In HomeController.cs
define an action method BlinkToPDF.
public IActionResult BlinkToPDF()
{
//Initialize HTML to PDF converter.
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings settings = new BlinkConverterSettings();
//Set command line arguments to run without the sandbox.
settings.CommandLineArguments.Add("--no-sandbox");
settings.CommandLineArguments.Add("--disable-setuid-sandbox");
//Set Blink viewport size.
settings.ViewPortSize = new Syncfusion.Drawing.Size(1280, 0);
//Assign Blink settings to the HTML converter.
htmlConverter.ConverterSettings = settings;
//Convert URL to PDF document.
PdfDocument document = htmlConverter.Convert("https://www.syncfusion.com");
//Create the memory stream.
MemoryStream stream = new MemoryStream();
//Save the document to the memory stream.
document.Save(stream);
return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "BlinkLinuxDockerAWSBeanstalk.pdf");
}
Step 7: Click the Publish to AWS Elastic Beanstalk (Legacy) option by right-clicking the project to publish the application in the AWS Elastic Beanstalk environment.
Step 8: Select the Create a new application environment and click Next from Publish to AWS Elastic Beanstalk window.
Step 9: Please give any valid name to the environment and URL text box. Check whether the URL link is available while clicking the Check availability option. If the requested link is available means, click NEXT in the Application Environment window.
Step 10: Select t3a.micro from the Instance Type text box and select Next in the AWS Options Window.
Step 11: Select the Roles and Next option from the Permissions window.
Step 12: Click Next from the Application Options window.
Step 13: Click Deploy from the Review window.
Step 14: Click the URL link to launch the application once the Environment is updated successfully and Environment status is healthy.
Now, the webpage will open in the browser. Click the button to convert the webpage to a PDF document.
By executing the program, the output PDF document will be generated as shown below.
A complete working sample for converting an HTML to PDF using Blink in AWS Elastic Beanstalk can be downloaded from GitHub.
Take a moment to peruse the documentation for converting HTML to PDF, where you’ll find various options, such as converting a URL to PDF, HTML string to PDF, and handling hyperlinks.
Starting with v16.2.0.x, if you reference the Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.
Conclusion:
I hope you enjoyed learning about how to convert HTML to PDF using Blink in AWS Elastic Beanstalk.
You can refer to our ASP.NET Core PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our ASP.NET Core PDF example to understand how to present and manipulate data.
For current customers, you can check out our ASP.NET Core components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our ASP.NET Core PDF and other ASP.NET Core components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!