在PDF导出上创建水印文本 [英] Creating watermark text on PDF export
本文介绍了在PDF导出上创建水印文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个PDF导出方法。我想添加水印文本作为背景。有人可以帮帮我吗?谢谢。
private void ExportGridToPDF()
{
username =(string)(Session) [用户名]);
Response.ContentType =application / pdf;
Response.AddHeader(content-disposition,attachment; filename =+
username +'Purchase.pdf);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//gv_CartProduct.DataBind();
gv_CartProduct.RenderControl(hw);
//gv_CartProduct.HeaderRow.Style.Add(\"width,15%);
//gv_CartProduct.HeaderRow.Style.Add(\"font-size,10px);
//gv_CartProduct.Style.Add(\"text-decoration,none);
//gv_CartProduct.Style.Add(\"font-family,Arial,Helvetica,sans-serif;);
//gv_CartProduct.Style.Add(\"font-size,8px);
StringReader sr = new StringReader(sw.ToString());
string str =< h1 title ='Header'align ='Center'>谢谢你
+用户名+,以
购物ShopNow< / h1>< br> ;< table
align ='Center'>< tr>< td
style ='width:100px; color:green'>您已在ShopNow成功付款
在线商店。请
保留此发票。感谢
您< / td>< / tr>< / table>;
StringReader sr1 = new StringReader(str);
文件pdfDoc =新文件(PageSize.A4,7f,7f,7f,0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc,Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr1);
htmlparser.Parse(sr);
ConfirmPurchase();
pdfDoc.Close();
Response.Write(pdfDoc);
}
解决方案
你可以参考这个codeproject文章 PDF文件编写器C#类库(版本1.11.0) [ ^
Hi, I have this PDF export method. I wanted to add watermarking text as the background. Anyone can help me? Thank you.
private void ExportGridToPDF() { username = (string)(Session["username"]); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=" + username + "'s Purchase.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); //gv_CartProduct.DataBind(); gv_CartProduct.RenderControl(hw); //gv_CartProduct.HeaderRow.Style.Add("width", "15%"); //gv_CartProduct.HeaderRow.Style.Add("font-size", "10px"); //gv_CartProduct.Style.Add("text-decoration", "none"); //gv_CartProduct.Style.Add("font-family", "Arial, Helvetica, sans-serif;"); //gv_CartProduct.Style.Add("font-size", "8px"); StringReader sr = new StringReader(sw.ToString()); string str = "<h1 title=’Header’ align=’Center’> Thank You " + username + ", for shopping at ShopNow</h1><br><table align=’Center’><tr><td style=’width:100px;color:green’> You have made successful payment at ShopNow online shop. Please keep this invoice. Thank You</td></tr></table>"; StringReader sr1 = new StringReader(str); Document pdfDoc = new Document(PageSize.A4, 7f, 7f, 7f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr1); htmlparser.Parse(sr); ConfirmPurchase(); pdfDoc.Close(); Response.Write(pdfDoc); }
解决方案
You can refer to this codeproject article PDF File Writer C# Class Library (Version 1.11.0)[^]
这篇关于在PDF导出上创建水印文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文