/// <summary>
/// 为PDF添加水印或背景图片
/// </summary>
/// <param name="strSourceFilePath">源文件路径</param>
/// <param name="strTargetFilePath">目标文件路径</param>
/// <param name="strWaterMarkPicPath">水印图片路径</param>
/// <param name="strTargetFileTmpPath">目标临时文件</param>
/// <returns>添加结果</returns>
public static bool AddWaterMarkForPdf(string strSourceFilePath, string strTargetFilePath, string strWaterMarkPicPath, FileInfo TargetFileTmp)
{
bool blnRt = false;
PdfFileInfo pdf = new PdfFileInfo(strSourceFilePath);
if (! pdf.BePdfFile)
{
throw new ApplicationException("源文件不是有效的PDF文件");
}
//开始处理
int intPageNums = pdf.NumberofPages; PdfFileStamp fileStamp = null;
try
{
int intNumber = ;
int intCount = (int)Math.Ceiling(intPageNums / (decimal.Parse(intNumber.ToString())));
for (int j = ; j < intCount; j++)
{
fileStamp = new PdfFileStamp(strSourceFilePath, strTargetFilePath);
for (int i = ; i <= intNumber; i++)
{
if (j * intNumber + i > intPageNums)
{
break;
}
Stamp stamp = new Stamp();
if (!String.IsNullOrEmpty(strWaterMarkPicPath))
{
stamp.BindImage(strWaterMarkPicPath);
}
stamp.IsBackground = true;
stamp.PageNumber = j * intNumber + i;
stamp.SetImageSize(PageSize.A4.Height, PageSize.A4.Width);
fileStamp.AddStamp(stamp);
}
fileStamp.Close();
TargetFileTmp.Delete();
File.Copy(strTargetFilePath, TargetFileTmp.FullName);
strSourceFilePath = TargetFileTmp.FullName;
}
blnRt = true;
}
catch (Exception ex)
{
throw ex;
}
return blnRt;
}

具体代码

注意,给PDF增加水晶报表,当页码过多时会报错,或卡死。为了防止这种情况,我们要分多次对PDF进行增加水印。

如第一次加600页,保存关闭当前文件,再拿加过水印的文件进行再追加水印,这样这就不会了错了。

pdf增加水印的更多相关文章

  1. PDF的水印怎么去掉

    很多朋友私下都有问过PDF去除水印的方法,现在在网上下载一些PDF电子书,几乎页面内都会有水印的,而且有的水印还带有超链接,稍微不注意就会点开进入别的页面内,不仅影响了阅读效果还带给读者负面影响,那如 ...

  2. 怎么编辑PDF,如何给PDF加水印

    在使用PDF文件的时候,往往会用到PDF编辑器来修改,那么,在使用PDF编辑器修改文件的时候,想要在文件中添加水印,这该怎么操作呢,不会的小伙伴可以看看下面的文章了哦,说不定就会了. 1.打开运行PD ...

  3. java 实现 PDF 加水印功能

    使用java代码实现给PDF加水印的功能 首先导入所需要的依赖 <dependency> <groupId>com.itextpdf</groupId> <a ...

  4. C#图片增加水印

    给图片增加水印 1.引用 using System.Drawing; 2.代码实现 string ImagePath = @"C:\Users\RAPOO\Pictures\Camera R ...

  5. 【Python】批量给图片增加水印工具

    背景 最近有一些图片需要增加水印,找了一圈也没看见比较好的工具,又不想用破解的PS,干脆自己做了一个GUI工具,有需要的同学自取 功能 支持水印预览 自定义水印文字内容 支持行楷和微软雅黑两种字体 支 ...

  6. PDF打水印加密

    using System; using System.Collections.Generic; using System.Data; using System.Diagnostics; using S ...

  7. 给现有的word和pdf加水印

    iTextSharp简单生成pdf和操作pdf添加水印 给word加水印,利用的是aspose.words

  8. pdf文件下载水印添加的中文与空格问题解决

    public static boolean waterMark(String inputFile, String outputFile, String waterMarkName)throws IOE ...

  9. 阿里云ali-oss图片增加水印

    先附上文档连接 : https://helpcdn.aliyun.com/document_detail/44957.html 水印文字或图片必须经过一下转化 URL安全的Base64位编码 在图片处 ...

随机推荐

  1. Java 8 Stream API Example Tutorial

    Stream API Overview Before we look into Java 8 Stream API Examples, let’s see why it was required. S ...

  2. Windows Azure 微软公有云体验(二) 存储成本比较分析

    Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...

  3. sql 联合查询速度慢,需要对其进行分组

    分组:SELECT   * FROM(SELECT ROW_NUMBER() OVER(ORDER BY  ProjID) as row_number,* FROM ( select ProjAppl ...

  4. 如何删除C/C++源代码中的注释

    具体代码: #include <stdlib.h>  #include <stdio.h>  //删除注释  void commentFilter(FILE* sourceFi ...

  5. 【数论】UVa 11526 - H(n)

    What is the value this simple C++ function will return? long long H(int n) { ; ; i <= n; i=i+ ) { ...

  6. merge into update

    如果要DML实现真正意义上的并发,在开始执行需要并发语句前,需要执行开启session并发  ALTER SESSION ENABLE PARALLEL DML;  在执行完语句后,需要执行关闭ses ...

  7. 关于oracle误删数据的恢复

    与数据打交道,免不了会误删一些数据,之后还commit了,连回滚的机会都没了,而更糟糕的是你又没有备份,这种事终于在今天被我不幸的遇上了... 唯一一点值得欣慰的是,我删除表记录的时候,时间不长,一天 ...

  8. 改变xmind显示中文界面

    最近打算迁移到ubuntu系统做为主系统,打算使用xmind这个工具,因为我的ubuntu并没有使用简体中文,xmind是根据系统的语种来自动选择的,所以也直接为英文界面,实在使用不习惯,查到了这篇文 ...

  9. 基本STRUTS标签-学习笔记-Bean标签

    <bean:include> 和标准的JSP标签<jsp:include>很相似,都可以用来包含其他Web资源的内容,区别在于<bean:include>标签把其它 ...

  10. Jersey(1.19.1) - Client API, Overview of the API

    To utilize the client API it is first necessary to create an instance of a Client, for example: Clie ...