Skip to main content
All docs
V26.1
  • BarcodeGenerator.ExportToPdf(String, Encoding, Stream) Method

    Exports a barcode to PDF format.

    Namespace: DevExpress.Docs.Barcode

    Assembly: DevExpress.Docs.Barcode.v26.1.dll

    Declaration

    public void ExportToPdf(
        string text,
        Encoding encoding,
        Stream stream
    )

    Parameters

    Name Type Description
    text String

    The text to encode in the barcode.

    encoding Encoding

    The text encoding type.

    stream Stream

    The stream to which the PDF document is written.

    Remarks

    The following code snippet exports a barcode to PDF format and then saves it to a file using the PdfDocument class:

    using DevExpress.Docs;
    using DevExpress.Docs.Barcode;
    using DevExpress.Docs.Pdf;
    using System.Drawing;
    
    namespace ConsoleApp1;
    
    public class Program {
        public static async Task Main(string[] _) {
    
            // Configure QR code options.
            QRCodeOptions qrOptions = new QRCodeOptions {
                ErrorCorrectionLevel = QRCodeErrorCorrectionLevel.H,
                CompactionMode = QRCodeCompactionMode.Auto,
                IncludeQuietZone = false,
                Version = QRCodeVersion.Version10,
                ModuleSize = 40,
                BackColor = Color.LightGray,
                ShowText = false,
                Padding = new Padding(5),
                BorderWidth = 1,
                BorderColor = Color.Blue,
                Width = 500,
                Height = 500,
            };
    
            using BarcodeGenerator generator = new BarcodeGenerator(qrOptions);
    
            // Export the barcode as PDF.
            using MemoryStream pdfMemoryStream = new MemoryStream();
            generator.ExportToPdf("https://example.com", Encoding.UTF8, pdfMemoryStream);
            pdfMemoryStream.Position = 0;
    
            // Create a PDF document from the stream, add text to it, and save it to a file.
            using PdfDocument pdfDocument = new PdfDocument(pdfMemoryStream);
            pdfDocument.Pages[0].AddTextFragment("Scan it", 60, 300);
            using FileStream outputStream = new FileStream(@"D:\output.pdf", FileMode.Create, FileAccess.Write);
            pdfDocument.Save(outputStream);
    }
    
    See Also