Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET es un producto muy poderoso para gestionar documentos PDF. Facilita la conversión de páginas en documentos PDF a imágenes. Aspose.BarCode para .NET es un producto igualmente poderoso para generar y reconocer códigos de barras.
La clase PdfConverter bajo el espacio de nombres Aspose.Pdf.Facades admite la conversión de páginas PDF a varios formatos de imagen. El PngDevice bajo el espacio de nombres Aspose.Pdf.Devices admite la conversión de páginas PDF a archivos PNG. Cualquiera de estas clases se puede utilizar para transformar páginas de un archivo PDF en imágenes.
Cuando las páginas se han convertido a un formato de imagen, podemos usar Aspose.BarCode para .NET para identificar códigos de barras dentro de ellas. Los ejemplos de código a continuación muestran cómo convertir páginas utilizando PdfConverter o PngDevice.
La clase PdfConverter contiene un método llamado GetNextImage que genera una imagen de la página PDF actual. Para especificar el formato de imagen de salida, este método acepta un argumento de la enumeración System.Drawing.Imaging.ImageFormat.
Aspose.Barcode contiene un espacio de nombres, BarCodeRecognition, que contiene la clase BarCodeReader. La clase BarCodeReader te permite leer, determinar e identificar códigos de barras de archivos de imagen.
Para los propósitos de este ejemplo, primero convierte una página en un archivo PDF en una imagen con Aspose.Pdf.Facades.PdfConverter. Luego usa la clase Aspose.BarCodeRecognition.BarCodeReader para reconocer el código de barras en la imagen.
// 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();
}
}
En Aspose.Pdf.Devices, está el PngDevice. Esta clase te permite convertir páginas en documentos PDF a imágenes PNG.
Para los propósitos de este ejemplo, carga el archivo PDF de origen en las páginas del documento en imágenes PNG. Cuando se hayan creado las imágenes, usa la clase BarCodeReader bajo Aspose.BarCodeRecognition para identificar y leer códigos de barras en las imágenes.
// 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();
}
}
}
}
Para más información sobre los temas cubiertos en este artículo, visita:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.