虚心求教,向PDF文件里面加水印问题,做过的请进来看看

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了虚心求教,向PDF文件里面加水印问题,做过的请进来看看相关的知识,希望对你有一定的参考价值。

try

PdfReader pdfReader = new PdfReader(inputPath);
int numberOfPages = pdfReader.NumberOfPages;
FileStream outputStream = new FileStream(outputPath, FileMode.Create);
PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream);
PdfContentByte waterMarkContent;

string watermarkimagepath = watermarkPath;
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(watermarkimagepath);

image.SetAbsolutePosition(255, 785);
for (int i = 1; i <= numberOfPages; i++)

waterMarkContent = pdfStamper.GetUnderContent(i);
waterMarkContent.AddImage(image);

pdfStamper.Close();
pdfReader.Close();

catch (Exception ex)

WriteLog.Log(ex.ToString());
throw ex;


这是我在网上搜的代码,其中iTextSharp已经添加引用了,但是PdfStamper这个类始终报错,说找不到找不到类型或命名控件,想请教下这个需要导入什么包,谢谢了。同时也希望高手能HI我具体教下怎么给PDF加水印
向PDF里面添加图片已经解决,但不是水印,也就是说图片会把下面的文字覆盖掉,有人有办法解决吗?

wdby,请问下Watermark需要引用什么吗? 可是,我在iTextSharp里面并没有找到Watermark这个类啊,
import com.lowagie.text.pdf.PdfStamper; 这是JAVA导入的方式吧

输入是没问题,我都把iTextSharp.text里面所以的类都翻遍了,就是没找到watermark,会有其他原因吗?

真的没找到这个类,你看你能不能把你用的iTextSharp发给我以下,谢谢了,85532732@qq.com

顺便祝国庆快乐!!!

import com.lowagie.text.pdf.PdfStamper;

iTextSharp的确好用,但我加水印一般在初始化的时候写两行就行了,不需要这么麻烦,只是图片得自己做淡一些
if(System.IO.File.Exists("./waterMark/waterMark.JPG") == false)
MessageBox.Show("waterMark加载失败,请确定文件waterMark.JPG放在waterMark文件夹下!");
else

Watermark watermark = new Watermark(iTextSharp.text.Image.getInstance("./waterMark/waterMark.JPG"), wm_left, wm_top);
document.Add(watermark);


wm_left, wm_top是水印的位置,从第几页开始显示水印就把上面的代码加到第几页

补充:watermark是iTextSharp里的,不需要其他引用
iTextSharp.text.watermark 检查是否输入正确

.\itextsharp-0.04-src\iTextSharp\text\watermark.cs 。。。。。。
或者你可以搜索一下?
代码全文:
using System;

/*
* $Id: Watermark.cs,v 1.3 2003/05/15 01:49:58 geraldhenson Exp $
* $Name: $
*
* Copyright 2000, 2001, 2002 by Bruno Lowagie.
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/

namespace iTextSharp.text
/// <summary>
/// A <CODE>Watermark</CODE> is a graphic element (GIF or JPEG)
/// that is shown on a certain position on each page.
/// </summary>
/// <seealso cref="T:iTextSharp.text.Element"/>
/// <seealso cref="T:iTextSharp.text.Jpef"/>
/// <seealso cref="T:iTextSharp.text.Gif"/>
/// <seealso cref="T:iTextSharp.text.Png"/>
public class Watermark : Image, IElement

// membervariables

/// <summary> This is the offset in x-direction of the Watermark. </summary>
private float offsetX = 0;

/// <summary> This is the offset in y-direction of the Watermark. </summary>
private float offsetY = 0;

// Constructors

/// <summary>
/// Constructs a <CODE>Watermark</CODE>-object, using an <CODE>Image</CODE>.
/// </summary>
/// <param name="image">an <CODE>Image</CODE>-object</param>
/// <param name="offsetX">the offset in x-direction</param>
/// <param name="offsetY">the offset in y-direction</param>
public Watermark(Image image, float offsetX, float offsetY) : base(image)
this.offsetX = offsetX;
this.offsetY = offsetY;


// implementation of the Element interface

/// <summary>
/// Gets the type of the text element.
/// </summary>
/// <value>a type</value>
public override int Type
get
return type;



// methods to retrieve information

/// <summary>
/// Returns the offset in x direction.
/// </summary>
/// <value>a value</value>
public float OffsetX
get
return offsetX;



/// <summary>
/// Returns the offset in y direction.
/// </summary>
/// <value>an offset</value>
public float OffsetY
get
return offsetY;





恩,给你发过去了,带有word教程和示例代码,国庆快乐
参考技术A 水印的话应该是添加到最下边的空白位置.image.SetAbsolutePosition(255, 785);这样的设置会让图片处于绝对位置. 参考技术B 这个好像得加COM组件

[pdf加水印防删除]求怎么给PDF加水印而不会被被人去掉的方法

  查看: 9436|回复: 23

  技术图片

  技术图片

  [复制链接]

  crdcool

  crdcool

  当前离线

  好友

  阅读权限20

  听众

  收听

  技术图片

  技术图片

  楼主

  技术图片

  crdcool

  发表于 2018-8-29 12:25

  35吾爱币

  我只要方便快捷的方法,不要转换成图片加水印,或者转换成WORD加水印在转成PDF的方法,

  要快捷方便的 文件多没时间弄它。

  或者可以增加类似水印的东西别人无法去掉的方法也可以。

  要软件 最好批量的

  技术图片 感动何尚

  查看完整内容

  软件:Adobe Acrobat 9 Pro

  步骤:1、打开PDF,右上角依次点开文档-水印-添加得到下图:,这里可以添加文字水印或者图片水印,设置大小角度透明等。

  2、按下图依次打开拼合预览,得到下图,先把红方框里的选中,再点应用,最后确定。

  完事,这样添加的水印没有字体,不能完美消除,只能用PS等工具扣,就看你的水印复杂程度了

  发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

  感动何尚

  感动何尚

  当前离线

  好友

  阅读权限10

  听众

  收听

  技术图片

  技术图片

  沙发

  技术图片

  感动何尚

  发表于 2018-8-29 12:25

  软件:Adobe Acrobat 9 Pro

  步骤:1、打开PDF,右上角依次点开文档-水印-添加得到下图:

  技术图片

  54Z_NH{T$V_YB~~3X2F(3GX.png (238.8 KB, 下载次数: 2)

  下载附件

  保存到相册

  2018-8-29 14:20 上传

  ,这里可以添加文字水印或者图片水印,设置大小角度透明等。

  2、按下图依次打开拼合预览

  技术图片

  5GLKWFE[QW(%A9~SIK@)JFK.png (92.96 KB, 下载次数: 0)

  下载附件

  保存到相册

  2018-8-29 14:20 上传

  ,得到下图,先把红方框里的选中,再点应用,最后确定

  技术图片

  TB}RNI9S0O3OB{P37`{K_{L.png (65.59 KB, 下载次数: 0)

  下载附件

  保存到相册

  2018-8-29 14:20 上传

  。

  完事,这样添加的水印没有字体,不能完美消除,只能用PS等工具扣,就看你的水印复杂程度了

  NDKVBJ$PGTEJ(A1S~I6XFEY.png

  (71.19 KB, 下载次数: 3)

  下载附件

  保存到相册

  2018-8-29 14:20 上传

  技术图片

  技术图片

  技术图片

  DM7RA2JDVJ2MPC6TN%AB_EX.png

  (524.69 KB, 下载次数: 3)

  下载附件

  保存到相册

  2018-8-29 14:20 上传

  技术图片

  技术图片

  技术图片

  参与人数 1吾爱币 +1

  收起

  理由

  技术图片 cqe5210

  + 1

  谢谢@Thanks!

  查看全部评分

  【吾爱破解论坛总版规】 - [让你充分了解吾爱破解论坛行为规则]

  lizhipei78

  lizhipei78

  当前离线

  好友

  阅读权限35

  听众

  收听

  技术图片

  技术图片

  3#

  技术图片

  lizhipei78

  发表于 2018-8-29 12:45

  吾爱破解论坛没有任何官方QQ群,禁止留联系方式,禁止任何商业交易。

  话说了,你都能添加了,如果不通过转换,那人家为啥不能移除呢?最简单的方法在原来PDF中添加水印,通过虚拟机打印PDF,这样子不会是图片式的,人家也移除不了

  如果要批量的,只能通过软件转换

  参与人数 1吾爱币 +1

  热心值 +1

  收起

  理由

  技术图片 crdcool

  + 1

  + 1

  谢谢@Thanks!

  查看全部评分

  如何升级?如何获得积分?积分对应解释说明!

  lizhipei78

  lizhipei78

  当前离线

  好友

  阅读权限35

  听众

  收听

  技术图片

  技术图片

  4#

  技术图片

  lizhipei78

  发表于 2018-8-29 12:53

  《站点帮助文档》有什么问题来这里看看吧,这里有你想知道的内容!

  你可以试一下这个软件,可批量,加水印后一般也不好去除

  PDF Shaper v8.5 中文破解专业版绿色版本

  PDF Shaper - 免费实用的全能PDF工具箱!这款PDF转换器包含了很多非常实用的PDF工具,可以轻松的把 PDF 转成 Word,PDF 转图像,PDF 加密等等。它还可以合并,分割,加密和解密 PDF,图像转换为 PDF,PDF 转换为 RTF 或 图像,从 PDF 中提取文本和图像,转换或裁剪已签名的PDF等。PDF Shaper,该软件原生免费仅限非商业用途,体积小巧,资源占用低,界面简单易用,支持批处理、支持Unicode文本。 PDF Shaper 的功能可以说几乎覆盖了日常PDF操作的方方面面,并且它拥有无需安装的便携特性,整个软件虽然功能众多,但体积小巧;由于其界面直观优雅,所以无需学习简单易用!实乃PDF工具必备利器!

  技术图片

  https://pan.baidu.com/s/1FX1z-HsGi46j7gWyt5hsCw

  呼吁大家发布原创作品添加吾爱破解论坛标示!

  hero1987zlh

  hero1987zlh

  当前离线

  好友

  阅读权限10

  听众

  收听

  技术图片

  技术图片

  5#

  技术图片

  hero1987zlh

  发表于 2018-8-29 14:34

  lizhipei78 发表于 2018-8-29 12:45

  话说了,你都能添加了,如果不通过转换,那人家为啥不能移除呢?最简单的方法在原来PDF中添加水印,通过虚 ...

  怎么通过虚拟机打印,我转换成图片的有什么不一样?

  如何快速判断一个文件是否为病毒!

  感动何尚

  感动何尚

  当前离线

  好友

  阅读权限10

  听众

  收听

  技术图片

  技术图片

  6#

  技术图片

  感动何尚

  发表于 2018-8-29 14:42

  感动何尚 发表于 2018-8-29 14:25

  软件:Adobe Acrobat 9 Pro

  步骤:1、打开PDF,右上角依次点开文档-水印-添加得到下图:,这里可以添加文 ...

  最后可以用CTRL+D查看字体,没有字体就说明可以了。这种方法用于印刷前拼合,相当完美了

  技术图片

  VC@L}___{0SYEOB9KF`5`Y5.png (146.01 KB, 下载次数: 1)

  下载附件

  保存到相册

  2018-8-29 14:42 上传

  crdcool

  crdcool

  当前离线

  好友

  阅读权限20

  听众

  收听

  技术图片

  技术图片

  7#

  技术图片

  楼主|

  crdcool

  发表于 2018-8-29 15:25

  <

  lizhipei78 发表于 2018-8-29 12:53

  你可以试一下这个软件,可批量,加水印后一般也不好去除

  PDF Shaper v8.5 中文破解专业版绿色版本

  PDF Sh ...

  这个不支持中文文字格式的水印,只能是英文或者数字,打上的水印无法变大小 或者 无法变浅,

  加上的水印文件不是在原文件上加要从新建立一个。无法微调水印位置,想放在哪里必须是程序规定的。

  但是这个水印打上确实是别人删不掉。

  lizhipei78

  lizhipei78

  当前离线

  好友

  阅读权限35

  听众

  收听

  技术图片

  技术图片

  8#

  技术图片

  lizhipei78

  发表于 2018-8-29 15:27

  hero1987zlh 发表于 2018-8-29 14:34

  怎么通过虚拟机打印,我转换成图片的有什么不一样?

  PdfFactory等虚拟打印,论坛搜索一下或者百度都有一大堆,你转换成图片,人家是无法选择复制啊,这个得看你的要求了,现在有了OCR技术,图片式PDF也就是加了一丁点难度防复制罢了,实则一点意义没有,所以直接给人家文字复制好了,还能减小PDF体积,也更好的观看效果。

  lizhipei78

  lizhipei78

  当前离线

  好友

  阅读权限35

  听众

  收听

  技术图片

  技术图片

  9#

  技术图片

  lizhipei78

  发表于 2018-8-29 15:30

  crdcool 发表于 2018-8-29 15:25

  这个不支持中文文字格式的水印,只能是英文或者数字,打上的水印无法变大小 或者 无法变浅,

  加上的水印 ...

  经我这里测试是没有问题啊,你也可以以图片式添加啊,加水印的软件很多,我一般用这个,是因为它功能比较齐全,懒得下其它的软件

  crdcool

  crdcool

  当前离线

  好友

  阅读权限20

  听众

  收听

  技术图片

  技术图片

  10#

  技术图片

  楼主|

  crdcool

  发表于 2018-8-29 15:45

  <

  感动何尚 发表于 2018-8-29 14:25

  软件:Adobe Acrobat 9 Pro

  步骤:1、打开PDF,右上角依次点开文档-水印-添加得到下图:,这里可以添加文 ...

  你这方法太麻烦了技术图片

  我试试

以上是关于虚心求教,向PDF文件里面加水印问题,做过的请进来看看的主要内容,如果未能解决你的问题,请参考以下文章

java 获取电脑设备打印机状态,越具体越好,做过的请帮忙理下思路,好

PDF文件添加二维码水印

开工啦!批量向PDF文件添加中文水印...

虚心求教:stm32使用hal库中adc采样频率如何查看和修改?

怎么给PDF文件添加水印

pdf怎么加满屏水印