0

I am working in LARAVEL 6.8.

I worknig on to generate New PDF which uses existing PDF as a background template. I have tried FPDF & FPDI packages but I couldn't find a way to add data in it. Below is the code which I have tried but this simple code also gives back the empty pdf.

$pdf = new \setasign\Fpdi\Fpdi();    
$pdf->AddPage();
$pdf->setSourceFile('existingPDFfile.pdf'); <--- This PDF has a header and footer already in it.

$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 200);

$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(50, 50);
$pdf->Write(0, "Ajay Patel");

$pdf->Output('D','test.pdf', "F");  

In further, I need to use this existing PDF as a template and want to add new data in the body of pdf and generate new pdf from it which has a background of this "Template PDF".

I hope i have explained myself.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
  • Your script imports the first page of the document `existingPDFfile.pdf` and places it onto your created page at the position 10mm, 10mm with a width of 200mm. The height is caluclated automatically in the aspect ratio. Then you write "Ajay Patel" at the position 50mm,50mm and output the document (the 3rd parameter of `Output()` is obsolete). I don't see any question or problem at all? – Jan Slabon Jan 28 '20 at 09:54
  • @JanSlabon needs to add a MySQL table and show table row in it. as simple table view. – always-a-learner Jan 28 '20 at 10:23
  • @JanSlabon and also the `existingPDFfile.pdf` is dynamic which may have header and footer with some variation every time so how could I major that and from where i will start the table to add in it. did you getting my point sir? – always-a-learner Jan 28 '20 at 10:25
  • Everything you describe are tasks and not problems... You should check out the tutorials and manual of [FPDF](http://fpdf.org/) and [FPDI](https://manuals.setasign.com/fpdi-manual/v2/) and simply code what you need ;-) – Jan Slabon Jan 28 '20 at 13:21

0 Answers0