uvinum/pdf-watermarker

简单的PDF水印

1.0.3 2019-05-29 16:33 UTC

This package is auto-updated.

Last update: 2024-08-29 05:06:56 UTC


README

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

使用它,您可以

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

安装

使用composer安装

> composer require binarystash/pdf-watermarker:^2.0

用法

<?php

use BinaryStash\PdfWatermarker\Pdf;
use BinaryStash\PdfWatermarker\Watermark;
use BinaryStash\PdfWatermarker\FpdiPdfWatermarker as PDFWatermarker;

// Specify path to the existing pdf
$pdf = new Pdf('my.pdf');

// Specify path to image. The image must have a 96 DPI resolution.
$watermark = new Watermark('watermark.png'); 

// Create a new watermarker
$watermarker = new PDFWatermarker($pdf, $watermark); 
 
// Save the new PDF to its specified location
$watermarker->savePdf('output.pdf');

?>

选项

<?php

use BinaryStash\PdfWatermarker\Position;

// Set the position of the watermark
// All possible positions can be found in Position::options
$watermarker->setPosition(new Position('BottomCenter'));

// Alternatively
$watermarker->setPosition(Position::BottomCenter());

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

// Only Watermark specific range of pages
// This would only watermark page 3 and 4
$watermarker->setPageRange(3, 4);

?>

输出选项

<?php

// The filename is optional for all output options
$watermarker->savePdf();

// Start a download of the PDF
$watermarker->downloadPdf('output.pdf');

// Send the PDF to standard out
$watermarker->stdOut('output.pdf');

?>

支持

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