您使用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();