Exemple #1
0
        public static ShapeBase CreateBarcodeEntity(float scaleFactor)
        {
            LinearBarcode barcode = new LinearBarcode();

            barcode.Text         = "1234";
            barcode.Height       = 6 * scaleFactor;
            barcode.Width        = 12 * scaleFactor;
            barcode.Location.X   = -20 * scaleFactor;
            barcode.Location.Y   = 20 * scaleFactor;
            barcode.BarcodeType  = BarcodeType.Codabar;
            barcode.HatchPattern = BarcodeHatchPattern.CreateLineHatchPattern(0.025f * scaleFactor, true, true);
            barcode.Color        = Color.Black;

            return(barcode);
        }
Exemple #2
0
		/// <summary>
		/// 	生成订单号的一维码图片
		/// </summary>
		/// <param name = "orderNumber"></param>
		public static void SaveBarcode(string orderNumber) {
			LinearBarcode myBarCode = new LinearBarcode();
			myBarCode.SymbologyID = LinearBarcode.Symbologies.Code128;
			myBarCode.DataToEncode = orderNumber;
			myBarCode.TopMarginCM = "1";
			myBarCode.LeftMarginCM = "1";
			
			myBarCode.BarHeightCM = "7"; //(200 / 500 * 0.54).ToString();
			myBarCode.WhiteBarIncrease = "2000";
			myBarCode.ImageType = LinearBarcode.ImageTypes.PNG;

			myBarCode.ImageResolution = 100;
			myBarCode.Font.Size = new FontUnit(12);
			myBarCode.ShowText = false;
			myBarCode.SaveImageAs("R:\\barcode\\" + orderNumber.Replace("D#", "") + ".png", ImageFormat.Png);
		}
        /// <summary>
        /// Generates a barcode image according to the users settings and returns it
        /// </summary>
        public Image GetImage()
        {
            var barcode = new LinearBarcode(txtData.Text, (Symbology)Enum.Parse(typeof(Symbology), ((ComboboxItem)cboSymbology.SelectedItem).Value))
            {
                Encoder =
                {
                    Quietzone     = chkIncludeQuitezone.Checked,
                    TargetWidth   = (int)numTargetWidth.Value,
                    BarcodeHeight = (int)numHeight.Value,
                    XDimension    = (int)numXDimension.Value,
                    Dpi           = (int)numDPI.Value,
                }
            };

            barcode.Encoder.HumanReadableValue = txtText.Text;
            barcode.Encoder.SetHumanReadableFont(cboFontFamily.Text, (int)numFontSize.Value);
            barcode.Encoder.SetHumanReadablePosition(cboPosition.Text);

            return(barcode.Image);
        }
Exemple #4
0
        private static void AddLinearBarcode(VectorImage vectorImage, LinearBarcode linearBarcode, DistanceUnit currentUnit)
        {
            LinearBarcodeShape barcode = new LinearBarcodeShape();

            barcode.Text        = linearBarcode.Text;
            barcode.BarcodeType = linearBarcode.BarcodeType;

            barcode.Height           = linearBarcode.Height;
            barcode.InvertImage      = linearBarcode.InvertImage;
            barcode.QuietZone        = linearBarcode.QuietZone;
            barcode.Angle            = linearBarcode.Angle;
            barcode.PrintRatio       = linearBarcode.PrintRatio;
            barcode.Width            = linearBarcode.Width;
            barcode.FlipHorizontally = linearBarcode.FlipHorizontally;
            barcode.FlipVertically   = linearBarcode.FlipVertically;
            barcode.MarkingOrder     = linearBarcode.MarkingOrder;
            barcode.Angle            = linearBarcode.Angle;

            barcode.HatchPattern = linearBarcode.HatchPattern;

            barcode.Location = linearBarcode.Location.Clone();
            vectorImage.AddBarcodeShape(barcode);
        }
        /// <summary>
        /// Create the watermarks.
        /// </summary>
        /// <returns>An array of watermarks to apply</returns>
        public static Watermark[] CreateWatermarks()
        {
            List <Watermark> watermarks = new List <Watermark>();

            // ** Specify the default settings for properties
            Defaults wmDefaults = new Defaults();

            wmDefaults.FillColor      = "#000000";
            wmDefaults.LineColor      = "#000000";
            wmDefaults.FontFamilyName = "Arial";
            wmDefaults.FontSize       = "10";

            // **************** 'Confidential' Text ***************

            // ** 'Confidential' watermark for front page
            Watermark confidential = new Watermark();

            confidential.Defaults  = wmDefaults;
            confidential.Rotation  = "-45";
            confidential.Width     = "500";
            confidential.Height    = "500";
            confidential.HPosition = HPosition.Center;
            confidential.VPosition = VPosition.Middle;
            confidential.ZOrder    = -1;
            // ** For PowerPoint traditional page numbering is used
            confidential.StartPage = 1;
            confidential.EndPage   = 1;
            // ** In case of Word and Excel this only appears on pages which has 'First Page Header'
            confidential.PageType = PageType.First;

            // ** Create a new Text element that goes inside the watermark
            Text cfText = new Text();

            cfText.Content      = "Confidential";
            cfText.FontSize     = "40";
            cfText.FontStyle    = FontStyle.Bold | FontStyle.Italic;
            cfText.Width        = "500";
            cfText.Height       = "500";
            cfText.Transparency = "0.10";

            // ** And add it to the list of watermark elements.
            confidential.Elements = new Element[] { cfText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(confidential);


            // **************** Watermark for Odd pages ***************

            Watermark oddPages = new Watermark();

            oddPages.Defaults  = wmDefaults;
            oddPages.Width     = "600";
            oddPages.Height    = "50";
            oddPages.HPosition = HPosition.Right;
            oddPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            oddPages.StartPage = 3;
            oddPages.EndPage   = 2;
            // ** In case of Word and Excel this only appears on pages which has 'Odd Page Header'
            oddPages.PageType = PageType.Default;

            // ** Add a horizontal line
            Line line = new Line();

            line.X     = "1";
            line.Y     = "1";
            line.EndX  = "600";
            line.EndY  = "1";
            line.Width = "5";

            // ** Add a page counter
            Text oddText = new Text();

            oddText.Content   = "Page: {PAGE} of {NUMPAGES}";
            oddText.Width     = "100";
            oddText.Height    = "20";
            oddText.X         = "475";
            oddText.Y         = "15";
            oddText.LineWidth = "-1";
            oddText.FontStyle = FontStyle.Regular;
            oddText.HAlign    = HAlign.Right;

            // ** And add it to the list of watermark elements
            oddPages.Elements = new Element[] { line, oddText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(oddPages);

            // **************** Watermark for Even pages ***************

            Watermark evenPages = new Watermark();

            evenPages.Defaults  = wmDefaults;
            evenPages.Width     = "600";
            evenPages.Height    = "50";
            evenPages.HPosition = HPosition.Left;
            evenPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            evenPages.StartPage    = 2;
            evenPages.PageInterval = 2;
            // ** In case of Word and Excel this only appears on pages which has 'Even Page Header'
            evenPages.PageType = PageType.Even;

            // ** No need to create an additional line,re-use the previous one

            // ** Add a page counter
            Text evenText = new Text();

            evenText.Content   = "Page: {PAGE} of {NUMPAGES}";
            evenText.Width     = "100";
            evenText.Height    = "20";
            evenText.X         = "25";
            evenText.Y         = "15";
            evenText.LineWidth = "-1";
            evenText.FontStyle = FontStyle.Regular;
            evenText.HAlign    = HAlign.Left;

            // ** And add it to the list of watermark elements
            evenPages.Elements = new Element[] { line, evenText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(evenPages);

            // **************** Watermark for all pages except first ***************

            Watermark contentPages = new Watermark();

            contentPages.Defaults  = wmDefaults;
            contentPages.Width     = "200";
            contentPages.Height    = "85";
            contentPages.HPosition = HPosition.Center;
            contentPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            contentPages.StartPage = 2;
            // ** In case of Word and Excel this only appears on pages which does not have 'First Page Header'
            contentPages.PageType = PageType.Even | PageType.Default;

            // ** Add a barcode
            LinearBarcode barcode = new LinearBarcode();

            barcode.Text        = "012345678";
            barcode.BarcodeType = BarcodeType.Code39;
            // ** Change fill color to white because wmDefaults defines it as black
            barcode.FillColor = "#ffffff";
            barcode.LineColor = "#000000";
            barcode.Width     = "200";
            barcode.Height    = "50";
            barcode.HPosition = HPosition.Center;
            barcode.VPosition = VPosition.Top;

            // ** And add it to the list of watermark elements
            contentPages.Elements = new Element[] { barcode };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(contentPages);

            return(watermarks.ToArray());
        }