![]() | Encode Barcode as PDF |
This sample encodes a text message as a two dimensional QR-Code and saves it as a PDF file.
using Opait.Barcoder.Api; // Encodes a message as QR-Code and saves as a PDF file. static void EncodePdfBarcode(string message, string fileName) { // Initialize the barcoder library with default options. var barcoder = new Barcoder(); // Create a barcode encoder of the specified type and content. var encoder = barcoder.CreateEncoder(BarcodeType.QRCode, message); // Create a PDF renderer for saving the generated barcode. var renderer = barcoder.CreatePdfRenderer(); // Create a new PDF document. using (var pdf = barcoder.CreatePdfDocument()) { // Add a new page to the document. var page = pdf.AddPage(); // Place the barcode in the middle of the page. renderer.RenderBarcode(page, encoder, page.Width / 2 - 100, page.Height / 2 - 100, 200, 200); // Save the PDF file. pdf.Save(fileName); } }