binarystash/pdf-watermarker

为PDF文档添加水印或印章

1.1.2 2016-06-04 09:54 UTC

This package is auto-updated.

Last update: 2024-09-26 06:13:11 UTC


README

Build Status

PDF Watermarker

PDFWatermarker 允许您将图片作为水印添加到现有的PDF文件中。它使用 FPDF 允许您编写PDF文件,FPDI 允许您将现有PDF文档导入到FPDF。

使用它,您可以

  • 使用具有96 DPI分辨率的jpg和png(带alpha通道)文件
  • 轻松地将水印定位在PDF文件的页面中

安装

  1. composer.phar 放置在您解压缩文件的文件夹中。

  2. 运行 php composer.phar install

  3. 将文件包含到您的项目中。

<?php
require_once('pdfwatermarker/pdfwatermarker.php');
require_once('pdfwatermarker/pdfwatermark.php');

用法

<?php

//Specify path to image. The image must have a 96 DPI resolution.
$watermark = new PDFWatermark('C:\myimage.png'); 

//Set the position
$watermark->setPosition('bottomleft');

//Place watermark behind original PDF content. Default behavior places it over the content.
$watermark->setAsBackground();

//Specify the path to the existing pdf, the path to the new pdf file, and the watermark object
$watermarker = new PDFWatermarker('C:\test.pdf','C:\output.pdf',$watermark); 

//Set page range. Use 1-based index.
$watermarker->setPageRange(1,5);
 
//Save the new PDF to its specified location
$watermarker->savePdf(); 
?>

可以使用五个位置,'center' 是默认值。

  • center
  • topleft
  • topright
  • bottomright
  • bottomleft

更多详细信息,请参阅 API 文档

支持

https://github.com/binarystash/pdf-watermarker/issues 上报告错误。