上一篇发了一个对pdf文档进行"建立及操作PDF文件"的类,这里将介绍另一个pdf的类,主要是对pdf文档进行操作的.具体功能这里不是详细简介,其实我也刚刚接触的,反正功能不算弱,就推荐给大家了,如果用手头没有好的可以试一下这个的,呵呵
Imports a single page of an existing PDF document and adds text in front of it.
require_once(‘fpdi.php’);
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
$pdf->SetFont(‘Arial’,”,10);
// set the sourcefile
$pdf->setSourceFile(‘PDFDocument.pdf’);
// import MediaBox from page 1
$box = ‘/MediaBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 10, 15, 50);
$pdf->Rect(10, 15, $size[‘w’], $size[‘h’]);
// reimport page ones CropBox
$box = ‘/CropBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 70, 15, 50);
$pdf->Rect(70, 15, $size[‘w’], $size[‘h’]);
// reimport page ones TrimBox
$box = ‘/TrimBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 130, 15, 50);
$pdf->Rect(130, 15, $size[‘w’], $size[‘h’]);
$pdf->ln(45);
// reimport page ones BleedBox
$box = ‘/BleedBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 10, 60, 50);
$pdf->Rect(10, 60, $size[‘w’], $size[‘h’]);
// reimport page ones ArtBox
$box = ‘/ArtBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 70, 60, 50);
$pdf->Rect(70, 60, $size[‘w’], $size[‘h’]);
$pdf->Output(‘newpdf.pdf’, ‘D’);
This demo creates a thumbnail overview of an existing PDF document.
require(‘fpdi.php’);
$pdf =& new FPDI();
$pagecount = $pdf->setSourceFile(‘pdfdoc.pdf’);
$w = $pdf->w/2 – 15;
$h = 0;
$_x = $x = 10;
$_y = $y = 10;
$pdf->addPage();
for ($n = 1; $n <= $pagecount; $n++) {
$tplidx = $pdf->ImportPage($n);
$size = $pdf->useTemplate($tplidx, $x, $y, $w);
$pdf->Rect($x, $y, $size[‘w’], $size[‘h’]);
$h = max($h, $size[‘h’]);
if ($n % 2 == 0) {
$y += $h+10;
$x = $_x;
$h = 0;
} else {
$x += $w+10;
}
if ($n % 4 == 0 && $n != $pagecount) {
$pdf->AddPage();
$x = $_x;
$y = $_y;
}
}
$pdf->Output(‘newpdf.pdf’, ‘D’);
A concatenation of PDF documents.
require(‘fpdi.php’);
class concat_pdf extends FPDI {
var $files = array();
function setFiles($files) {
$this->files = $files;
}
function concat() {
foreach($this->files AS $file) {
$pagecount = $this->setSourceFile($file);
for ($i = 1; $i <= $pagecount; $i++) {
$tplidx = $this->ImportPage($i);
$s = $this->getTemplatesize($tplidx);
$this->AddPage($s[‘h’] > $s[‘w’] ? ‘P’ : ‘L’);
$this->useTemplate($tplidx);
}
}
}
}
$pdf =& new concat_pdf();
$pdf->setFiles(array(‘pdfdoc1.pdf’, ‘pdfdoc2.pdf’, ‘pdfdoc3.pdf’));
$pdf->concat();
$pdf->Output(‘newpdf.pdf’, ‘D’);
Import different boxes of a single page.
require_once(‘fpdi.php’);
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
$pdf->SetFont(‘Arial’,”,10);
// set the sourcefile
$pdf->setSourceFile(‘PDFDocument.pdf’);
// import MediaBox from page 1
$box = ‘/MediaBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 10, 15, 50);
$pdf->Rect(10, 15, $size[‘w’], $size[‘h’]);
// reimport page ones CropBox
$box = ‘/CropBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 70, 15, 50);
$pdf->Rect(70, 15, $size[‘w’], $size[‘h’]);
// reimport page ones TrimBox
$box = ‘/TrimBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 130, 15, 50);
$pdf->Rect(130, 15, $size[‘w’], $size[‘h’]);
$pdf->ln(45);
// reimport page ones BleedBox
$box = ‘/BleedBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 10, 60, 50);
$pdf->Rect(10, 60, $size[‘w’], $size[‘h’]);
// reimport page ones ArtBox
$box = ‘/ArtBox’;
$pdf->Cell(60, 4, $box);
$tplIdx = $pdf->importPage(1, $box);
$size = $pdf->useTemplate($tplIdx, 70, 60, 50);
$pdf->Rect(70, 60, $size[‘w’], $size[‘h’]);
$pdf->Output(‘newpdf.pdf’, ‘D’);
此类需要两个文件:
文件1:点击本地下载
文件2:点击本地下载