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 for .NETも、バーコードを生成および認識するための同様に強力な製品です。
Aspose.Pdf.Facades名前空間のPdfConverterクラスは、PDFページをさまざまな画像形式に変換することをサポートしています。Aspose.Pdf.Devices名前空間のPngDeviceは、PDFページをPNGファイルに変換することをサポートしています。これらのクラスのいずれかを使用して、PDFファイルのページを画像に変換できます。
ページが画像形式に変換されたら、Aspose.BarCode for .NETを使用してその中のバーコードを識別できます。以下のコードサンプルは、PdfConverterまたはPngDeviceを使用してページを変換する方法を示しています。
PdfConverterクラスには、現在のPDFページから画像を生成するGetNextImageというメソッドがあります。出力画像形式を指定するために、このメソッドはSystem.Drawing.Imaging.ImageFormat列挙体からの引数を受け入れます。
Aspose.Barcodeには、BarCodeRecognitionという名前空間があり、BarCodeReaderクラスが含まれています。BarCodeReaderクラスを使用すると、画像ファイルからバーコードを読み取り、判断し、識別できます。
この例の目的のために、まずAspose.Pdf.Facades.PdfConverterを使用してPDFファイルのページを画像に変換します。次に、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画像に変換します。画像が作成されたら、Aspose.BarCodeRecognitionのBarCodeReaderクラスを使用して画像内のバーコードを識別し、読み取ります。
// 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.