Example #1
0
        public new string doExport(string profile, string Account_date, string MadeBillDate, string payDate, List <Ticket_Group> Tickets, List <MainContract> msc)
        {
            string result_file = null;

            account_date = Account_date;
            _profile     = "pdf";
            for (int i = 0; i < _options.SectionCount; i++)
            {
                if (_options[i].Name == profile)
                {
                    _profile = profile;
                }
            }


            stamp_pic  = new WaterStamp_Pic(_options, _profile);
            stamp_txt  = new WaterStamp_Txt(_options, _profile);
            HeadFooter = new PDFHeaderFooter(_options, _profile);
            CreatePDF(get_tempname(true), Tickets, msc, Account_date, MadeBillDate, payDate);
            if (_options[_profile]["IsWaterStamp_Txt"].Value == "T")
            {
                setWatermark_Txt(stamp_txt, get_tempname(false), get_tempname(true));
            }
            if (_options[_profile]["IsWaterStamp_Pic"].Value == "T")
            {
                setWatermark_Pic(stamp_pic, get_tempname(false), get_tempname(true));
            }
            System.Diagnostics.Process.Start("IEXPLORE.EXE", get_tempname(false));
            return(result_file);
        }
Example #2
0
        private static bool setWatermark_Pic(WaterStamp_Pic WaterStamp_Pic_Option, string in_file, string out_file)
        {
            //throw new NotImplementedException();
            PdfReader  pdfReader  = null;
            PdfStamper pdfStamper = null;

            try
            {
                pdfReader = new PdfReader(in_file);

                int numberOfPages = pdfReader.NumberOfPages;

                iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);

                float width = psize.Width;

                float height = psize.Height;

                pdfStamper = new PdfStamper(pdfReader, new FileStream(out_file, FileMode.Create));

                PdfContentByte waterMarkContent;

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(WaterStamp_Pic_Option.ModelPicName);

                //image.GrayFill = opt.WaterStamp_Pic_Option.GrayFill;//透明度,灰色填充
                image.Rotation        = WaterStamp_Pic_Option.Rotation;        //旋转
                image.RotationDegrees = WaterStamp_Pic_Option.RotationDegrees; //旋转角度
                //水印的位置
                if (WaterStamp_Pic_Option.Left < 0)
                {
                    WaterStamp_Pic_Option.Left = width / 2 - image.Width + WaterStamp_Pic_Option.Left;
                }

                //image.SetAbsolutePosition(left, (height - image.Height) - top);
                image.SetAbsolutePosition(WaterStamp_Pic_Option.Left, (height / 2 - image.Height) - WaterStamp_Pic_Option.Top);

                //每一页加水印,也可以设置某一页加水印

                for (int i = 1; i <= numberOfPages; i++)
                {
                    if (WaterStamp_Pic_Option.IsOverContent)
                    {
                        waterMarkContent = pdfStamper.GetOverContent(i);
                    }
                    else
                    {
                        waterMarkContent = pdfStamper.GetUnderContent(i);
                    }
                    waterMarkContent.AddImage(image);
                }
                //strMsg = "success";
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (pdfStamper != null)
                {
                    pdfStamper.Close();
                }

                if (pdfReader != null)
                {
                    pdfReader.Close();
                }
            }
        }