mikehaertl\pdftk\Pdf::shuffle PHP Method

shuffle() public method

This works the same as cat(), but each call to this method creates a "stream" of pages. The outfile will be assembled by adding one page from each stream at a time. Example: $pdf = new Pdf; $pdf1 = $pdf->addFile('file1.pdf'); $pdf->cat($pdf1, array(1,3,2)) ->cat($pdf1, array(4,5,9) ->saveAs('out.pdf'); This will give the page order 1, 4, 3, 5, 2, 9 in the out.pdf
public shuffle ( integer | array $start, integer | null $end = null, string $handle = null, string | null $qualifier = null, string $rotation = null ) : Pdf
$start integer | array the start page number or an array of page numbers.
$end integer | null the end page number or null for single page (or list if $start is an array)
$handle string the handle of the input file to use
$qualifier string | null the page number qualifier, either 'even' or 'odd' or null for none
$rotation string the rotation to apply to the pages. See cat() for more details.
return Pdf the pdf instance for method chaining
    public function shuffle($start, $end = null, $handle = null, $qualifier = null, $rotation = null)
    {
        $this->getCommand()->setOperation('shuffle')->addPageRange($start, $end, $handle, $qualifier, $rotation);
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 public function testCanShuffleFiles()
 {
     $document1 = $this->getDocument1();
     $document2 = $this->getDocument2();
     $file = $this->getOutFile();
     $pdf = new Pdf(array('A' => $document1, 'B' => $document2));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle(1, 5, 'A'));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle(array(2, 3, 4), 'B'));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle('end', '2', 'B', 'even'));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle(3, 5, 'A', null, 'east'));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle(4, 8, 'B', 'even', 'east'));
     $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->shuffle(1, null, 'A', null, 'south'));
     $this->assertTrue($pdf->saveAs($file));
     $this->assertFileExists($file);
     $tmpFile = (string) $pdf->getTmpFile();
     $this->assertEquals("pdftk A='{$document1}' B='{$document2}' shuffle A1-5 2 3 4 Bend-2even A3-5east B4-8eveneast A1south output '{$tmpFile}'", (string) $pdf->getCommand());
 }