* PDF文件加水印
* composer命令安装:composer require setasign/fpdf
* composer命令安装:composer require setasign/fpdi
public
function
add_water
(
$type
=
1
)
{
$pdf
=
new
Fpdi
();
$file
=
'Upload/all_to_path/report_file/FA065307C8FF0236FC2002DAA098D439.pdf'
;
$pageCount
=
$pdf
->
setSourceFile
(
$file
);
for
(
$pageNo
=
1
;
$pageNo
<=
$pageCount
;
$pageNo
++){
$templateId
=
$pdf
->
importPage
(
$pageNo
);
$size
=
$pdf
->
getTemplateSize
(
$templateId
);
if
(
$size
[
'width'
] >
$size
[
'height'
]){
$pdf
->
AddPage
(
'L'
,
array
(
$size
[
'width'
],
$size
[
'height'
]));
}
else
{
$pdf
->
AddPage
(
'P'
,
array
(
$size
[
'width'
],
$size
[
'height'
]));
$pdf
->
useTemplate
(
$templateId
);
if
(
$type
==
1
){
$family
= [
'courier'
,
'helvetica'
,
'times'
,
'symbol'
,
'zapfdingbats'
];
$pdf
->
SetFont
(
'helvetica'
,
'U'
,
'50'
);
$center_x
=
$size
[
'width'
]/
2
;
$center_y
=
$size
[
'height'
]/
2
;
$pdf
->
SetXY
(
$center_x
,
$center_y
);
$pdf
->
Write
(
7
,
'ROOT_ICO'
);
}
else
{
$center_x
=
$size
[
'width'
]/
2
-
40
;
$center_y
=
$size
[
'height'
]/
2
;
$pdf
->
image
(
"Upload/all_to_path/report_file/water_mark.png"
,
$center_x
,
$center_y
,
80
);
$pdf
->
image
(
"Upload/all_to_path/report_file/water_mark2.png"
,
0
,
0
,
210
);
$pdf
->
Output
(
'F'
,
'Upload/all_to_path/report_file/save.pdf'
,
false
);
复制代码