How does the ASP.NET Core framework handle barcode to image conversion?
Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can create a barcode and you can convert the barcode to image in the ASP.NET Core platform.
Steps to convert the barcode to image in the ASP.NET Core platform:
- Create a new ASP.NET Core Web Application project.
- Select the Web Application pattern (Model-View-Controller) for the project.
- Install the Syncfusion.Pdf.Imaging.Net.Core NuGet package as a reference to your .NET Core application from nuget.org.
- Add a new button in the Index.cshtml as shown below.
CSHTML
@{Html.BeginForm("CreateDocument", "Home", FormMethod.Get); { <div> <input type="submit" value="Create Document" style="width:150px;height:27px" /> </div> } Html.EndForm(); }
- A default controller with a name HomeController.cs is added to the ASP.NET Core project. Include the following namespaces in that HomeController.cs file.
C#
using Syncfusion.Pdf.Barcode; using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
VB.NET
Imports Syncfusion.Pdf.Barcode Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Drawing
- Add a new action method CreateDocument in the HomeController.cs and include the following code snippet to convert the barcode to image and download it.
C#
//Drawing QR Barcode PdfQRBarcode barcode = new PdfQRBarcode(); //Set an error correction level barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.Medium; //Set XDimension barcode.XDimension = 3; //Set text barcode.Text = "http://www.syncfusion.com"; //Convert to image Stream barcodeImage = barcode.ToImage(new SizeF(300,300)); //Download the PDF document in the browser FileStreamResult fileStreamResult = new FileStreamResult(barcodeImage, "application/jpg"); fileStreamResult.FileDownloadName = "Barcode.jpg"; return fileStreamResult;
VB.NET
'Drawing QR Barcode Dim barcode As PdfQRBarcode = New PdfQRBarcode() 'Set an error correction level barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.Medium 'Set XDimension barcode.XDimension = 3 'Set text barcode.Text = "http://www.syncfusion.com" 'Convert to image Dim barcodeImage As Stream = barcode.ToImage(New SizeF(300, 300)) 'Download the PDF document in the browser Dim fileStreamResult As FileStreamResult = New FileStreamResult(barcodeImage, "application/jpg") fileStreamResult.FileDownloadName = "Barcode.jpg" Return fileStreamResult
A complete working sample can be downloaded from BarcodeToImage.zip.
By executing the program, you will get the image as follows.
Starting with v16.2.0.x, if you reference 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 a trial message.
Conclusion:
I hope you enjoyed learning about how does the ASP.NET Core framework handle barcode to image conversion.
You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!