0

I am creating a PDF for our clients website. The PDF is paginated for an A4 print. At the end I need to insert several existing PDFs.

Using the FPDI library works fine except when the inserted PDF is wider than the the A4 width, it doesn't rescale. In the documentation I've found 2 examples of how to do it, none seems to deliver:

  1. First example

    $varPageId = $objPDF->ImportPage($intPageNumber);
    $varTemplateSize = $objPDF->getTemplatesize($varPageId);
    $objPDF->AddPage(
            $varTemplateSize['orientation']
            , $varTemplateSize
            );
    $objPDF->useImportedPage($varPageId);
    
  2. Second example

    $varPageId = $objPDF->ImportPage($intPageNumber);
    $objPDF->AddPage();
    $objPDF->useTemplate(
            $varPageId
            , ['adjustpageSize' => true]
            );
    

Would anyone know how I can make sure the inserted PDF gets rescaled and all the content is displayed in the new denerated PDF?

Thanks in advance!

mtr.web
  • 1,505
  • 1
  • 13
  • 19
  • Both examples will work as expected. What error do you get exactly? Are you using the latest version? – Jan Slabon Apr 19 '18 at 18:01
  • Thanks for your answer. It is possible my expectations are wrong. I'm creating a A4 pdf. I need to inswert an A3 PDF in landsacape at the end of my first PDF which is A4 portrait. I'm not getting any error either. But the result is my inserted PDF is cut off at the A4 margin. What I need is for it to get rescaled so that the whole width of my A3 landscape pdf is visible inside the original A4 width. Or, even better, I would want the final PDF to change format for the attached page and go from A4 portrait to whatever size the inserted page has. – Jan Zelenka Apr 21 '18 at 12:36
  • Both examples do exactly what you want (make the page the same size as the imported one), so there must be another issue. ARE YOU USING THE LATEST VERSION? – Jan Slabon Apr 21 '18 at 20:55
  • I'm using 2.0.2. I see there is 2.0.3. since 18.4., will give it a try but I can't see anything related in the relesase notes... – Jan Zelenka Apr 23 '18 at 08:38
  • I have tried with 2.0.3, the same result unfortunatelly. Just to make myself absolutely clear, here is the file I'm trying to insert: https://nofile.io/f/jYBQsaNCe2b/Large.pdf And here the result: https://nofile.io/f/jG2aNRn6pDa/801_267.pdf – Jan Zelenka Apr 26 '18 at 12:08

1 Answers1

0

Works as expected. Here is a real example using following following code:

<?php

require_once 'vendor/autoload.php';

$pdf = new \setasign\Fpdi\TcpdfFpdi();

$pageCount = $pdf->setSourceFile('p.pdf');
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    $pageId = $pdf->importPage($pageNo);
    $s = $pdf->getTemplatesize($pageId);
    $pdf->AddPage($s['orientation'], $s);
    $pdf->useImportedPage($pageId);
}

$pdf->Output();
Jan Slabon
  • 4,736
  • 2
  • 14
  • 29
  • Thanks for taking your time to actually create a sample. There is one difference between what you did and what we do. You created a blank PDF and inserted the bew file. We create a new PDF, create several pages and then insert the sepaeate PDF. we use this code to create our PDF: $objPDF = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false); $objPDF->SetCreator('preop.be'); $objPDF->SetAuthor($strHospitalName); $objPDF->SetTitle('Vragenlijst preop.be'); $objPDF->SetFont('helvetica', '', 9); Is it possible that the parameters we pass to the constructor cause us to fail? – Jan Zelenka May 04 '18 at 09:03
  • It could be everything... but this is out of my scope as I'm not a psychic ;-) At the end everything of the code is open source. So what stops you from debugging it? – Jan Slabon May 05 '18 at 14:19
  • Budget, pretty much. Thanks for all the valueable info anyway! – Jan Zelenka May 14 '18 at 10:35