linux pdf 加水印,将动态水印添加到PDF

您使用FPDI与FPDF结合使用的一些信息可以重新创建初始文档 .

FPDI的免费版本不支持PDF 1.5中引入的压缩功能 . 无论如何,我们提供了一个商业插件,增加了对此的支持:FPDI PDF-Parser .

无论如何,FPDI和FPDI PDF-Parser都不支持读取加密/受保护的PDF文档 .

但是:特别是对于水印,我们提供另一种产品(不是免费的!),它是为了这个目的而制作的:SetaPDF-Stamper组件 .

它还允许您向PDF文档添加新内容,这些文档也是加密/保护的 . 这可以通过authenticating使用所有者密码或绕过限制来完成(如果我们通过支持渠道知道您正在做什么,我们可以为此提供支持) .

一个简单的水印可以这样做:

require_once('library/SetaPDF/Autoload.php');

// or if you use composer require_once('vendor/autoload.php');

// create a file writer

$writer = new SetaPDF_Core_Writer_File('processed/directory/result.pdf');

// load document by filename

$document = SetaPDF_Core_Document::loadByFilename('your.pdf', $writer);

// create a stamper instance for the document

$stamper = new SetaPDF_Stamper($document);

// create a font for this document

$font = new SetaPDF_Core_Font_TrueType_Subset($document, 'fonts/DejaVuSans.ttf');

// create a stamp with the created font and font size 60

$stamp = new SetaPDF_Stamper_Stamp_Text($font, 60);

// center the text to the text block

$stamp->setAlign(SetaPDF_Core_Text::ALIGN_CENTER);

// set text for the stamp

$stamp->setText($theInvoiceNo);

// add the stamp to the center of the page and rotate it by 60 degrees

$stamper->addStamp(

$stamp,

[

'position' => SetaPDF_Stamper::POSITION_CENTER_MIDDLE,

'rotation' => 60

]

);

// stamp the document

$stamper->stamp();

// save the file and finish the writer (e.g. file handler will closed)

$document->save()->finish();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值