Reputation: 649
In my PDF I need to create a cover page. It would be very handy if it's possible to create the cover page, add further pages and while adding the other pages, go back to the cover page and add more content.
The following works well (Example1):
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
This generates a well rendered cover page.
The following doesn't work as expected (Example2):
// Add Cover page
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
// Add some content page(s)
$pdf->AddPage();
$pdf->writeHTML('<p>Content page...</p>', true, false, false, false, '');
// Go back to cover page and add more content...
$pdf->setPage(1);
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
The 2 lines on the cover page do overlap (or at least they are not positioned as well as in example1).
Is there any way to jump to an exising page and append some content?
Upvotes: 0
Views: 3262
Reputation: 649
Hm, got it. You can get/set the Y-position of the current page.
The following works:
// Add Cover page
$pdf->AddPage();
$pdf->writeHTML('<h1>COVER PAGE HERE!</h1>', true, false, false, false, '');
$start_y = $pdf->GetY();
// Add some content page(s)
$pdf->AddPage();
$pageNo = $pdf->getPage();
$pdf->writeHTML('<p>Content page...</p>', true, false, false, false, '');
// Go to cover page and add more content...
$pdf->setPage(1);
$pdf->setY($start_y);
$pdf->writeHTML('<h2>Some more content for cover page!</h2>', true, false, false, false, '');
// Go back to current page
$pdf->setPage($pageNo);
For some reason PHPStorm doesn't show this methods in the code completion, so I've overseen them...
Upvotes: 1