//! Barcode Demo - Code128 and QR barcodes //! //! Demonstrates barcode generation for product labels, shipping, URLs, etc. const std = @import("std"); const zpdf = @import("zpdf"); const Pdf = zpdf.Pdf; const Color = zpdf.Color; const QRCode = zpdf.QRCode; pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); var pdf = Pdf.init(allocator, .{}); defer pdf.deinit(); pdf.setTitle("Barcode Demo"); pdf.setAuthor("zpdf"); var page = try pdf.addPage(.{}); // Title try page.setFont(.helvetica_bold, 28); page.setFillColor(Color.hex(0x333333)); try page.drawText(50, 780, "Barcode Demo"); try page.setFont(.helvetica, 12); page.setFillColor(Color.hex(0x666666)); try page.drawText(50, 760, "Code128 barcode generation with zpdf"); // Reset to black for barcodes page.setFillColor(Color.black); try page.setFont(.helvetica, 10); // Section 1: Basic Barcodes try page.setFont(.helvetica_bold, 16); try page.drawText(50, 720, "Basic Code128 Barcodes"); try page.setFont(.courier, 10); // Simple text try page.drawText(50, 690, "Product Code:"); try page.drawCode128WithText(170, 650, "ABC-12345", 50, 1.5, true); // Numbers only (will use Code C for efficiency) try page.drawText(50, 580, "Serial Number:"); try page.drawCode128WithText(170, 540, "9876543210", 50, 1.5, true); // Mixed content try page.drawText(50, 470, "SKU:"); try page.drawCode128WithText(170, 430, "ITEM-2024-XYZ", 50, 1.5, true); // Section 2: Different Sizes try page.setFont(.helvetica_bold, 16); page.setFillColor(Color.black); try page.drawText(50, 370, "Different Sizes"); try page.setFont(.courier, 10); // Small barcode try page.drawText(50, 340, "Small (0.8 module):"); try page.drawCode128(170, 320, "SMALL", 30, 0.8); // Medium barcode try page.drawText(50, 280, "Medium (1.2 module):"); try page.drawCode128(170, 250, "MEDIUM", 40, 1.2); // Large barcode try page.drawText(50, 200, "Large (2.0 module):"); try page.drawCode128(170, 150, "LARGE", 60, 2.0); // Section 3: Real-world Examples try page.setFont(.helvetica_bold, 16); try page.drawText(350, 720, "Real-world Examples"); try page.setFont(.helvetica, 10); // Shipping label try page.drawText(350, 690, "Shipping Label:"); try page.drawCode128WithText(350, 640, "1Z999AA10123456784", 45, 1.2, true); // Invoice number try page.drawText(350, 580, "Invoice #:"); try page.drawCode128WithText(350, 535, "INV-2024-00123", 40, 1.3, true); // ISBN-like try page.drawText(350, 470, "ISBN:"); try page.drawCode128WithText(350, 425, "978-0-123456-78-9", 45, 1.2, true); // Warehouse location try page.drawText(350, 360, "Location:"); try page.drawCode128WithText(350, 315, "A-12-B-34", 40, 1.5, true); // Section 4: QR Codes try page.setFont(.helvetica_bold, 16); page.setFillColor(Color.black); try page.drawText(350, 250, "QR Codes"); try page.setFont(.helvetica, 10); // URL QR Code try page.drawText(350, 225, "Website URL:"); try page.drawQRCode(350, 120, "HTTPS://GITHUB.COM", 100, QRCode.ErrorCorrection.M); // Simple text try page.drawText(480, 225, "Text Data:"); try page.drawQRCode(480, 120, "HELLO WORLD", 100, QRCode.ErrorCorrection.H); // Footer try page.setFont(.helvetica_oblique, 10); page.setFillColor(Color.hex(0x999999)); try page.drawText(50, 50, "Generated with zpdf - Code128 and QR Code Support"); try pdf.save("barcode_demo.pdf"); std.debug.print("Generated barcode_demo.pdf\n", .{}); }