我修改了这个堆栈问题:
Applying watermarks on pdf files when users try to download the files但是我遇到了一个错误,虽然有一条评论说如何解决它,但它还不够详细.
这是代码:
require_once('fpdf/fpdf.php');
require_once('fpdi/fpdi.php');
class WaterMark
public $pdf, $file, $newFile,
$wmText = "STACKOVERFLOW";
/** $file and $newFile have to include the full path. */
public function __construct($file, $newFile)
$this->pdf = new FPDI();
$this->file = $file;
$this->newFile = $newFile;
/** $file and $newFile have to include the full path. */
public static function applyAndSpit($file, $newFile)
$wm = new WaterMark($file, $newFile);
if($wm->isWaterMarked())
return $wm->spitWaterMarked();
else{
$wm->doWaterMark();
return $wm->spitWaterMarked();
/** @todo Make the text nicer and add to all pages */
public function doWaterMark()
$currentFile = $this->file;
$newFile = $this->newFile;
$this->pdf->addPage();
$pagecount = $this->pdf->setSourceFile($currentFile);
for($i = 1; $i <= $pagecount; $i++){
$tplidx = $this->pdf->importPage($i);
$this->pdf->useTemplate($tplidx, 10, 10, 100);
// now write some text above the imported page
$this->pdf->SetFont('Arial', 'I', 40);
$this->pdf->SetTextColor(255,0,0);
$this->pdf->SetXY(25, 135);
$this->_rotate(55);
$this->pdf->Write(0, $this->wmText);
$this->pdf->Output($newFile, 'F');
public function isWaterMarked()
return (file_exists($this->newFile));
public function spitWaterMarked()
return readfile($this->newFile);
protected function _rotate($angle,$x=-1,$y=-1) {
if($x==-1)
$x=$this->pdf->x;
if($y==-1)
$y=$this->pdf->y;
if($this->pdf->angle!=0)
$this->pdf->_out('Q');
$this->pdf->angle=$angle;
if($angle!=0){
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->pdf->k;
$cy=($this->pdf->h-$y)*$this->pdf->k;
$this->pdf->_out(sprintf(
'q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',
$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
header('Content-type: application/pdf');
//header('Content-Disposition: attachment; filename="downloaded.pdf"');
WaterMark::applyAndSpit('C:\xampp\htdocs\tst\test0.pdf','C:\xampp\htdocs\tst\output0.pdf');
当我加载一个超过2的pdf时,所有页面合并在一个页面中.我在这篇文章中附上了图片.
我修改了这个堆栈问题:Applying watermarks on pdf files when users try to download the files但是我遇到了一个错误,虽然有一条评论说如何解决它,但它还不够详细.这是代码:require_once('fpdf/fpdf.php');require_once('fpdi/fpdi.php');class WaterMark{public...
<?
php
function
pdf
Encrypt ($origFile, $password, $destFile){
require_once('
fpdi
/
FPDI
_Protection.
php
');
$
pdf
= new
FPDI
_Protection();
// set the format of the destinaton file, in our case 6×9 inch
//$
pdf
->F
PDF
('P', 'in', array('6','9'));
$
pdf
->F
PDF
('P', 'in');
//Calculate the number of page
昨天研究如何在既有的
PDF
档案上放入中文字,虽然找到支援中文的F
PDF
,但是有些Unicode 字集我实在试不出如何显示(如:堃) 。
我的同事建议我用图形来解决看看,以下就是我的实验过程(我用的是Windows 平台) 。
我用的相关技术如下:
F
PDF
PHP
上用来产生
PDF
的第三方套件
[http://www.f...
第一个:TC
PDF
这个TC
PDF
上网有直接下载的地址,我用的是tp3.2框架,TC
PDF
给我手写了一个
pdf
出来很棒!!
第二个:
FPDI
,下面是
FPDI
合并
pdf
的代码
namespace Qwadmin\Controller;
//导入TC
PDF
类库
use TC
PDF
;
require_once('tc
pdf
/config...
a4纸的大小为 210 * 297mm, a5大小为210 * (297 /2)
.2
pdf
是合并之前的临时文件, 当合并成功后, 输出新的文件, 并删除 .2
pdf
临时文件
private function convert
Pdf
A5ToA4(string $file_path, string $file_name): void
FPDI
-免费的
PDF
文档导入器
:red_exclamation_mark: 本文档引用了
FPDI
2。不建议使用版本1,并停止开发。 :red_exclamation_mark:
FPDI
是
PHP
类的集合,它使开发人员可以从现有的
PDF
文档中读取页面并将它们用作模板,该模板由Olivier Plathey开发。 除了的副本外,
FPDI
不需要任何特殊
PHP
扩展。
FPDI
也可以用作或的扩展。
因为
FPDI
可以与F
PDF
,TC
PDF
或tF
PDF
一起使用,所以我们没有在composer.json主文件中添加固定的依赖项。 您需要自己将依赖性添加到您选择的
PDF
生成库中。
要将
FPDI
与F
PDF
一起使用,请在composer.json文件中包含以下内容:
使用
FPDI
获取
PDF
内容的方式
FPDI
内部使用了StreamReader类,它使用低级函数,如fread()或ftell()来与流交互。
流读取器类提供了通过特定输入类型创建实例的静态方法。它的构造函数允许你传递任何可查找的开放流资源:
//资源类型获取
$fh = fopen('a/path/to/a.
pdf
', 'rb');
$
pdf
->setSourceFile(new StreamReader($fh));
$
pdf
->setSourceFile($fh);
fclose($fh);
在我们写项目的时候,经常需要对
PDF
文件进行操作。例如:合并多个
PDF
文件,取
PDF
特定页数以及合并。
PHP
有一个专门对
PDF
进行操作的插件,SETASIGN,官方文档为:
https://www.setasign.com/products/
fpdi
/demos/simple-demo/
首先,我们要先下载,该插件支持composer下载,具体的操作步骤,请看文档下载:
https://pac...
boolean AcceptPageBreak()
版本1.4
内容: 每逢有
分页
的情况出现,就代表这个功能已经被执行了,而且,
分页
会自动显示出来,也不需要依靠在其他数值资料。预设履行反回数值,取决於 SetAutoPageBreak() 的模式选择。这个功能是会自动处理的,也不需要其他程式操控。
这个功能,对於有三个栏位编排的页面是无有作用的:
。。。。。。。。。。