Home > Net >  Writing multiple text fields to existing pdf document in php
Writing multiple text fields to existing pdf document in php

Time:10-13

I am a working program that adds a text to an existing pdf document.

The problem is I dont know how to add more than one ?

    <?php
/* pdf_creator.php */

$county = $_POST['county'];

require_once __DIR__ . '/vendor/autoload.php';

$pdf = new mPDF();

$pdf->SetImportUse();
$pdf->SetSourceFile('document.pdf');

$tplId = $pdf->ImportPage(1);
$pdf->UseTemplate($tplId);

//text number 1
$pdf->SetX(10);
$pdf->SetY(17.5);
$pdf->WriteHTML($county);

$pdf->Output('newdocument.pdf');

header('Location: newdocument.pdf');

How would I add another text with different x,y coordinates to the existing pdf?

CodePudding user response:

<?php
/* pdf_creator.php */

$county = $_POST['county'];
$county_one = $_POST['county_one'];

require_once __DIR__ . '/vendor/autoload.php';

$pdf = new mPDF();

$pdf->SetImportUse();
$pdf->SetSourceFile('document.pdf');

$tplId = $pdf->ImportPage(1);
$pdf->UseTemplate($tplId);

//text number 1
$pdf->SetX(10);
$pdf->SetY(17.5);
$pdf->WriteHTML($county);

//text number 2
$pdf->SetX(20);
$pdf->SetY(27.5);
$pdf->WriteHTML($county_one);

$pdf->Output('newdocument.pdf');

header('Location: newdocument.pdf');
  • Related