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); }
private void setWatermark_Txt(WaterStamp_Txt WaterStamp_Txt_Option, string in_file, string out_file) { PdfReader pdfReader = null; PdfStamper pdfStamper = null; try { pdfReader = new PdfReader(in_file); FileStream fs = new FileStream(out_file, FileMode.Create); pdfStamper = new PdfStamper(pdfReader, fs); // 设置密码 //pdfStamper.SetEncryption(true,"1", "1", PdfWriter.AllowPrinting); int total = pdfReader.NumberOfPages + 1; PdfContentByte content; BaseFont font = BaseFont.CreateFont(WaterStamp_Txt_Option.Font, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); PdfGState gs = new PdfGState(); gs.FillOpacity = WaterStamp_Txt_Option.FillOpacity; //透明度 int j = WaterStamp_Txt_Option.WaterMarkName.Length; char c; int rise = 0; for (int i = 1; i < total; i++) { rise = WaterStamp_Txt_Option.TxtLeft; //content = pdfStamper.GetOverContent(i);//在内容上方加水印 content = pdfStamper.GetUnderContent(i);//在内容下方加水印 content.SetGState(gs); content.BeginText(); content.SetColorFill(new BaseColor(WaterStamp_Txt_Option.FTxtColor.Red, WaterStamp_Txt_Option.FTxtColor.Green, WaterStamp_Txt_Option.FTxtColor.Blue));//(BaseColor.DARK_GRAY); content.SetFontAndSize(font, WaterStamp_Txt_Option.FontSize); // 设置水印文字字体倾斜 开始 { content.SetTextMatrix(WaterStamp_Txt_Option.TxtLeft, WaterStamp_Txt_Option.TxtHeight); for (int k = 0; k < j; k++) { content.SetTextRise(rise); c = WaterStamp_Txt_Option.WaterMarkName[k]; content.ShowText(c + ""); rise -= WaterStamp_Txt_Option.TxtRotation; } } content.EndText(); } } catch (Exception ex) { throw ex; } finally { if (pdfStamper != null) { pdfStamper.Close(); } if (pdfReader != null) { pdfReader.Close(); } } }