Example #1
0
        private Document RemoveExistingWatermarks(Document pdfDocument)
        {
            PdfContentEditor ped = new PdfContentEditor(pdfDocument);

            for (int i = 1; i <= pdfDocument.Pages.Count; i++)
            {
                double pHeight = pdfDocument.Pages[i].Rect.Height;
                double pWidth  = pdfDocument.Pages[i].Rect.Width;

                StampInfo[] vstamp     = ped.GetStamps(i);
                List <int>  ltToDelete = new List <int>();
                for (int j = 0; j < vstamp.Length; j++)
                {
                    if (StampType.Form == vstamp[j].StampType)
                    {
                        if ((vstamp[j].Rectangle.Height * 100) / pHeight >= 30 || (vstamp[j].Rectangle.Width * 100) / pWidth >= 30)
                        {
                            ltToDelete.Add(j);
                        }
                    }
                }

                int[] vToDelete = new int[ltToDelete.Count];
                for (int j = 0; j < ltToDelete.Count; j++)
                {
                    vToDelete[j] = ltToDelete[j];
                }

                ped.DeleteStamp(i, vToDelete);
            }


            MemoryStream outStream = new MemoryStream();

            ped.Save(outStream);
            Document pdfDocumentNoStamps = new Document(outStream);

            return(pdfDocumentNoStamps);
        }