如何使用C#水印Pdf文件,下面是用于图像上的水印的代码,而不是我不想在Pdf文件上制作水印。请建议解决方案 [英] How To Watermark Pdf File Using C#?,Below Is The Code Used For Watermark On Image,Instead Of That I Wan't To Make Watermark On Pdf File.Please Suggest Solutions
问题描述
位图original_image =新位图(FileUpload1.FileContent);
string sWaterMark =(string)s1;
int fontsize =((original_image.Width * 2)/(sWaterMark.Length * 3));
int x = original_image.Width / 2;
int y = original_image.Height * 9/20;
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
Graphics graphic = Graphics.FromImage(original_image);
graphic.DrawString( sWaterMark,new Font(Verdana,fontsize,FontStyle.Bold),新的SolidBrush(Color.FromArgb(80,255,255,255)),x,y,drawFormat);
original_image。保存(MapPath(〜/+ newfolder +\\) + FileUpload1.FileName);
if(original_image!= null)original_image.Dispose();
if(graphic!= null)graphic.Dispose();
您需要第三方dll,例如 pdfsharp [< a href =http://pdfsharp.com/PDFsharp/target =_ blanktitle =New Window> ^ ]或 iTextSharp [ ^ ]为pdf添加水印
Bitmap original_image = new Bitmap(FileUpload1.FileContent);
string sWaterMark = (string)s1;
int fontsize = ((original_image.Width * 2) / (sWaterMark.Length * 3));
int x = original_image.Width / 2;
int y = original_image.Height * 9 / 20;
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
Graphics graphic = Graphics.FromImage(original_image);
graphic.DrawString(sWaterMark, new Font("Verdana", fontsize, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, 255, 255, 255)), x, y, drawFormat);
original_image.Save(MapPath("~/" + newfolder + "\\") + FileUpload1.FileName);
if (original_image != null) original_image.Dispose();
if (graphic != null) graphic.Dispose();
You'll need a 3rd party dll,such as pdfsharp[^] or iTextSharp[^] to watermark a pdf
这篇关于如何使用C#水印Pdf文件,下面是用于图像上的水印的代码,而不是我不想在Pdf文件上制作水印。请建议解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!