public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate Document object with input file
            Document doc = new Document(dataDir + "DefineAlignment.pdf");
            // instantiate FormattedText object with sample string
            FormattedText text = new FormattedText("This");

            // add new text line to FormattedText
            text.AddNewLineText("is sample");
            text.AddNewLineText("Center Aligned");
            text.AddNewLineText("TextStamp");
            text.AddNewLineText("Object");
            // create TextStamp object using FormattedText
            TextStamp stamp = new TextStamp(text);

            // specify the Horizontal Alignment of text stamp as Center aligned
            stamp.HorizontalAlignment = HorizontalAlignment.Center;
            // specify the Vertical Alignment of text stamp as Center aligned
            stamp.VerticalAlignment = VerticalAlignment.Center;
            // specify the Text Horizontal Alignment of TextStamp as Center aligned
            stamp.TextAlignment = HorizontalAlignment.Center;
            // set top margin for stamp object
            stamp.TopMargin = 20;
            // add the stamp object over first page of document
            doc.Pages[1].AddStamp(stamp);
            // save the udpated document
            doc.Save(dataDir + "StampedPDF.pdf");
        }
        public static void Run()
        {
            // ExStart:DefineAlignment
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate Document object with input file
            Document doc = new Document(dataDir+ "DefineAlignment.pdf");
            // Instantiate FormattedText object with sample string
            FormattedText text = new FormattedText("This");
            // Add new text line to FormattedText
            text.AddNewLineText("is sample");
            text.AddNewLineText("Center Aligned");
            text.AddNewLineText("TextStamp");
            text.AddNewLineText("Object");
            // Create TextStamp object using FormattedText
            TextStamp stamp = new TextStamp(text);
            // Specify the Horizontal Alignment of text stamp as Center aligned
            stamp.HorizontalAlignment = HorizontalAlignment.Center;
            // Specify the Vertical Alignment of text stamp as Center aligned
            stamp.VerticalAlignment = VerticalAlignment.Center;
            // Specify the Text Horizontal Alignment of TextStamp as Center aligned
            stamp.TextAlignment = HorizontalAlignment.Center;
            // Set top margin for stamp object
            stamp.TopMargin = 20;
            // Add the stamp object over first page of document
            doc.Pages[1].AddStamp(stamp);

            dataDir = dataDir + "StampedPDF_out.pdf";
            // Save the udpated document
            doc.Save(dataDir);
            // ExEnd:DefineAlignment            
            Console.WriteLine("\nAlignment defined successfully for text stamp.\nFile saved at " + dataDir);
        }
예제 #3
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();

            // Instantiate Document object with input file
            Document doc = new Document(dataDir+ "DefineAlignment.pdf");
            // instantiate FormattedText object with sample string
            FormattedText text = new FormattedText("This");
            // add new text line to FormattedText
            text.AddNewLineText("is sample");
            text.AddNewLineText("Center Aligned");
            text.AddNewLineText("TextStamp");
            text.AddNewLineText("Object");
            // create TextStamp object using FormattedText
            TextStamp stamp = new TextStamp(text);
            // specify the Horizontal Alignment of text stamp as Center aligned
            stamp.HorizontalAlignment = HorizontalAlignment.Center;
            // specify the Vertical Alignment of text stamp as Center aligned
            stamp.VerticalAlignment = VerticalAlignment.Center;
            // specify the Text Horizontal Alignment of TextStamp as Center aligned
            stamp.TextAlignment = HorizontalAlignment.Center;
            // set top margin for stamp object
            stamp.TopMargin = 20;
            // add the stamp object over first page of document
            doc.Pages[1].AddStamp(stamp);
            // save the udpated document
            doc.Save(dataDir+ "StampedPDF.pdf");
            
            
        }
        private FormattedText getFormattedText(string watermarkText)
        {
            FormattedText fmtText = new FormattedText();
            var           lines   = watermarkText.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

            foreach (var line in lines)
            {
                fmtText.AddNewLineText(line);
            }
            return(fmtText);
        }
예제 #5
0
        private void AddWatermarkToPage(double pWidth, double pHeight, Aspose.Pdf.Page pg, string sUserName, string sTextDate)
        {
            //try{
            //    DeleteExistingWatermarks(pg);
            //}catch {


            //}

            double alfaR = 30;

            double c    = pWidth / pHeight;
            double alfa = Math.Atan(c);

            alfaR = (alfa * 180) / Math.PI;

            FormattedText wtext = new FormattedText("Confidential", new FontColor(220, 20, 60), new FontColor(255, 255, 255),
                                                    Aspose.Pdf.Facades.FontStyle.HelveticaBold,
                                                    EncodingType.Winansi, true, 35);

            wtext.AddNewLineText("Downloaded by");
            wtext.AddNewLineText(sUserName.Length > 55 ? sUserName.Substring(0, 55) : sUserName);
            wtext.AddNewLineText(sTextDate.Length > 19 ? sTextDate.Substring(0, 19) : sTextDate);

            TextStamp wStamp = new TextStamp(wtext);

            wStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
            wStamp.TextState.FontStyle       = FontStyles.Bold;
            wStamp.TextState.FontSize        = 35;

            wStamp.HorizontalAlignment = HorizontalAlignment.Center;
            wStamp.VerticalAlignment   = VerticalAlignment.Center;
            wStamp.TextAlignment       = HorizontalAlignment.Center;
            wStamp.Opacity             = .15F;
            wStamp.RotateAngle         = (float)(alfaR - 90);

            pg.AddStamp(wStamp);
        }
예제 #6
0
        private MemoryStream AddWatermarkToFile(Document pdfDocument, ref PdfFileStamp pdfStamp, string sUserName, DateTime dtCurrentDate, string sCompany)
        {
            string sTextDate = dtCurrentDate.ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            FormattedText wtext = new FormattedText("Confidential", new FontColor(220, 20, 60), new FontColor(255, 255, 255),
                                                    Aspose.Pdf.Facades.FontStyle.HelveticaBold,
                                                    EncodingType.Winansi, true, 35);

            wtext.AddNewLineText(sUserName, 5);
            wtext.AddNewLineText(sTextDate, 5);

            int nPageCount = 1;

            foreach (Aspose.Pdf.Page pg in pdfDocument.Pages)
            {
                //get the page size position for each page
                Aspose.Pdf.Rectangle rtPage = pg.TrimBox;
                AddWatermarkToPage(rtPage.Width, rtPage.Height, pg, sUserName, sTextDate);

                nPageCount++;
            }

            MemoryStream outStream = new MemoryStream();
            //save updated PDF file
            DocumentPrivilege pv = null;

            pv = DocumentPrivilege.AllowAll;

            pv.ChangeAllowLevel = 0;
            pv.CopyAllowLevel   = 1;
            pv.PrintAllowLevel  = 2;

            pdfStamp.Document.Encrypt("", new Guid().ToString(), pv, CryptoAlgorithm.RC4x128, false);

            pdfStamp.Save(outStream);

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

            // Instantiate Document object with input file
            Document doc = new Document(dataDir + "DefineAlignment.pdf");
            // Instantiate FormattedText object with sample string
            FormattedText text = new FormattedText("This");

            // Add new text line to FormattedText
            text.AddNewLineText("is sample");
            text.AddNewLineText("Center Aligned");
            text.AddNewLineText("TextStamp");
            text.AddNewLineText("Object");
            // Create TextStamp object using FormattedText
            TextStamp stamp = new TextStamp(text);

            // Specify the Horizontal Alignment of text stamp as Center aligned
            stamp.HorizontalAlignment = HorizontalAlignment.Center;
            // Specify the Vertical Alignment of text stamp as Center aligned
            stamp.VerticalAlignment = VerticalAlignment.Center;
            // Specify the Text Horizontal Alignment of TextStamp as Center aligned
            stamp.TextAlignment = HorizontalAlignment.Center;
            // Set top margin for stamp object
            stamp.TopMargin = 20;
            // Add the stamp object over first page of document
            doc.Pages[1].AddStamp(stamp);

            dataDir = dataDir + "StampedPDF_out.pdf";
            // Save the udpated document
            doc.Save(dataDir);
            // ExEnd:DefineAlignment
            Console.WriteLine("\nAlignment defined successfully for text stamp.\nFile saved at " + dataDir);
        }
예제 #8
0
        private MemoryStream AddFooterToFile(Document pdfDocument, ref PdfFileStamp pdfStamp, string sUserName, DateTime dtCurrentDate, string sCompany)
        {
            //create footer
            List <TextStamp> ltFooterStamp = new List <TextStamp>();
            TextStamp        footerStamp   = null;


            //footerStamp = new TextStamp("Document ID: ");
            ////set properties of the stamp
            //footerStamp.BottomMargin = 10;
            //footerStamp.XIndent = 20;
            ////footerStamp.HorizontalAlignment = HorizontalAlignment.Left;
            //footerStamp.VerticalAlignment = VerticalAlignment.Bottom;
            //footerStamp.TextState.FontStyle = FontStyles.Bold;

            //ltFooterStamp.Add(footerStamp);


            //footerStamp = new TextStamp(documentGuid.ToString());
            ////set properties of the stamp
            //footerStamp.BottomMargin = 10;
            //footerStamp.XIndent = 130;
            ////footerStamp.HorizontalAlignment = HorizontalAlignment.Left;
            //footerStamp.VerticalAlignment = VerticalAlignment.Bottom;
            //footerStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);

            //ltFooterStamp.Add(footerStamp);


            string sTextDate = dtCurrentDate.ToString("dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

            FormattedText wtext = new FormattedText("Confidential", new FontColor(220, 20, 60), new FontColor(255, 255, 255),
                                                    Aspose.Pdf.Facades.FontStyle.HelveticaBold,
                                                    EncodingType.Winansi, true, 17);

            wtext.AddNewLineText(sUserName, 5);
            wtext.AddNewLineText(sTextDate, 5);
            footerStamp = new TextStamp(wtext);
            ltFooterStamp.Add(footerStamp);


            float fWidth = wtext.TextWidth;


            Dictionary <Tuple <double, double>, List <int> > dictMeasurements = new Dictionary <Tuple <double, double>, List <int> >();
            int nPageCount = 1;

            foreach (Aspose.Pdf.Page pg in pdfDocument.Pages)
            {
                foreach (TextStamp ts in ltFooterStamp)
                {
                    pg.AddStamp(ts);
                }



                nPageCount++;
            }


            MemoryStream outStream = new MemoryStream();

            //save updated PDF file
            pdfStamp.Save(outStream);

            return(outStream);
        }