이 빠른 튜토리얼은 C#을 사용하여 PDF를 QR 코드로 변환하는 방법을 안내합니다. 여기에는 개발을 위한 IDE 설정 방법과 C#을 사용하여 PDF를 바코드로 변환하는 단계 목록이 포함되어 있습니다. PDF에서 모든 바코드와 QR 코드를 추출하고 각각의 텍스트를 표시하는 방법을 배우게 됩니다.
C#을 사용하여 PDF를 QR 코드로 변환하는 단계
- Aspose.PDF 및 Aspose.BarCode for .NET을 사용하여 QR 코드와 바코드를 읽도록 IDE를 설정합니다
- Document 객체를 사용하여 QR 코드와 바코드가 포함된 소스 PDF를 로드합니다
- PDF의 모든 페이지를 반복하고 각 페이지의 이미지 컬렉션을 처리합니다
- 각 이미지를 JPG로 메모리 스트림에 저장합니다
- BarCodeReader 객체를 인스턴스화하고 이미지 메모리 스트림과 대상 디코드 유형을 전달합니다
- 이미지의 모든 바코드와 QR 코드 컬렉션을 파싱합니다
- 감지된 코드의 텍스트와 유형을 표시합니다
이 단계는 C#을 사용하여 PDF를 QR 코드로 변환하는 방법을 설명합니다. Aspose.PDF와 Aspose.BarCode를 모두 사용하도록 환경을 설정하고, QR 코드와 바코드가 포함된 소스 PDF 파일을 로드하고, 모든 또는 선택한 페이지를 반복하고, 각 페이지의 이미지 컬렉션을 추출합니다. 각 이미지를 메모리 스트림에 저장하고, BarCodeReader에서 QR 코드와 바코드를 읽고, 마지막으로 코드의 텍스트와 유형을 표시합니다.
C#을 사용한 PDF에서 QR 코드로의 변환기 코드
// Necessary using directives | |
using Aspose.Pdf; | |
using System.IO; | |
using Aspose.BarCode.BarCodeRecognition; | |
// Custom namespace for the application | |
namespace DocumentProcessor | |
{ | |
// Core class of the application | |
class BarcodeExtractor | |
{ | |
// Application's entry method | |
static void Main(string[] args) | |
{ | |
// Set up licenses for Aspose.PDF and Aspose.BarCode | |
var pdfLicense = new Aspose.Pdf.License(); | |
pdfLicense.SetLicense("License.lic"); | |
var barcodeLicense = new Aspose.BarCode.License(); | |
barcodeLicense.SetLicense("License.lic"); | |
// Load the PDF file | |
using (var pdfDocument = new Document("bar_qr_code.pdf")) | |
{ | |
// Iterate through each page in the PDF | |
for (int pageIndex = 1; pageIndex <= pdfDocument.Pages.Count; pageIndex++) | |
{ | |
var page = pdfDocument.Pages[pageIndex]; | |
// Check if the page contains images | |
if (page.Resources.Images.Count > 0) | |
{ | |
// Process each image in the page | |
foreach (var image in page.Resources.Images) | |
{ | |
using (var imgStream = new MemoryStream()) | |
{ | |
// Save the image to a memory stream in JPEG format | |
image.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg); | |
imgStream.Position = 0; // Reset stream position | |
// Initialize the barcode reader for the image | |
var reader = new BarCodeReader(imgStream, DecodeType.AllSupportedTypes); | |
// Retrieve and display barcode results | |
foreach (var result in reader.ReadBarCodes()) | |
{ | |
var barcodeText = result.CodeText; | |
var barcodeType = result.CodeTypeName; | |
System.Console.WriteLine($"Detected {barcodeType} with content: {barcodeText}"); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
위의 코드는 C#을 사용하여 PDF에서 QR 코드를 생성하는 프로세스를 보여줍니다. PDF의 모든 페이지를 분석하고 각 페이지의 이미지 컬렉션을 사용하여 QR과 바코드를 감지합니다. 하나의 이미지에는 하나 이상의 QR/바코드가 포함될 수 있으며, ReadBarCodes() 메서드로 읽고 하나씩 처리하며 텍스트와 코드를 표시합니다.
이 튜토리얼은 PDF를 QR 코드로 변환하는 방법을 안내했습니다. 새로운 QR 또는 바코드를 생성하려면 C#에서 QR 코드를 생성하는 방법 문서를 참조하십시오.