C# PDF添加水印
需要iTextSharp.dll, 下载地址http://sourceforge.net/projects/itextsharp/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
namespace pdf_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string source = @"D:\Sample\18.pdf"; //模板路径
string output = @"D:\Sample\Chap1018.pdf"; //导出水印背景后的PDF
string watermark = @"D:\Sample\03.gif"; // 水印图片
bool isSurrcess = PDFWatermark(source, output, watermark, 10, 10);
}
public bool PDFWatermark(string inputfilepath, string outputfilepath, string ModelPicName, float top, float left)
{
//throw new NotImplementedException();
PdfReader pdfReader = null;
PdfStamper pdfStamper = null;
try
{
pdfReader = new PdfReader(inputfilepath);
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(outputfilepath, FileMode.Create));
PdfContentByte waterMarkContent;
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(ModelPicName);
image.GrayFill = 20;//透明度,灰色填充
//image.Rotation//旋转
//image.RotationDegrees//旋转角度
//水印的位置
if (left < 0)
{
// left = width - image.Width + left; //h////////////
}
//image.SetAbsolutePosition(left, (height - image.Height) - top); //h////////////
image.SetAbsolutePosition(136, 36);
//每一页加水印,也可以设置某一页加水印
for (int i = 1; i <= numberOfPages; i++)
{
waterMarkContent = pdfStamper.GetUnderContent(i);
waterMarkContent.AddImage(image);
}
//strMsg = "success";
return true;
}
catch (Exception ex)
{
ex.Message.Trim();
return false;
}
finally
{
if (pdfStamper != null)
pdfStamper.Close();
if (pdfReader != null)
pdfReader.Close();
}
}
//
}
}
C# PDF添加水印的更多相关文章
- 如何在PDF中添加水印,PDF添加水印技巧
PDF文件现在的使用很是普遍,不管是工作中还是学习中都会使用到PDF文件,制作一个PDF文件就很辛苦的,我们要是想把PDF文件中添加水印防止抄袭的时候应该要怎么做呢,其实吧PDF文件添加水印还挺简单的 ...
- PDF如何添加水印,PDF添加水印工具的使用方法
PDF文件在编辑修改的时候是需要借助工具才可以编辑,PDF文件不像普通的文件可以直接打开编辑,PDF编辑工具是PDF文件进行编辑的重要工具,就以添加水印为例,能够在PDF中添加水印的工具有哪些呢?要怎 ...
- PHP使用FPDF pdf添加水印中文乱码问题 pdf合并版本问题
---恢复内容开始--- require_once('../fpdf/fpdf.php');require_once('../fpdi/fpdi.php'); 使用此插件 pdf 合并 并添加水印 期 ...
- C#使用iTextSharp给PDF添加水印
代码: /// <summary> /// 添加普通偏转角度文字水印 /// </summary> public static void SetWatermark(string ...
- iTextSharp简单生成pdf和操作pdf添加水印
遇到需要导出页面到pdf,并添加pdf水印的业务.稍微研究了下,借阅网友的前车之鉴,经过使用可行之后的代码贴出来,做个记录,也供需要的网友借阅. public class PDFSetWaterMar ...
- java 为pdf添加水印图片
首先需要引入两个Jar包分别是:iTextAsian.jar .itext-2.1.7.jar 可以去 http://download.csdn.net/detail/work201003/922 ...
- C#向pdf 添加水印
调用直接这样用: //PDFHelper.AddImageWatermarkPDF(path, "D://my.pdf", Server.MapPath("/HtmlTo ...
- php pdf添加水印(中文水印,图片水印)
1.下载软件包 链接:https://pan.baidu.com/s/1cah-mf-SCtfMhVyst_sG8w&shfl=sharepset 提取码:ld8z 2.下载pdf_water ...
- PDF上添加水印
1.整合jar: itext-asian-5.2.0.jar,itextpdf-5.5.10.jar,iTextAsianCmaps.jar 下载:itext的整合jar包 2.使用方法: publi ...
随机推荐
- mysql:sql行列转换
今天一个同学遇到一个问题问我了,由于本人平时学习的mysql比较基础,确实没解决,后来google了一下,才知道是sql的一种技法[行列转换],话不多说先上图: 想得到下面的结果: +------+- ...
- Angular.js+Bootstrap实现表格分页
最近一直学习Angular.js,在学习过程中也练习了很多的Demo,这里先贴一下表格+分页. 先上图看看最终结果: 不得不说Angular.js代码风格很受人欢迎,几十行代码清晰简洁的实现了上面的功 ...
- G面经prepare: Straight Partition of A Deck of Cards
Define “Straight” as 5 cards with consecutive numbers. Determine if the deck can be fully divided in ...
- Mac下无法安装Dragon Bones的解决方案
在Mac下安装dragon bones 然后很郁闷的发现 没有 Exchange Manger 然后就去官网下载了一个 不过下载以后发现 怎么都认不出我的Flash CC来 一安装zxp扩展就提示我没 ...
- 传递闭包(Floyd+bellman-Fold POJ1932)
传递闭包 在一个有向(无向)连通图中,如果节点i与k联通,k与j联通,则i和j联通,传递闭包就是把所有传递性的节点求出来,之后就知道了任意两个节点的连通性,只需枚举节点的联通情况即可,无需考虑最短路径 ...
- hdu1251(字典树)
统计难题(hdu1251) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Tota ...
- c#如实现将一个数字转化为其他进制字符串输出
之前在 os 上看到有人说过 一直想整理 但是一直没时间 后来 从csdn 上 知道了一份 下面内容 来自 (1)http://bbs.csdn.net/topics/60512816 tost ...
- springmvc+spring+mybatis分页查询实例版本3,添加条件检索
在第二个版本上添加了姓名模糊查询,年龄区间查询;自以为easy,结果发现mybatis的各种参数写法基本搞混或是忘了,zuo啊,直接上代码,然后赶紧把mybatis整理一遍再研究自己的项目,应该还会有 ...
- [ThinkPHP] 输出、模型的使用
# # ThinkPHP 3.1.2 输出和模型使用 # 讲师:赵桐正 微博:http://weibo.com/zhaotongzheng 本节课大纲: 一.ThinkPHP 3 的输出 ...
- ActiveMQ消息的可靠性机制(转)
文章转自:http://www.linuxidc.com/Linux/2013-02/79664.htm 1.JMS消息确认机制 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通 ...