use Cubist\PDF\PDFTools;
use Cubist\Util\CommandLine;
use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Image;
use Cubist\Util\Math;
+use Illuminate\Support\Facades\Log;
class Poppler
{
const RESOLUTION_FACTOR = 72;
+ /**
+ * @throws \Exception
+ */
public static function extractArea($file, $page, $rect, $to = null, $options = array(), $cache = null)
{
if (null === $to && null === $cache) {
}
if ($options['format'] === 'svg') {
- $pdftocairo = new CommandLine('pdftocairo');
- $pdftocairo->setArg('-svg');
- $pdftocairo->setArg('-paperw', round($rect['width']));
- $pdftocairo->setArg('-paperh', round($rect['height']));
- self::_crop($pdftocairo, $page, $rect, 1, 1);
- self::_exec($pdftocairo, $file, $dest . '.' . $extension);
+ $destfile = $dest . '.' . $extension;
+ self::_pdftocairoRect($file, $page, $destfile, $rect);
+ $dim = Image::getimagesize($destfile);
+ // If result image direction is reverted (cf. bug #6094)
+ if (($dim[0] > $dim[1] && $rect['width'] < $rect['height']) || ($dim[1] > $dim[0] && $rect['height'] < $rect['width'])) {
+ self::_pdftocairoRect($file, $page, $destfile, $rect, true);
+ }
if (!$options['background']) {
PDFTools::makeTextSVGFile($dest . '.' . $extension, $dest . '.' . $extension);
}
return $res;
}
+ protected static function _pdftocairoRect($file, $page, $destfile, $rect, $invertPaper = false)
+ {
+ $pdftocairo = new CommandLine('pdftocairo');
+ $pdftocairo->setArg('-svg');
+ $pdftocairo->setArg('-paperw', round($invertPaper ? $rect['height'] : $rect['width']));
+ $pdftocairo->setArg('-paperh', round($invertPaper ? $rect['width'] : $rect['height']));
+ self::_crop($pdftocairo, $page, $rect, 1, 1);
+ self::_exec($pdftocairo, $file, $destfile);
+ }
+
/**
* @param $cli CommandLine
* @param $page int