예제 #1
0
        public static void Run()
        {
            // ExStart:AddImageStamp
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddImageStamp.pdf");

            // Create image stamp
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            imageStamp.Background = true;
            imageStamp.XIndent    = 100;
            imageStamp.YIndent    = 100;
            imageStamp.Height     = 300;
            imageStamp.Width      = 300;
            imageStamp.Rotate     = Rotation.on270;
            imageStamp.Opacity    = 0.5;
            // Add stamp to particular page
            pdfDocument.Pages[1].AddStamp(imageStamp);

            dataDir = dataDir + "AddImageStamp_out.pdf";
            // Save output document
            pdfDocument.Save(dataDir);
            // ExEnd:AddImageStamp
            Console.WriteLine("\nImage stamp added successfully.\nFile saved at " + dataDir);
        }
예제 #2
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            //Open document
            Document pdfDocument = new Document(dataDir+ "AddImageStamp.pdf");

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");
            imageStamp.Background = true;
            imageStamp.XIndent = 100;
            imageStamp.YIndent = 100;
            imageStamp.Height = 300;
            imageStamp.Width = 300;
            imageStamp.Rotate = Rotation.on270;
            imageStamp.Opacity = 0.5;
            //Add stamp to particular page
            pdfDocument.Pages[1].AddStamp(imageStamp);

            //Save output document
            pdfDocument.Save(dataDir + "AddImageStamp_out.pdf");
            
            
        }
예제 #3
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            //open document
            Document pdfDocument = new Document(dataDir+ "ImageinHeader.pdf");

            //create header
            ImageStamp imageStamp = new ImageStamp(dataDir+ "aspose-logo.jpg");
            //set properties of the stamp
            imageStamp.TopMargin = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment = VerticalAlignment.Top;
            //add header on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }

            //save updated document
            pdfDocument.Save(dataDir+ "ImageinHeader_out.pdf");
            
            
        }
예제 #4
0
        public static void Run()
        {
            // ExStart:ImageInFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "ImageInFooter.pdf");
            // Create footer
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            // Set properties of the stamp
            imageStamp.BottomMargin        = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment   = VerticalAlignment.Bottom;
            // Add footer on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }
            dataDir = dataDir + "ImageInFooter_out_.pdf";
            // Save updated PDF file
            pdfDocument.Save(dataDir);
            // ExEnd:ImageInFooter
            Console.WriteLine("\nImage in footer added successfully.\nFile saved at " + dataDir);
        }
예제 #5
0
        public bool AddDigitalSignature(Pages PageObj, List <ImageSignParameters> ImgParamObj)
        {
            var pdfDocument = new Aspose.Pdf.Document(PageObj.FilePath);

            foreach (ImageSignParameters obj in ImgParamObj)
            {
                //add image signature parameters to database
                _documentRepository.AddSignatureToDB(obj);


                Stream     stream     = new MemoryStream(obj.ImageStream);
                ImageStamp imageStamp = new ImageStamp(stream);
                imageStamp.Background = true;
                // imageStamp.VerticalAlignment = VerticalAlignment.Top;
                imageStamp.XIndent = obj.XIndent;
                imageStamp.YIndent = obj.YIndent;
                imageStamp.Height  = obj.Height;
                imageStamp.Width   = obj.Width;
                imageStamp.Opacity = obj.Opacity;
                pdfDocument.Pages[obj.PageNumber].AddStamp(imageStamp);
            }
            pdfDocument.Save(string.Format("D:\\ElectronicSignaturesService\\BusinessLogic\\Files\\Sign1{0}.pdf", DateTime.Now.Ticks));

            return(true);
        }
        public static void Run()
        {
            // ExStart:ImageInFooter
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open document
            Document pdfDocument = new Document(dataDir+ "ImageInFooter.pdf");
            // Create footer
            ImageStamp imageStamp = new ImageStamp(dataDir+ "aspose-logo.jpg");
            // Set properties of the stamp
            imageStamp.BottomMargin = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment = VerticalAlignment.Bottom;
            // Add footer on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }
            dataDir = dataDir + "ImageInFooter_out.pdf";
            // Save updated PDF file
            pdfDocument.Save(dataDir);
            // ExEnd:ImageInFooter
            Console.WriteLine("\nImage in footer added successfully.\nFile saved at " + dataDir);
        }
예제 #7
0
        //===================================================================================================== Generate documents

        protected Stream GetPreviewImagesPdfStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Pdf);

            try
            {
                var ms       = new MemoryStream();
                var pdf      = new Pdf();
                var document = new Aspose.Pdf.Document(pdf);
                var index    = 1;

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    using (var imgStream = GetRestrictedImage(previewImage, restrictionType: restrictionType))
                    {
                        int newWidth;
                        int newHeight;

                        ComputeResizedDimensions((int)previewImage["Width"], (int)previewImage["Height"], PREVIEW_PDF_WIDTH, PREVIEW_PDF_HEIGHT, out newWidth, out newHeight);

                        var imageStamp = new ImageStamp(imgStream)
                        {
                            TopMargin           = 10,
                            HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
                            VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top,
                            Width  = newWidth,
                            Height = newHeight
                        };

                        try
                        {
                            var page = index == 1 ? document.Pages[1] : document.Pages.Add();
                            page.AddStamp(imageStamp);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            Logger.WriteException(new Exception("Error during pdf generation. Path: " + previewImage.Path, ex));
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
            }

            return(null);
        }
예제 #8
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            Document doc = new Document(dataDir+ "input.pdf");
            ImageStamp stamp = new ImageStamp(dataDir + "aspose-logo.jpg");
            stamp.Quality = 10;
            doc.Pages[1].AddStamp(stamp);
            doc.Save(dataDir + "output.pdf");
        }
예제 #9
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            Document   doc   = new Document(dataDir + "input.pdf");
            ImageStamp stamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            stamp.Quality = 10;
            doc.Pages[1].AddStamp(stamp);
            doc.Save(dataDir + "output.pdf");
        }
        ///<Summary>
        /// AddImageStamp method to add image stamp
        ///</Summary>

        public Response AddImageStamp(string fileName, string folderName, string watermarkImage, string imageFolderName,
                                      string outputType, string watermarkImageColor = "", double imageAngle = 0, double imageZoom = 100)
        {
            return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                string imageSourceFolder = Config.Configuration.WorkingDirectory + imageFolderName;
                watermarkImage = imageSourceFolder + "/" + watermarkImage;

                // Open document
                Document pdfDocument = new Document(inFilePath);

                // Create image stamp
                ImageStamp imageStamp = null;
                if (watermarkImageColor.ToLower().Contains("gray"))
                {
                    System.Drawing.Bitmap bmp = MakeGrayscale3(new Bitmap(watermarkImage));
                    var memory = new MemoryStream();
                    bmp.Save(memory, ImageFormat.Jpeg);
                    imageStamp = new ImageStamp(memory);
                }
                else
                {
                    imageStamp = new ImageStamp(watermarkImage);
                }
                imageStamp.Background = true;
                //				imageStamp.XIndent = 100;
                //			imageStamp.YIndent = 100;
                imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
                imageStamp.VerticalAlignment = VerticalAlignment.Center;

                //imageStamp.Height = 300;
                //imageStamp.Width = 300;
                double _imageZoom = Convert.ToDouble(imageZoom);
                imageStamp.Zoom = (_imageZoom / 100.0f);
                //imageStamp.Rotate = Rotation.on270;
                imageStamp.RotateAngle = imageAngle;
                imageStamp.Opacity = 0.5;


                // Add Image stamp to all pages
                foreach (Pdf.Page page in pdfDocument.Pages)
                {
                    page.AddStamp(imageStamp);
                }

                // Save the document in PDF format.
                pdfDocument.Save(outPath, GetSaveFormat(outputType));
            }));
        }
예제 #11
0
        public static void ControlImageQuality()
        {
            // ExStart:ControlImageQuality
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddImageStamp.pdf");

            // Create image stamp
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            imageStamp.Quality = 10;
            pdfDocument.Pages[1].AddStamp(imageStamp);
            pdfDocument.Save(dataDir + "ControlImageQuality_out.pdf");
            // ExEnd:ControlImageQuality
        }
예제 #12
0
        public void AddWaterprint(string absoluteFilePath, string outputPath)
        {
            var watermarkImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DefaultResource", "waterMarkImg.jpeg");

            using (var pdfDocument = new Aspose.Pdf.Document(absoluteFilePath))
                using (BackgroundArtifact background = new BackgroundArtifact())
                {
                    foreach (Page aPdfPage in pdfDocument.Pages)
                    {
                        ImageStamp imageStamp = new ImageStamp(watermarkImgPath);
                        imageStamp.XIndent = 300;
                        imageStamp.YIndent = aPdfPage.PageInfo.Height - 200;
                        imageStamp.Height  = 81;
                        imageStamp.Width   = 80;
                        aPdfPage.AddStamp(imageStamp);
                    }


                    pdfDocument.Save(outputPath);
                }
        }
예제 #13
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir+ "input.pdf");
            //create footer
            ImageStamp imageStamp = new ImageStamp(dataDir+ "aspose-logo.jpg");
            //set properties of the stamp
            imageStamp.BottomMargin = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment = VerticalAlignment.Bottom;
            //add footer on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }

            //save updated PDF file
            pdfDocument.Save(dataDir+ "output.pdf");
        }
예제 #14
0
        private void AddImage(DocumentInfo doc, string imageFile)
        {
            string signatureImageName = imageFile;

            // Open document
            Document pdfDocument = doc.PdfDocument;
            var      page        = pdfDocument.Pages[1];

            using (var im = new Bitmap(signatureImageName))
            {
                var coeff      = (double)im.Width / im.Height;
                var imageStamp = new ImageStamp(signatureImageName);
                // imageStamp.Background = true;
                //				imageStamp.XIndent = 100;
                //			imageStamp.YIndent = 100;
                imageStamp.HorizontalAlignment = HorizontalAlignment.Right;
                imageStamp.VerticalAlignment   = VerticalAlignment.Bottom;
                imageStamp.Width  = page.PageInfo.Width / 3;
                imageStamp.Height = imageStamp.Width / coeff;

                page.AddStamp(imageStamp);
            }
        }
        private static void AddImage(Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, HeaderFooterConfig headerFooterConfig, GroupLogo groupLogo, bool isHeader, Package package)
        {
            if (groupLogo.ImageStream == null)
            {
                return;
            }

            var pageMargin = GetHeaderFooterMargin(horizontalAlignment, headerFooterConfig, isHeader, package);

            ImageStamp imageStamp = new ImageStamp(groupLogo.ImageStream)
            {
                TopMargin           = pageMargin.TopPoints,
                BottomMargin        = pageMargin.BottomPoints,
                LeftMargin          = pageMargin.LeftPoints,
                RightMargin         = pageMargin.RightPoints,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment,
                Width  = groupLogo.ResizedWidth,
                Height = groupLogo.CalculatedHeight > 0 ? groupLogo.CalculatedHeight : groupLogo.Height
            };

            page.AddStamp(imageStamp);
        }
예제 #16
0
        private void AddDrawing(DocumentInfo doc, string imageFile)
        {
            var page = doc.PdfDocument.Pages[1];

            // Convert base 64 string to byte[]
            byte[] imageBytes = Convert.FromBase64String(imageFile);
            // Convert byte[] to Image
            using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
            {
                var bitmap = new Bitmap(ms);
                var coeff  = bitmap.Width / bitmap.Height;

                var imageStamp = new ImageStamp(ms);
                //  imageStamp.Background = true;
                //				imageStamp.XIndent = 100;
                //			imageStamp.YIndent = 100;
                imageStamp.HorizontalAlignment = HorizontalAlignment.Right;
                imageStamp.VerticalAlignment   = VerticalAlignment.Bottom;
                imageStamp.Width  = page.PageInfo.Width / 3;
                imageStamp.Height = imageStamp.Width / coeff;
                page.AddStamp(imageStamp);
            }
        }
예제 #17
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Open document
            Document pdfDocument = new Document(dataDir+ "input.pdf");

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");
            imageStamp.Background = true;
            imageStamp.XIndent = 100;
            imageStamp.YIndent = 100;
            imageStamp.Height = 300;
            imageStamp.Width = 300;
            imageStamp.Rotate = Rotation.on270;
            imageStamp.Opacity = 0.5;
            //Add stamp to particular page
            pdfDocument.Pages[1].AddStamp(imageStamp);

            //Save output document
            pdfDocument.Save(dataDir + "output.pdf");
        }
예제 #18
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            imageStamp.Background = true;
            imageStamp.XIndent    = 100;
            imageStamp.YIndent    = 100;
            imageStamp.Height     = 300;
            imageStamp.Width      = 300;
            imageStamp.Rotate     = Rotation.on270;
            imageStamp.Opacity    = 0.5;
            //Add stamp to particular page
            pdfDocument.Pages[1].AddStamp(imageStamp);

            //Save output document
            pdfDocument.Save(dataDir + "output.pdf");
        }
        private static void AddLineSeparator(Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, Config config, Package package)
        {
            if (package.LineSeparator.ImageStream == null)
            {
                return;
            }

            // for drawing line separator between headerfooter and body, we need to add header/footer offsets to page margins
            var bodyMargin = PageSetting.GetBodyMargin(package, config);

            ImageStamp imageStamp = new ImageStamp(package.LineSeparator.ImageStream)
            {
                TopMargin           = bodyMargin.TopPoints,
                BottomMargin        = bodyMargin.BottomPoints,
                LeftMargin          = bodyMargin.LeftPoints,
                RightMargin         = bodyMargin.RightPoints,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment,
                Width  = page.PageInfo.Width - bodyMargin.LeftPoints - bodyMargin.RightPoints,
                Height = 1
            };

            page.AddStamp(imageStamp);
        }
예제 #20
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            //create header
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            //set properties of the stamp
            imageStamp.TopMargin           = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment   = VerticalAlignment.Top;
            //add header on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }

            //save updated document
            pdfDocument.Save(dataDir + "output.pdf");
        }
예제 #21
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            //open document
            Document pdfDocument = new Document(dataDir + "ImageinHeader.pdf");

            //create header
            ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");

            //set properties of the stamp
            imageStamp.TopMargin           = 10;
            imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
            imageStamp.VerticalAlignment   = VerticalAlignment.Top;
            //add header on all pages
            foreach (Page page in pdfDocument.Pages)
            {
                page.AddStamp(imageStamp);
            }

            //save updated document
            pdfDocument.Save(dataDir + "ImageinHeader_out.pdf");
        }
예제 #22
0
        public static void UploadPic(List <shap> shapes, string filename, string aspectRatio)
        {
            Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf"));

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));

            for (int i = 0; i < shapes.Count; i++)
            {
                //create stamp
                Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

                float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);

                double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY));

                var isSpecial = true;//regexItem.IsMatch(shapes[i].imName);

                if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image")
                {
                    if (shapes[i].Itype == "highlight")
                    {
                        imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));
                    }
                    else
                    {
                        imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/" + shapes[i].imName));
                    }

                    imageStamp.Background = false;
                    imageStamp.XIndent    = (float)(shapeX);
                    imageStamp.YIndent    = (float)(yaxis);
                    imageStamp.Height     = shapeH;
                    imageStamp.Width      = shapeW;

                    //Add stamp to particular page
                    doc.Pages[shapes[i].p].AddStamp(imageStamp);
                }
                else if (shapes[i].Itype == "text")
                {
                    /*
                     * // create TextBuilder for first page
                     * TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]);
                     *
                     * // TextFragment with sample text
                     * TextFragment fragment = new TextFragment(shapes[i].t);
                     *
                     * // set the font for TextFragment
                     * fragment.TextState.Font = FontRepository.FindFont(shapes[i].n);
                     * fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s);
                     * if (shapes[i].wt == "bold")
                     * {
                     *  fragment.TextState.FontStyle = FontStyles.Bold;
                     * }
                     *
                     * if (shapes[i].st == "italic")
                     * {
                     *  fragment.TextState.FontStyle = FontStyles.Italic;
                     * }
                     *
                     * // set the formatting of text as Underline
                     * // fragment.TextState.Underline = true;
                     * fragment.TextState.ForegroundColor = GetColor(shapes[i].c);
                     * // specify the position where TextFragment needs to be placed
                     * fragment.Position = new Position((float)(shapeX), (float)(yaxis));
                     *
                     * // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);
                     *
                     * // append TextFragment to PDF file
                     * tb.AppendText(fragment);
                     */

                    //create text stamp
                    TextStamp textStamp = new TextStamp(shapes[i].t);
                    //set whether stamp is background
                    // textStamp.Background = true;
                    //set origin
                    textStamp.XIndent = (float)(shapeX);
                    textStamp.YIndent = (float)(yaxis);
                    //rotate stamp
                    textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);

                    //set text properties
                    textStamp.TextState.Font     = FontRepository.FindFont(shapes[i].n);
                    textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f;

                    if (shapes[i].wt == "bold")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Bold;
                    }

                    if (shapes[i].st == "italic")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Italic;
                    }


                    textStamp.TextState.ForegroundColor = GetColor(shapes[i].c);
                    //add stamp to particular page
                    doc.Pages[shapes[i].p].AddStamp(textStamp);
                }
                else if (shapes[i].Itype == "field" && isSpecial)
                {
                    if (shapes[i].fieldType == "Text")
                    {
                        // Get a field
                        TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField;
                        // Modify field value
                        textBoxField.Value = shapes[i].t;
                    }
                    else if (shapes[i].fieldType == "CheckBox")
                    {
                        // Get a field
                        CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField;
                        if (shapes[i].t != "")
                        {
                            // Modify field value
                            checkBoxField.Checked = Convert.ToBoolean(shapes[i].t);
                        }
                    }
                    else if (shapes[i].fieldType == "Radio")
                    {
                        RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)];

                        RadioButtonField rbf = (RadioButtonField)field.Parent;
                        if (Convert.ToBoolean(shapes[i].t))
                        {
                            rbf.Selected = rbf.Options[field.OptionName].Index;
                        }
                        else
                        {
                            field.ActiveState = "Off";
                        }
                    }
                    else if (shapes[i].fieldType == "ComboBox")
                    {
                        // Get a field
                        ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField;
                        var           values        = shapes[i].t.Split(new string[] { "^^^" }, StringSplitOptions.None)[0];

                        foreach (var item in comboBoxField.Options.Cast <Option>())
                        {
                            if (item.Value == values)
                            {
                                comboBoxField.Selected = item.Index;
                            }
                        }
                    }
                }
            }

            doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf"));
        }
예제 #23
0
        public static void UploadPic(List<shap> shapes , string filename, string aspectRatio)
        {
          
                Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf"));

                //Create image stamp
                ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));

                for (int i = 0; i < shapes.Count; i++)
                {
                    //create stamp
                    Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

                    float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                    float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                    float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                    float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio);
                                                            
                    double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY));

                    var isSpecial = true;//regexItem.IsMatch(shapes[i].imName);

                    if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image")
                    {

                        if (shapes[i].Itype == "highlight")
                        {
                            imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png"));
                        }
                        else
                        {

                            imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/"+shapes[i].imName));
                        
                        }
                                                
                        imageStamp.Background = false;
                        imageStamp.XIndent = (float)(shapeX);
                        imageStamp.YIndent = (float)(yaxis);
                        imageStamp.Height = shapeH;
                        imageStamp.Width = shapeW;
                        
                        //Add stamp to particular page
                        doc.Pages[shapes[i].p].AddStamp(imageStamp);
                    }                   
                    else if(shapes[i].Itype == "text")
                    {

                        /*
                        // create TextBuilder for first page
                        TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]);

                        // TextFragment with sample text
                        TextFragment fragment = new TextFragment(shapes[i].t);

                        // set the font for TextFragment
                        fragment.TextState.Font = FontRepository.FindFont(shapes[i].n);
                        fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s);
                        if (shapes[i].wt == "bold")
                        {
                            fragment.TextState.FontStyle = FontStyles.Bold;
                        }

                        if (shapes[i].st == "italic")
                        {
                            fragment.TextState.FontStyle = FontStyles.Italic;
                        }

                        // set the formatting of text as Underline
                        // fragment.TextState.Underline = true;
                        fragment.TextState.ForegroundColor = GetColor(shapes[i].c);
                        // specify the position where TextFragment needs to be placed
                        fragment.Position = new Position((float)(shapeX), (float)(yaxis));

                       // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);

                        // append TextFragment to PDF file
                        tb.AppendText(fragment);
                        */
                        
                        //create text stamp
                        TextStamp textStamp = new TextStamp(shapes[i].t);
                        //set whether stamp is background
                       // textStamp.Background = true;
                        //set origin
                        textStamp.XIndent = (float)(shapeX); 
                        textStamp.YIndent = (float)(yaxis);
                        //rotate stamp
                        textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI);
                        
                        //set text properties
                        textStamp.TextState.Font = FontRepository.FindFont(shapes[i].n);
                        textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f;

                        if (shapes[i].wt == "bold")
                        {
                            textStamp.TextState.FontStyle = FontStyles.Bold;
                        }

                        if (shapes[i].st == "italic")
                        {
                            textStamp.TextState.FontStyle = FontStyles.Italic;
                        }
                        
                       
                        textStamp.TextState.ForegroundColor = GetColor(shapes[i].c);
                        //add stamp to particular page
                        doc.Pages[shapes[i].p].AddStamp(textStamp);

                    }
                    else if (shapes[i].Itype == "field" && isSpecial)
                    {
                        if (shapes[i].fieldType == "Text")
                        {
                            // Get a field
                            TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField;
                            // Modify field value
                            textBoxField.Value = shapes[i].t;
                        
                        }
                        else if (shapes[i].fieldType == "CheckBox")
                        {

                            // Get a field
                            CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField;
                            if(shapes[i].t != "")
                            // Modify field value
                            checkBoxField.Checked = Convert.ToBoolean(shapes[i].t);
                        }
                        else if (shapes[i].fieldType == "Radio")
                        {
                            RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)];

                            RadioButtonField rbf = (RadioButtonField)field.Parent;
                            if (Convert.ToBoolean(shapes[i].t))
                            {
                                rbf.Selected = rbf.Options[field.OptionName].Index;

                            }
                            else
                            {
                                field.ActiveState = "Off";

                            }
                        }
                        else if (shapes[i].fieldType == "ComboBox")
                        {                            

                            // Get a field
                            ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField;
                            var values = shapes[i].t.Split(new string[]{"^^^"},StringSplitOptions.None)[0];

                            foreach (var item in comboBoxField.Options.Cast<Option>())
                            {
                                if (item.Value == values)
                                {

                                    comboBoxField.Selected = item.Index;
                                }
                            }
                        }
                    }

                }
            
                doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf"));
            
           
        }
예제 #24
0
        public IHttpActionResult UploadPic(UploadPicModel uploadPicModel)
        {
            var      fullPath         = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId);
            var      downloadFileName = "document.pdf";
            var      documentFileName = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId, downloadFileName);
            Document doc = new Document(documentFileName);

            //Create image stamp
            ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("/img/Test.png"));

            for (int i = 0; i < uploadPicModel.shapes.Count; i++)
            {
                //create stamp
                Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

                float shapeX = (uploadPicModel.shapes[i].x * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeY = (uploadPicModel.shapes[i].y * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeW = (uploadPicModel.shapes[i].w * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);
                float shapeH = (uploadPicModel.shapes[i].h * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio);

                double yaxis = (float)(doc.Pages[uploadPicModel.shapes[i].p].Rect.URY - (shapeH + shapeY));

                var isSpecial = true;                //regexItem.IsMatch(uploadPicModel.shapes[i].imName);

                if (uploadPicModel.shapes[i].Itype == "highlight" || uploadPicModel.shapes[i].Itype == "image")
                {
                    imageStamp = uploadPicModel.shapes[i].Itype == "highlight"
                                                ? new ImageStamp(HttpContext.Current.Server.MapPath("/img/test.png"))
                                                : new ImageStamp(fullPath + uploadPicModel.shapes[i].imName);

                    imageStamp.Background = false;
                    imageStamp.XIndent    = (float)(shapeX);
                    imageStamp.YIndent    = (float)(yaxis);
                    imageStamp.Height     = shapeH;
                    imageStamp.Width      = shapeW;

                    //Add stamp to particular page
                    doc.Pages[uploadPicModel.shapes[i].p].AddStamp(imageStamp);
                }
                else if (uploadPicModel.shapes[i].Itype == "text")
                {
                    //create text stamp
                    TextStamp textStamp = new TextStamp(uploadPicModel.shapes[i].t);
                    textStamp.XIndent = (float)(shapeX);
                    textStamp.YIndent = (float)(yaxis);
                    //rotate stamp
                    textStamp.RotateAngle = 360 - (Convert.ToDouble(uploadPicModel.shapes[i].fieldType) * 180 / Math.PI);

                    //set text properties
                    textStamp.TextState.Font     = FontRepository.FindFont(uploadPicModel.shapes[i].n);
                    textStamp.TextState.FontSize = Convert.ToInt32(uploadPicModel.shapes[i].s) * 0.75f;

                    if (uploadPicModel.shapes[i].wt == "bold")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Bold;
                    }

                    if (uploadPicModel.shapes[i].st == "italic")
                    {
                        textStamp.TextState.FontStyle = FontStyles.Italic;
                    }


                    textStamp.TextState.ForegroundColor = GetColor(uploadPicModel.shapes[i].c);
                    //add stamp to particular page
                    doc.Pages[uploadPicModel.shapes[i].p].AddStamp(textStamp);
                }
                else if (uploadPicModel.shapes[i].Itype == "field" && isSpecial)
                {
                    if (uploadPicModel.shapes[i].fieldType == "Text")
                    {
                        // Get a field
                        TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as TextBoxField;
                        // Modify field value
                        textBoxField.Value = uploadPicModel.shapes[i].t;
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "CheckBox")
                    {
                        // Get a field
                        CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as CheckboxField;
                        if (uploadPicModel.shapes[i].t != "")
                        {
                            // Modify field value
                            checkBoxField.Checked = Convert.ToBoolean(uploadPicModel.shapes[i].t);
                        }
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "Radio")
                    {
                        RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)];

                        RadioButtonField rbf = (RadioButtonField)field.Parent;
                        if (Convert.ToBoolean(uploadPicModel.shapes[i].t))
                        {
                            rbf.Selected = rbf.Options[field.OptionName].Index;
                        }
                        else
                        {
                            field.ActiveState = "Off";
                        }
                    }
                    else if (uploadPicModel.shapes[i].fieldType == "ComboBox")
                    {
                        // Get a field
                        ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as ComboBoxField;
                        var           values        = uploadPicModel.shapes[i].t.Split(new[] { "^^^" }, StringSplitOptions.None)[0];

                        foreach (var item in comboBoxField.Options.Cast <Option>())
                        {
                            if (item.Value == values)
                            {
                                comboBoxField.Selected = item.Index;
                            }
                        }
                    }
                }
            }

            doc.Save(Config.Configuration.OutputDirectory + "/Export.pdf");

            return(Ok(new DocStatusModel()));
        }
        // ===================================================================================================== Generate documents

        protected Stream GetPreviewImagesPdfStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null)
        {
            CheckLicense(LicenseProvider.Pdf);

            try
            {
                var ms             = new MemoryStream();
                var pdf            = new Pdf();
                var document       = new Aspose.Pdf.Document(pdf);
                var index          = 1;
                var pageAttributes = GetPageAttributes(content);
                var imageOptions   = new PreviewImageOptions()
                {
                    RestrictionType = restrictionType
                };

                foreach (var previewImage in previewImages.Where(previewImage => previewImage != null))
                {
                    // use the stored rotation value for this page if exists
                    int?rotation = pageAttributes.ContainsKey(previewImage.Index)
                        ? pageAttributes[previewImage.Index].degree
                        : null;

                    imageOptions.Rotation = rotation;

                    using (var imgStream = GetRestrictedImage(previewImage, imageOptions))
                    {
                        int newWidth;
                        int newHeight;

                        // Compute dimensions using a SQUARE (max width and height are equal).
                        ComputeResizedDimensionsWithRotation(previewImage, PREVIEW_PDF_HEIGHT, rotation, out newWidth, out newHeight);

                        var imageStamp = new ImageStamp(imgStream)
                        {
                            TopMargin           = 10,
                            HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
                            VerticalAlignment   = Aspose.Pdf.VerticalAlignment.Top,
                            Width  = newWidth,
                            Height = newHeight
                        };

                        try
                        {
                            var page = index == 1 ? document.Pages[1] : document.Pages.Add();

                            // If the final image is landscape, we need to rotate the page
                            // to fit the image. It does not matter if the original image
                            // was landscape or the rotation made it that way.
                            if (newWidth > newHeight)
                            {
                                page.Rotate = Rotation.on90;
                            }

                            page.AddStamp(imageStamp);
                        }
                        catch (IndexOutOfRangeException ex)
                        {
                            SnLog.WriteException(ex, "Error during pdf generation. Path: " + previewImage.Path);
                            break;
                        }
                    }

                    index++;
                }

                document.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                return(ms);
            }
            catch (Exception ex)
            {
                SnLog.WriteException(ex);
            }

            return(null);
        }