Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET — очень мощный продукт для управления PDF-документами. Он позволяет легко конвертировать страницы в PDF-документах в изображения. Aspose.BarCode для .NET — не менее мощный продукт для создания и распознавания штрихкодов.
Класс PdfConverter в пространстве имён Aspose.Pdf.Facades поддерживает преобразование PDF-страниц в различные форматы изображений. PngDevice в пространстве имён Aspose.Pdf.Devices поддерживает преобразование PDF-страниц в файлы PNG. Любой из этих классов можно использовать для преобразования страниц PDF-файла в изображения.
Когда страницы преобразованы в формат изображения, мы можем использовать Aspose.BarCode для .NET для идентификации штрихкодов внутри них. Приведённые ниже примеры кода показывают, как конвертировать страницы с помощью PdfConverter или PngDevice.
Класс PdfConverter содержит метод с именем GetNextImage, который генерирует изображение из текущей страницы PDF. Чтобы указать выходной формат изображения, этот метод принимает аргумент из перечисления System.Drawing.Imaging.ImageFormat.
Aspose.Barcode содержит пространство имён BarCodeRecognition, которое содержит класс BarCodeReader. Класс BarCodeReader позволяет считывать, определять и идентифицировать штрихкоды из файлов изображений.
Для этого примера сначала преобразуйте страницу в файле PDF в изображение с помощью Aspose.Pdf.Facades.PdfConverter. Затем используйте класс Aspose.BarCodeRecognition.BarCodeReader для распознавания штрихкода на изображении.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void IdentifyBarcodesConverter()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Create a PdfConverter object
var converter = new Aspose.Pdf.Facades.PdfConverter();
// Bind PDF document
converter.BindPdf(dataDir + "IdentifyBarcodes.pdf");
// Specify the start page to be processed
converter.StartPage = 1;
// Specify the end page for processing
converter.EndPage = 1;
// Create a Resolution object to specify the resolution of resultant image
converter.Resolution = new Aspose.Pdf.Devices.Resolution(300);
// Initialize the convertion process
converter.DoConvert();
// Create a MemoryStream object to hold the resultant image
using (var imageStream = new MemoryStream())
{
// Check if pages exist and then convert to image one by one
while (converter.HasNextImage())
{
// Save the image in the given image Format
converter.GetNextImage(imageStream, System.Drawing.Imaging.ImageFormat.Png);
// Set the stream position to the beginning of the stream
imageStream.Position = 0;
// Instantiate a BarCodeReader object
var barcodeReader = new Aspose.BarCodeRecognition.BarCodeReader(imageStream, Aspose.BarCodeRecognition.BarCodeReadType.Code39Extended);
// String txtResult.Text = "";
while (barcodeReader.Read())
{
// Get the barcode text from the barcode image
var code = barcodeReader.GetCodeText();
// Write the barcode text to Console output
Console.WriteLine("BARCODE : " + code);
}
// Close the BarCodeReader object to release the image file
barcodeReader.Close();
}
// Close the PdfConverter instance and release the resources
converter.Close();
}
}
В Aspose.Pdf.Devices есть класс PngDevice. Этот класс позволяет конвертировать страницы PDF-документов в PNG-изображения.
Для этого примера загрузите исходный PDF-файл в документ Document, преобразуйте страницы документа в PNG-изображения. Когда изображения будут созданы, используйте класс BarCodeReader в Aspose.BarCodeRecognition для идентификации и считывания штрихкодов на изображениях.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void IdentifyBarcodes()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "IdentifyBarcodes.pdf"))
{
// Traverse through the individual pages of the PDF file
for (int pageCount = 1; pageCount <= document.Pages.Count; pageCount++)
{
using (var imageStream = new MemoryStream())
{
// Create a Resolution object
var resolution = new Aspose.Pdf.Devices.Resolution(300);
// Instantiate a PngDevice object while passing a Resolution object as an argument to its constructor
var pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(document.Pages[pageCount], imageStream);
// Set the stream position to the beginning of Stream
imageStream.Position = 0;
// Instantiate a BarCodeReader object
var barcodeReader = new Aspose.BarCodeRecognition.BarCodeReader(imageStream, Aspose.BarCodeRecognition.BarCodeReadType.Code39Extended);
// String txtResult.Text = "";
while (barcodeReader.Read())
{
// Get the barcode text from the barcode image
var code = barcodeReader.GetCodeText();
// Write the barcode text to Console output
Console.WriteLine("BARCODE : " + code);
}
// Close the BarCodeReader object to release the image file
barcodeReader.Close();
}
}
}
}
Дополнительную информацию по темам, затронутым в этой статье, см. в разделах:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.