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 المصدر إلى صفحات المستند وتحويلها إلى صور 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.