php给pdf加上水印
来源:互联网 发布:xd网络上是什么意思啊 编辑:程序博客网 时间:2024/06/13 08:08
环境
php5.5.12 fpdi-1.5.2 fpdf-1.7原理
利用fpdi来加载已知pdf文件,用fpdf对pdf进行操作
注意事项
免费的fpdi只支持处理pdf1.4及以下版本,1.5以上就需要用到FPDI PDF-Parser插件
使用方法
fpdi-1.5.2 fpdf-1.71.文字水印 word.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!--?php
require_once(
'./fpdf/fpdf.php'
);
require_once(
'./fpdi/fpdi.php'
);
//word_watermark
$pdf =
new
FPDI();
// get the page count
$pageCount = $pdf--->setSourceFile(
'more.pdf'
);
// iterate through all pages
for
($pageNo =
1
; $pageNo <= $pageCount; $pageNo++)
{
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if
($size[
'w'
] > $size[
'h'
]) $pdf->AddPage(
'L'
, array($size[
'w'
], $size[
'h'
]));
else
$pdf->AddPage(
'P'
, array($size[
'w'
], $size[
'h'
]));
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetFont(
'Arial'
,
'B'
,
'12'
);
// sign with current date
$pdf->SetXY(
0
,
0
);
// you should keep testing untill you find out correct x,y values
$pdf->Write(
7
, date(
'Y-m-d'
));
}
$pdf->Output(
'word.pdf'
);
2.图片水印 pic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!--?php
require_once(
'./fpdf/fpdf.php'
);
require_once(
'./fpdi/fpdi.php'
);
//pic_watermark
$pdf =
new
FPDI();
// get the page count
$pageCount = $pdf--->setSourceFile(
'more.pdf'
);
// iterate through all pages
for
($pageNo =
1
; $pageNo <= $pageCount; $pageNo++)
{
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if
($size[
'w'
] > $size[
'h'
]) $pdf->AddPage(
'L'
, array($size[
'w'
], $size[
'h'
]));
else
$pdf->AddPage(
'P'
, array($size[
'w'
], $size[
'h'
]));
// use the imported page
$pdf->useTemplate($templateId);
// Place the graphics
$pdf->image(
"test.png"
,
75
,
85
,
50
);
}
$pdf->Output(
'pic.pdf'
);
阅读全文
0 0
- php给pdf加上水印
- php如何给pdf加上文字水印和图片水印
- HTACCESS 配合 PHP 给图片加上水印
- 给图片加上水印
- 给图片加上水印
- 给pdf加水印
- 给pdf加水印
- 给PDF文件加水印
- 给图片加上带版权的水印
- 给图片加上带版权的水印
- 给图片加上带版权的水印
- 给图片加上带版权的水印
- 如何给水晶报表加上水印
- ASP.NET给图片加上水印
- 给图片加上带版权的水印
- 给图片加上带版权的水印
- ASP.NET给图片加上水印
- Android Canvas 给图片加上水印
- Java 多线程编程
- 编程题
- Vue 2.0 键盘属性
- Java解释器的运行过程解释
- 对类的对象进行操作
- php给pdf加上水印
- Codeforces Educational Codeforces Round 31
- 百度地图开发-申请ak及相关配置
- 主要是打表---数豆子
- 算是,对自己的鞭策吧
- SQL语句总结
- tp框架和laravel框架的区别
- 29省份2016年平均工资出炉 北京居首河南垫底
- 最大公约数最小公倍数