Hello, I have a question with using TCPDF. I need to import one external pdf
file into the new pdf file created with TCPDF. My aim is to insert a watermark
in the new one. Is this possible with TCPDF?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FPDI is a TCPDF class wrapper, which can extend TCPDF class ad add extra
features, such as importing pages from another binary PDF file. That means,
you would create class like FPDI_TCPDF extends TCPDF, and then use FPDI
command to parse existing PDF file and import desired page into it.
Yet, you can normally insert images in such a class, e.g.
FPDI_TCPDF->image(params...) just like normal TCPDF.
I wonder, if Nicola would add such a feature for importing parsed external
files. Solution actually already exists (FPDI) and I use it, but it is kind of
pain to rename classes with each TCPDF upgrade:-)
Cheers
Lubos
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You don't have to rename anything... just initiate FPDI instead of TCPDF and
everything will work as before... but you have the new methods for importing
existing pages... There's no need to touch at least one line if you update
TCPDF.
Cheers!
Jan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I have a question with using TCPDF. I need to import one external pdf
file into the new pdf file created with TCPDF. My aim is to insert a watermark
in the new one. Is this possible with TCPDF?
Thanks
Check this: http://www.setasign.de/products/pdf-php-
solutions/fpdi/
Cheers!
Jan
Yes with FPDI, not TCPDF, but with FPDI is not possible insert a background
image.
Could you be more specific? Why should it be impossible to use a background
image with FPDI?
I have not found any FPDI manual, what is the command to insert a background
image with FPDI? Can you help me?
How would you insert a background image with TCPDF?
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// full background image
// store current auto-page-break status
$bMargin = $this->getBreakMargin();
$auto_page_break = $this->AutoPageBreak;
$this->SetAutoPageBreak(false, 0);
//$img_file = K_PATH_IMAGES.'image_demo.jpg';
$img_file = '../../upload/img/utente.jpg';
$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false,
false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true,
'UTF-8', false);
$pdf->addPage();
$pdf->Output('new.pdf', 'I');
so... simply extends FPDI instead of TCPDF and you should have the same
result. It's simply PHP...
There is no such a command.
FPDI is a TCPDF class wrapper, which can extend TCPDF class ad add extra
features, such as importing pages from another binary PDF file. That means,
you would create class like FPDI_TCPDF extends TCPDF, and then use FPDI
command to parse existing PDF file and import desired page into it.
Yet, you can normally insert images in such a class, e.g.
FPDI_TCPDF->image(params...) just like normal TCPDF.
I wonder, if Nicola would add such a feature for importing parsed external
files. Solution actually already exists (FPDI) and I use it, but it is kind of
pain to rename classes with each TCPDF upgrade:-)
Cheers
Lubos
You don't have to rename anything... just initiate FPDI instead of TCPDF and
everything will work as before... but you have the new methods for importing
existing pages... There's no need to touch at least one line if you update
TCPDF.
Cheers!
Jan
I tried using FPDI to import a PDF file to TCPDF and got empty document.
I used the following code:
require_once('tcpdf/tcpdf.php');
include('fpdi/fpdi.php');
$pdf = new FPDI
$pdf->setInputFile($fname);
$pdf->importPage(1);
$pdf->Output("test.pdf", D);