BackgroundColor

BarcodeParameters.BackgroundColor property

Bar code background color (0x000000 - 0xFFFFFF)

public string BackgroundColor { get; set; }

Examples

Shows how to use a barcode generator.

Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            // We can use a custom IBarcodeGenerator implementation to generate barcodes,
            // and then insert them into the document as images.
            doc.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();

            // Below are four examples of different barcode types that we can create using our generator.
            // For each barcode, we specify a new set of barcode parameters, and then generate the image.
            // Afterwards, we can insert the image into the document, or save it to the local file system.
            // 1 -  QR code:
            BarcodeParameters barcodeParameters = new BarcodeParameters
            {
                BarcodeType = "QR",
                BarcodeValue = "ABC123",
                BackgroundColor = "0xF8BD69",
                ForegroundColor = "0xB5413B",
                ErrorCorrectionLevel = "3",
                ScalingFactor = "250",
                SymbolHeight = "1000",
                SymbolRotation = "0"
            };

            Image img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET461_OR_GREATER || JAVA
            img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.QR.jpg");
#elif NET5_0_OR_GREATER
            using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.QR.jpg"))
            {
                img.Encode(fs, SKEncodedImageFormat.Jpeg, 100);
            }
#endif
            builder.InsertImage(img);

            // 2 -  EAN13 barcode:
            barcodeParameters = new BarcodeParameters
            {
                BarcodeType = "EAN13",
                BarcodeValue = "501234567890",
                DisplayText = true,
                PosCodeStyle = "CASE",
                FixCheckDigit = true
            };

            img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET461_OR_GREATER || JAVA
            img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.EAN13.jpg");
#elif NET5_0_OR_GREATER
            using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.EAN13.jpg"))
            {
                img.Encode(fs, SKEncodedImageFormat.Jpeg, 100);
            }
#endif
            builder.InsertImage(img);

            // 3 -  CODE39 barcode:
            barcodeParameters = new BarcodeParameters
            {
                BarcodeType = "CODE39",
                BarcodeValue = "12345ABCDE",
                AddStartStopChar = true
            };

            img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET461_OR_GREATER || JAVA
            img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.CODE39.jpg");
#elif NET5_0_OR_GREATER
            using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.CODE39.jpg"))
            {
                img.Encode(fs, SKEncodedImageFormat.Jpeg, 100);
            }
#endif
            builder.InsertImage(img);

            // 4 -  ITF14 barcode:
            barcodeParameters = new BarcodeParameters
            {
                BarcodeType = "ITF14",
                BarcodeValue = "09312345678907",
                CaseCodeStyle = "STD"
            };

            img = doc.FieldOptions.BarcodeGenerator.GetBarcodeImage(barcodeParameters);
#if NET461_OR_GREATER || JAVA
            img.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.ITF14.jpg");
#elif NET5_0_OR_GREATER
            using (SKFileWStream fs = new SKFileWStream(ArtifactsDir + "FieldOptions.BarcodeGenerator.ITF14.jpg"))
            {
                img.Encode(fs, SKEncodedImageFormat.Jpeg, 100);
            }
#endif            
            builder.InsertImage(img);

            doc.Save(ArtifactsDir + "FieldOptions.BarcodeGenerator.docx");

See Also