src/Filter/PDFBox/PdfToImage.php
public function process(ThingInterface $thing, $sourcePath, OptionsInterface $options = null)
    {
        $tmpDir = $this->tmpFs->createTemporaryDirectory();

        /** @var DocumentImageOptions $options */
        $options = $this->defaults->merge($options);

        $pb = $this->pdfBox->getProcessBuilder()
            ->toImage()
            ->imageType($options->getFormat())
            ->output($tmpDir)
            ->source($sourcePath);

        if ($options->has($options::OPTION_PAGES)) {
            $pages = $options->getPages();

            if (strpos($pages, '-') !== false) {
                list($startPage, $endPage) = explode('-', $pages);
            } else {
                $startPage = $pages;
            }

            $startPage = intval($startPage);
            if (isset($endPage)) {
                $endPage = intval($endPage);
            }

            if ($startPage === 0) {
                // one based
                $startPage = 1;

                if (isset($endPage)) {
                    $endPage++;
                }
            }

            $pb->startPage($startPage);

            if (isset($endPage)) {
                $pb->endPage($endPage);
            }
        }

        $process = $pb->getProcess();

        $code = $process->run();
        if ($code !== 0) {
            throw ProcessingFailedException::create(
                'Failed to convert PDF to image',
                $code,
                $process->getOutput(),
                $process->getErrorOutput()
            );
        }

        $outputFiles = glob($tmpDir.'*.jpg');

        return $outputFiles;
    }
public function process(ThingInterface $thing, $sourcePath, OptionsInterface $options = null)
    {
        $tmpDir = $this->tmpFs->createTemporaryDirectory();

        /** @var DocumentImageOptions $options */
        $options = $this->defaults->merge($options);

        $pb = $this->pdfBox->getProcessBuilder()
            ->toImage()
            ->imageType($options->getFormat())
            ->output($tmpDir)
            ->source($sourcePath);

        if ($options->has($options::OPTION_PAGES)) {
            $pages = $options->getPages();

            if (strpos($pages, '-') !== false) {
                list($startPage, $endPage) = explode('-', $pages);
            } else {
                $startPage = $pages;
            }

            $startPage = intval($startPage);
            if (isset($endPage)) {
                $endPage = intval($endPage);
            }

            if ($startPage === 0) {
                // one based
                $startPage = 1;

                if (isset($endPage)) {
                    $endPage++;
                }
            }

            $pb->startPage($startPage);

            if (isset($endPage)) {
                $pb->endPage($endPage);
            }
        }

        $process = $pb->getProcess();

        $code = $process->run();
        if ($code !== 0) {
            throw ProcessingFailedException::create(
                'Failed to convert PDF to image',
                $code,
                $process->getOutput(),
                $process->getErrorOutput()
            );
        }

        $outputFiles = glob($tmpDir.'*.jpg');

        return $outputFiles;
    }
public function process ( ThingInterface $ thing , $ sourcePath , OptionsInterface $ options = null ) { $ tmpDir = $ this -> tmpFs -> createTemporaryDirectory ( ) ; /** @var DocumentImageOptions $options */ $ options = $ this -> defaults -> merge ( $ options ) ; $ pb = $ this -> pdfBox -> getProcessBuilder ( ) -> toImage ( ) -> imageType ( $ options -> getFormat ( ) ) -> output ( $ tmpDir ) -> source ( $ sourcePath ) ; if ( $ options -> has ( $ options :: OPTION_PAGES ) ) { $ pages = $ options -> getPages ( ) ; if ( strpos ( $ pages , '-' ) !== false ) { list ( $ startPage , $ endPage ) = explode ( '-' , $ pages ) ; } else { $ startPage = $ pages ; } $ startPage = intval ( $ startPage ) ; if ( isset ( $ endPage ) ) { $ endPage = intval ( $ endPage ) ; } if ( $ startPage === 0 ) { // one based $ startPage = 1 ; if ( isset ( $ endPage ) ) { $ endPage ++ ; } } $ pb -> startPage ( $ startPage ) ; if ( isset ( $ endPage ) ) { $ pb -> endPage ( $ endPage ) ; } } $ process = $ pb -> getProcess ( ) ; $ code = $ process -> run ( ) ; if ( $ code !== 0 ) { throw ProcessingFailedException :: create ( 'Failed to convert PDF to image' , $ code , $ process -> getOutput ( ) , $ process -> getErrorOutput ( ) ) ; } $ outputFiles = glob ( $ tmpDir . '*.jpg' ) ; return $ outputFiles ; }
@param ThingInterface   $thing
@param string           $sourcePath
@param OptionsInterface $options

@throws \Asoc\Dadatata\Exception\ProcessingFailedException
@return array Paths to generated files
@param ThingInterface $thing @param string $sourcePath @param OptionsInterface $options