Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
Razor Barcode Generator is a handy tool that simplifies the creation of barcodes for developers and businesses alike. Integrating barcode generation into web applications enhances the functionality and user experience, making it straightforward to produce a variety of barcode types. Whether you're managing inventory, tracking assets, or streamlining checkout processes, utilizing a Razor Barcode Generator can significantly improve efficiency and accuracy. We'll use IronBarcode in this tutorial for creating a barcode generator.
IronBarcode is an essential tool for developers working with .NET Core, offering an easy-to-use library for barcode generation and reading. It stands out because of its simplicity in integrating into your projects, requiring minimal code to produce or decipher barcodes and QR codes. This makes IronBarcode a versatile choice for enhancing applications with both barcode generation and barcode reading functionality, from web applications using Razor pages to desktop and mobile applications. Its broad range of supported barcode formats ensures that it can meet diverse project requirements, including those for .NET MVC, Blazor WebAssembly app, and Blazor App, making it a reliable choice for developers.
Creating an ASP.NET Core Web App with Razor Pages in Visual Studio is straightforward. This guide will help you set up your project from scratch:
To install IronBarcode using the NuGet Package Manager in Visual Studio:
Enhance the Index page by editing the index.cshtml
file. Apply custom styling:
<style>
body {
font-family: 'Poppins', sans-serif;
}
/* More CSS styles omitted for brevity */
</style>
<style>
body {
font-family: 'Poppins', sans-serif;
}
/* More CSS styles omitted for brevity */
</style>
<h1 class="text-center mb-4" style="color:#004b9b">Welcome to Barcode Generator</h1>
<div class="svg-container text-center">
<img src="~/images/logo.svg" class="barcode-logo" alt="Barcode" />
</div>
<h1 class="text-center mb-4" style="color:#004b9b">Welcome to Barcode Generator</h1>
<div class="svg-container text-center">
<img src="~/images/logo.svg" class="barcode-logo" alt="Barcode" />
</div>
<div class="container">
<div class="row justify-content-center">
<!-- Form and Image Column will go here -->
</div>
</div>
<div class="container">
<div class="row justify-content-center">
<!-- Form and Image Column will go here -->
</div>
</div>
Include the form to collect user input for barcode generation:
<div class="col-md-6 divider col-padding">
<form method="post" enctype="multipart/form-data">
<!-- Form elements omitted for brevity -->
<button type="submit" asp-page-handler="Upload" class="btn btn-primary btn-block">Generate Barcode</button>
</form>
<div id="messageContainer">
<span id="message" style="color:green;">@Html.Raw(Model.Message)</span>
</div>
</div>
<div class="col-md-6 divider col-padding">
<form method="post" enctype="multipart/form-data">
<!-- Form elements omitted for brevity -->
<button type="submit" asp-page-handler="Upload" class="btn btn-primary btn-block">Generate Barcode</button>
</form>
<div id="messageContainer">
<span id="message" style="color:green;">@Html.Raw(Model.Message)</span>
</div>
</div>
For displaying and downloading the generated barcode:
<div class="col-md-6 image-padding">
<div id="imageContainer">
<!-- Image and download button elements omitted for brevity -->
</div>
</div>
<div class="col-md-6 image-padding">
<div id="imageContainer">
<!-- Image and download button elements omitted for brevity -->
</div>
</div>
Add functionality to handle input and download actions using jQuery:
@section Scripts {
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function () {
// jQuery code omitted for brevity
});
</script>
}
@section Scripts {
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function () {
// jQuery code omitted for brevity
});
</script>
}
At the top of your index.cshtml
file, add:
using Color = IronSoftware.Drawing.Color;
using Color = IronSoftware.Drawing.Color;
IRON VB CONVERTER ERROR developers@ironsoftware.com
Define available colors for barcodes:
public enum BarcodeColors
{
AliceBlue,
AntiqueWhite,
Aqua,
Aquamarine,
Azure,
Beige,
Bisque
// And others...
}
public enum BarcodeColors
{
AliceBlue,
AntiqueWhite,
Aqua,
Aquamarine,
Azure,
Beige,
Bisque
// And others...
}
Public Enum BarcodeColors
AliceBlue
AntiqueWhite
Aqua
Aquamarine
Azure
Beige
Bisque
' And others...
End Enum
Define available types of barcodes:
public enum BarcodeTypes
{
Aztec,
Codabar,
// Other barcode types...
}
public enum BarcodeTypes
{
Aztec,
Codabar,
// Other barcode types...
}
Public Enum BarcodeTypes
Aztec
Codabar
' Other barcode types...
End Enum
Convert enums to color and barcode encoding:
private Color EnumToColor(BarcodeColors colorEnum) { /* Conversion logic */ }
private BarcodeWriterEncoding GetBarcodeEncoding(BarcodeTypes barcodeType) { /* Encoding logic */ }
private Color EnumToColor(BarcodeColors colorEnum) { /* Conversion logic */ }
private BarcodeWriterEncoding GetBarcodeEncoding(BarcodeTypes barcodeType) { /* Encoding logic */ }
Private Function EnumToColor(ByVal colorEnum As BarcodeColors) As Color
End Function
Private Function GetBarcodeEncoding(ByVal barcodeType As BarcodeTypes) As BarcodeWriterEncoding
End Function
Handle form submission for barcode generation:
public JsonResult OnPostUpload(string barcodeText, string barcodeType, int? maxWidth, int? maxHeight, string barcodeColor)
{
// Function logic...
}
public JsonResult OnPostUpload(string barcodeText, string barcodeType, int? maxWidth, int? maxHeight, string barcodeColor)
{
// Function logic...
}
Public Function OnPostUpload(ByVal barcodeText As String, ByVal barcodeType As String, ByVal maxWidth? As Integer, ByVal maxHeight? As Integer, ByVal barcodeColor As String) As JsonResult
' Function logic...
End Function
Edit \_Layout.cshtml
for a minimalist design:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head contents omitted for brevity -->
</head>
<body>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<!-- Scripts inclusion omitted for brevity -->
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Head contents omitted for brevity -->
</head>
<body>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<!-- Scripts inclusion omitted for brevity -->
</body>
</html>
Run your application by pressing F5 or Ctrl + F5. Follow the instructions onscreen to input data, choose a barcode type, set dimensions, and generate a barcode.
The barcode generator web application offers an easy way to create custom barcodes. You can input data, select a barcode type, set dimensions, and choose a color before generating a barcode. IronBarcode powers this application with a free trial, and licenses start at $749.
For generating QR Code images, consider using IronQR.
A Razor Barcode Generator is a tool that simplifies the creation of barcodes for developers and businesses, integrating barcode generation into web applications for enhanced functionality and user experience.
This tutorial uses IronBarcode, a library for .NET Core that provides easy-to-use functions for barcode generation and reading.
To create an ASP.NET Core Web App with Razor Pages, open Visual Studio, select 'Create a new project', choose 'ASP.NET Core Web App', configure your project settings, and follow the setup prompts.
Install IronBarcode using the NuGet Package Manager in Visual Studio by right-clicking your project in Solution Explorer, selecting 'Manage NuGet Packages...', searching for 'IronBarcode', and clicking 'Install'.
You can enhance the Index page by customizing the styling in the 'index.cshtml' file, adding a welcome message, structuring main content, designing an input form, and managing image display.
BarcodeColors and BarcodeTypes enums are used to define available colors for barcodes and available types of barcodes, respectively, providing options for customization in the barcode generation process.
The OnPostUpload function handles form submissions for barcode generation, processing user input such as barcode text, type, dimensions, and color to generate the desired barcode.