Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET é um produto muito poderoso para gerenciar documentos PDF. Ele facilita a conversão de páginas em documentos PDF em imagens. Aspose.BarCode para .NET é um produto igualmente poderoso para gerar e reconhecer códigos de barras.
A classe PdfConverter sob o namespace Aspose.Pdf.Facades suporta a conversão de páginas PDF em vários formatos de imagem. O PngDevice sob o namespace Aspose.Pdf.Devices suporta a conversão de páginas PDF em arquivos PNG. Qualquer uma dessas classes pode ser usada para transformar páginas de um arquivo PDF em imagens.
Quando as páginas foram convertidas para um formato de imagem, podemos usar Aspose.BarCode para .NET para identificar códigos de barras dentro delas. Os exemplos de código abaixo mostram como converter páginas usando PdfConverter ou PngDevice.
A classe PdfConverter contém um método chamado GetNextImage que gera uma imagem da página PDF atual. Para especificar o formato da imagem de saída, este método aceita um argumento da enumeração System.Drawing.Imaging.ImageFormat.
Aspose.Barcode contém um namespace, BarCodeRecognition, que contém a classe BarCodeReader. A classe BarCodeReader permite que você leia, determine e identifique códigos de barras a partir de arquivos de imagem.
Para os propósitos deste exemplo, primeiro converta uma página em um arquivo PDF em uma imagem com Aspose.Pdf.Facades.PdfConverter. Em seguida, use a classe Aspose.BarCodeRecognition.BarCodeReader para reconhecer o código de barras na imagem.
// 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();
    }
}
No Aspose.Pdf.Devices, está o PngDevice. Esta classe permite que você converta páginas em documentos PDF em imagens PNG.
Para os propósitos deste exemplo, carregue o arquivo PDF de origem nas páginas do Documento] cument’s pages into PNG images. Quando as imagens forem criadas, use a classe BarCodeReader sob o Aspose.BarCodeRecognition para identificar e ler códigos de barras nas imagens.
// 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 mais informações sobre os tópicos abordados neste artigo, vá para:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.