Page orientation

Jun 8, 2012 at 9:15 AM

is it possible to Change the page orientation to Landscape?

Jun 8, 2012 at 9:35 AM

I guess that it should auto detect the page size for every page on these code lines:

89: $template = $fpdi->importPage($i);
90: $size = $fpdi->getTemplateSize($template);
91: 
92: $fpdi->AddPage('P', array($size['w'], $size['h'])); 

But it doesn´t.

I had created landscape DinA4 pages with DOMpdf and with PDF Merger I get the pages in Portrait orientation so that the right side is outside the page.

Jun 8, 2012 at 12:51 PM

Just found the solution.

In PDFMerge.php i had to change line 91 and 101

From:

$fpdi->AddPage('P', array($size['w'], $size['h']));

To:

$fpdi->AddPage($format, array($size['w'], $size['h']));

 

"$format" could be "L" or "P" (or "l", "p", "landscape" or "portrait").

Nov 22, 2013 at 3:51 PM
Edited Nov 22, 2013 at 3:59 PM
Thanks for this, Amerlander

We just have to define $format with something like this at both locations:
if($size['w'] > $size['h'])
    $format = 'L';
if($size['w'] < $size['h'])
    $format = 'P';
Mar 11, 2014 at 1:09 PM
Edited Mar 11, 2014 at 2:15 PM
Hi everyone,

I modified pdfmerger.php with :
            //add the pages
            if($filepages == 'all')
            {
                for($i=1; $i<=$count; $i++)
                {
                    $template   = $fpdi->importPage($i);
                    $size       = $fpdi->getTemplateSize($template);
                    __if($size['w'] > $size['h'])
                    {
                        $format = 'L';
                    }
                    if($size['w'] < $size['h'])
                    {
                        $format = 'P';
                    }
                    $fpdi->AddPage($format, array($size['w'], $size['h']));__
                    $fpdi->useTemplate($template);
                }
            }
            else
            {
                foreach($filepages as $page)
                {
                    if(!$template = $fpdi->importPage($page)): throw new exception("Could not load page '$page' in PDF '$filename'. Check that the page exists."); endif;
                    $size = $fpdi->getTemplateSize($template);
                __  if($size['w'] > $size['h'])
                    {
                        $format = 'L';
                    }
                    if($size['w'] < $size['h'])
                    {
                        $format = 'P';
                    }
                    $fpdi->AddPage($format, array($size['w'], $size['h']));__
                    $fpdi->useTemplate($template);
                }
            }   
But the merge are in Portrait and not in Landscape.

Please, someone can help me ?
Mar 24, 2014 at 1:46 AM
Here's how you can rotate PDF page with simple codings!
Jun 18, 2014 at 3:26 PM
What I did to get this to work was make some changes to the merge method in the PDFMerger.php file.
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
    {
        if(!isset($this->_files) || !is_array($this->_files)): throw new exception("No PDFs to merge."); endif;
        
        $fpdi = new FPDI;
        
        //merger operations
        foreach($this->_files as $file)
        {
            $filename  = $file[0];
            $filepages = $file[1];
            
            $count = $fpdi->setSourceFile($filename);
            
            //add the pages
            if($filepages == 'all')
            {
                for($i=1; $i<=$count; $i++)
                {
                    $template   = $fpdi->importPage($i);
                    $size       = $fpdi->getTemplateSize($template);

                    if($size['w'] > $size['h'])
                        $format = 'L';
                    if($size['w'] < $size['h'])
                        $format = 'P';

                    $fpdi->AddPage($format, array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            }
            else
            {
                foreach($filepages as $page)
                {
                    if(!$template = $fpdi->importPage($page)): throw new exception("Could not load page '$page' in PDF '$filename'. Check that the page exists."); endif;
                    $size = $fpdi->getTemplateSize($template);

                    if($size['w'] > $size['h'])
                        $format = 'L';
                    if($size['w'] < $size['h'])
                        $format = 'P';

                    $fpdi->AddPage($format, array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            }   
        }
        
        //output operations
        $mode = $this->_switchmode($outputmode);
        
        if($mode == 'S')
        {
            return $fpdi->Output($outputpath, 'S');
        }
        else
        {
            if($fpdi->Output($outputpath, $mode))
            {
                return true;
            }
            else
            {
//              throw new exception("Error outputting PDF to '$outputmode'.");
                return true;
            }
        }
        
        
    }
Many thanks to ProfDestyNova for their snippet