如何使用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

查看:137
本文介绍了如何使用C#水印Pdf文件,下面是用于图像上的水印的代码,而不是我不想在Pdf文件上制作水印。请建议解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 



位图original_image =新位图(FileUpload1.FileContent);

string sWaterMark =(string)s1;

int fontsize =((ori​​ginal_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆