public static void Run()
        {
            try
            {
                // ExStart:CreateAndSetSizeForImageWithBarcode
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageBarCodes();

                // Generate the barcode and set code text, symbology type
                BarCodeBuilder builder = new BarCodeBuilder("One thing 2 thing", EncodeTypes.Pdf417);

                // Set the code text location,  graphics unit and margins
                builder.CodeLocation = CodeLocation.None;
                builder.GraphicsUnit = GraphicsUnit.Pixel;
                builder.Margins.Set(0);
                
                // Get Bitmap with exact barcode only
                Bitmap bmp = builder.GetOnlyBarCodeImage();

                // Allows to set size for whole picture with barcode inside and Save image on local disk
                Bitmap bitmap = builder.GetCustomSizeBarCodeImage(new Size(bmp.Width * 5, bmp.Height * 5), false);
                bitmap.Save(dataDir +  "CreateAndSetSizeForImageWithBarcode_out.Png");
                // ExEnd:CreateAndSetSizeForImageWithBarcode
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
コード例 #2
0
        public static void Run()
        {
            try
            {
                // ExStart:CreateAndSetSizeForImageWithBarcode
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_ManageBarCodes();

                // Generate the barcode and set code text, symbology type
                BarCodeBuilder builder = new BarCodeBuilder("One thing 2 thing", EncodeTypes.Pdf417);

                // Set the code text location,  graphics unit and margins
                builder.CodeLocation = CodeLocation.None;
                builder.GraphicsUnit = GraphicsUnit.Pixel;
                builder.Margins.Set(0);

                // Get Bitmap with exact barcode only
                Bitmap bmp = builder.GetOnlyBarCodeImage();

                // Allows to set size for whole picture with barcode inside and Save image on local disk
                Bitmap bitmap = builder.GetCustomSizeBarCodeImage(new Size(bmp.Width * 5, bmp.Height * 5), false);
                bitmap.Save(dataDir + "CreateAndSetSizeForImageWithBarcode_out.Png");
                // ExEnd:CreateAndSetSizeForImageWithBarcode
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
コード例 #3
0
        public static void InserQrCodes(this Document document, string placeHolder, string barCodeData)
        {
            Regex            regex        = new Regex(string.Format("{{{{{0}}}}}", placeHolder), RegexOptions.IgnoreCase);
            int              maxStrLength = 800;
            FindMatchedNodes searchResult = new FindMatchedNodes();

            document.Range.Replace(regex, searchResult, false);
            foreach (Node node in searchResult.nodes)
            {
                var qrCodeHolder = new Paragraph(document);
                if (!string.IsNullOrEmpty(barCodeData))
                {
                    int maxImagesCount = barCodeData.Length / maxStrLength;
                    int imageIndex     = 0;
                    for (int index = 0; index < barCodeData.Length; index += maxStrLength)
                    {
                        var qrCodeText =
                            barCodeData.Substring(index, Math.Min(maxStrLength, barCodeData.Length - index));
                        BarCodeBuilder barCodeBuilder = new BarCodeBuilder();
                        barCodeBuilder.SymbologyType = Symbology.QR;
                        barCodeBuilder.CodeText      = qrCodeText;
                        barCodeBuilder.CodeLocation  = CodeLocation.None;
                        barCodeBuilder.GraphicsUnit  = GraphicsUnit.Pixel;
                        barCodeBuilder.Margins.Set(0);

                        // Allows to set size for whole picture with barcode inside and Save image on local disk
                        Bitmap       bitmap = barCodeBuilder.GetCustomSizeBarCodeImage(new Size(150, 150), false);
                        MemoryStream img    = new MemoryStream();
                        bitmap.Save(img, ImageFormat.Png);
                        img.Position = 0;
                        Shape image = new Shape(document, ShapeType.Image);
                        image.ImageData.SetImage(img);
                        image.Left          = 0;
                        image.Top           = 0;
                        image.Width         = (double)image.ImageData.ImageSize.WidthPixels * 72 / 96;
                        image.Height        = (double)image.ImageData.ImageSize.HeightPixels * 72 / 96;
                        image.DistanceLeft  = 0;
                        image.DistanceRight = 0;
                        image.WrapType      = WrapType.Inline;
                        qrCodeHolder.AppendChild(image);
                        if (imageIndex < maxImagesCount)
                        {
                            qrCodeHolder.AppendChild(new Run(document, "  "));
                        }
                        imageIndex++;
                    }
                    node.ParentNode.ParentNode.InsertAfter(qrCodeHolder, node.ParentNode);
                }
                node.ParentNode.Remove();
            }
        }
コード例 #4
0
        public static void InsertDocUrl(this Aspose.Words.Document document, string url)
        {
            var builder = new DocumentBuilder(document);

            builder.MoveToDocumentEnd();
            var linkH = builder.InsertParagraph();

            linkH.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            linkH.AppendChild(new Run(document, "Ссылка на оригинал"));
            var linkP = builder.InsertParagraph();

            linkP.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            BarCodeBuilder barCodeBuilder = new BarCodeBuilder();

            barCodeBuilder.SymbologyType = Symbology.QR;
            barCodeBuilder.QRErrorLevel  = QRErrorLevel.LevelM;
            barCodeBuilder.CodeText      = url;
            barCodeBuilder.CodeLocation  = CodeLocation.None;
            barCodeBuilder.GraphicsUnit  = GraphicsUnit.Pixel;
            barCodeBuilder.QREncodeType  = QREncodeType.ForceQR;
            barCodeBuilder.Margins.Set(0);
            // Allows to set size for whole picture with barcode inside and Save image on local disk
            Bitmap       bitmap = barCodeBuilder.GetCustomSizeBarCodeImage(new Size(35, 35), false);
            MemoryStream img    = new MemoryStream();

            bitmap.Save(img, ImageFormat.Png);
            img.Position = 0;
            Shape image = new Shape(document, ShapeType.Image);

            image.ImageData.SetImage(img);
            image.Left          = 0;
            image.Top           = 0;
            image.Width         = (double)image.ImageData.ImageSize.WidthPixels * 72 / 96;
            image.Height        = (double)image.ImageData.ImageSize.HeightPixels * 72 / 96;
            image.DistanceLeft  = 0;
            image.DistanceRight = 0;
            image.WrapType      = WrapType.Inline;
            linkP.AppendChild(image);
        }