/// <summary>
 /// Gets the barcode image URI for the specified text using the
 /// Code 128 barcode symbology.
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public string GetBarcode128(string text)
 {
     BarcodeImageUriBuilder uri = new BarcodeImageUriBuilder ();
     uri.Text = text;
     uri.EncodingScheme = BarcodeSymbology.Code93;
     uri.BarMinHeight = uri.BarMaxHeight = 30;
     uri.BarMinWidth = uri.BarMaxWidth = 1;
     return uri.ToString ();
 }
        /// <summary>
        /// Gets the barcode image URI for the specified text using the
        /// Code 128 barcode symbology.
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public string GetBarcode128(string text)
        {
            BarcodeImageUriBuilder uri = new BarcodeImageUriBuilder();

            uri.Text           = text;
            uri.EncodingScheme = BarcodeSymbology.Code93;
            uri.BarMinHeight   = uri.BarMaxHeight = 30;
            uri.BarMinWidth    = uri.BarMaxWidth = 1;
            return(uri.ToString());
        }
示例#3
0
        /// <summary>
        /// Generates a barcode URI.
        /// </summary>
        /// <param name="helper">The HTML helper.</param>
        /// <param name="text">The text to be encoded.</param>
        /// <param name="symbology">The barcode symbology to use.</param>
        /// <param name="height">The height.</param>
        /// <param name="scale">
        /// The scale factor to use (null = use default for symbology).
        /// </param>
        /// <param name="useExtensionlessUri">
        /// <c>true</c> to use extensionless URI; otherwise, <c>false</c>.
        /// </param>
        /// <returns></returns>
        public static string Barcode(
            this UrlHelper helper,
            string text,
            BarcodeSymbology symbology,
            int height = 30,
            int?scale  = null,
            bool useExtensionlessUri = true)
        {
            BarcodeImageUriBuilder builder = null;

            // We cheat and get the default metrics
            var temp    = BarcodeDrawFactory.GetSymbology(symbology);
            var metrics = temp.GetDefaultMetrics(height);

            if (scale != null)
            {
                metrics.Scale = scale.Value;
            }
            BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;

            if (metrics1d != null)
            {
                builder =
                    new BarcodeImageUriBuilder
                {
                    EncodingScheme      = symbology,
                    Text                = text,
                    BarMaxHeight        = metrics1d.MaxHeight,
                    BarMinHeight        = metrics1d.MinHeight,
                    BarMaxWidth         = metrics1d.MaxWidth,
                    BarMinWidth         = metrics1d.MinWidth,
                    Scale               = metrics.Scale,
                    UseExtensionlessUri = useExtensionlessUri
                };
            }
            else
            {
                BarcodeMetricsQr metricsQr = metrics as BarcodeMetricsQr;
                if (metricsQr != null)
                {
                    builder =
                        new BarcodeImageUriBuilder
                    {
                        EncodingScheme      = BarcodeSymbology.CodeQr,
                        Text                = text,
                        QrEncodingMode      = metricsQr.EncodeMode,
                        QrErrorCorrect      = metricsQr.ErrorCorrection,
                        QrVersion           = metricsQr.Version,
                        Scale               = metrics.Scale,
                        UseExtensionlessUri = useExtensionlessUri
                    };
                }
            }
            return(helper.Content(builder.ToString()));
        }
        /// <summary>
        /// Generates a barcode URI.
        /// </summary>
        /// <param name="helper">The HTML helper.</param>
        /// <param name="text">The text to be encoded.</param>
        /// <param name="symbology">The barcode symbology to use.</param>
        /// <param name="height">The height.</param>
        /// <param name="scale">
        /// The scale factor to use (null = use default for symbology).
        /// </param>
        /// <param name="useExtensionlessUri">
        /// <c>true</c> to use extensionless URI; otherwise, <c>false</c>.
        /// </param>
        /// <returns></returns>
        public static string Barcode(
            this UrlHelper helper,
            string text,
            BarcodeSymbology symbology,
            int height = 30,
            int? scale = null,
            bool useExtensionlessUri = true)
        {
            BarcodeImageUriBuilder builder = null;

            // We cheat and get the default metrics
            var temp = BarcodeDrawFactory.GetSymbology(symbology);
            var metrics = temp.GetDefaultMetrics(height);
            if (scale != null)
            {
                metrics.Scale = scale.Value;
            }
            BarcodeMetrics1d metrics1d = metrics as BarcodeMetrics1d;
            if (metrics1d != null)
            {
                builder =
                    new BarcodeImageUriBuilder
                    {
                        EncodingScheme = symbology,
                        Text = text,
                        BarMaxHeight = metrics1d.MaxHeight,
                        BarMinHeight = metrics1d.MinHeight,
                        BarMaxWidth = metrics1d.MaxWidth,
                        BarMinWidth = metrics1d.MinWidth,
                        Scale = metrics.Scale,
                        UseExtensionlessUri = useExtensionlessUri
                    };
            }
            else
            {
                BarcodeMetricsQr metricsQr = metrics as BarcodeMetricsQr;
                if (metricsQr != null)
                {
                    builder =
                        new BarcodeImageUriBuilder
                        {
                            EncodingScheme = BarcodeSymbology.CodeQr,
                            Text = text,
                            QrEncodingMode = metricsQr.EncodeMode,
                            QrErrorCorrect = metricsQr.ErrorCorrection,
                            QrVersion = metricsQr.Version,
                            Scale = metrics.Scale,
                            UseExtensionlessUri = useExtensionlessUri
                        };
                }
            }
            return helper.Content(builder.ToString());
        }