Skip to content

Commit

Permalink
Acquire Support for PDFToText from https://github.com/townsweb/popple…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncjoes committed Feb 13, 2019
2 parents ad174cd + 5532759 commit 615603f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/PopplerPhp/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ abstract class Constants
const _ICC = '-icc';
const _LEVEL2 = '-level2';
const _LEVEL3 = '-level3';
const _BBOX_LAYOUT = '-bbox-layout';
const _LAYOUT = '-layout';
const _BOX = '-box';

//Poppler Option DataTypes
const T_STRING = 'string';
Expand Down
3 changes: 3 additions & 0 deletions src/PopplerPhp/PdfInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use NcJoes\PopplerPhp\PopplerOptions\CredentialOptions;
use NcJoes\PopplerPhp\PopplerOptions\DateFlags;
use NcJoes\PopplerPhp\PopplerOptions\EncodingOptions;
use NcJoes\PopplerPhp\PopplerOptions\InfoFlags;
use NcJoes\PopplerPhp\PopplerOptions\PageRangeOptions;

class PdfInfo extends PopplerUtil
Expand All @@ -23,6 +24,7 @@ class PdfInfo extends PopplerUtil
use EncodingOptions;
use PageRangeOptions;
use ConsoleFlags;
use InfoFlags;

private $pdf_info;

Expand Down Expand Up @@ -211,6 +213,7 @@ public function utilOptionRules()
public function utilFlags()
{
return array_merge(
$this->infoFlags(),
$this->dateFlags(),
$this->encodingFlags(),
$this->allConsoleFlags()
Expand Down
33 changes: 28 additions & 5 deletions src/PopplerPhp/PdfToText.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@
namespace NcJoes\PopplerPhp;

use NcJoes\PopplerPhp\Constants as C;
use NcJoes\PopplerPhp\PopplerOptions\ConsoleFlags;
use NcJoes\PopplerPhp\PopplerOptions\CredentialOptions;
use NcJoes\PopplerPhp\PopplerOptions\EncodingOptions;
use NcJoes\PopplerPhp\PopplerOptions\HtmlOptions;
use NcJoes\PopplerPhp\PopplerOptions\PageRangeOptions;
use NcJoes\PopplerPhp\PopplerOptions\TextFlags;

class PdfToText extends PopplerUtil
{
use PageRangeOptions;
use ConsoleFlags;
use HtmlOptions;
use EncodingOptions;
use CredentialOptions;
use TextFlags;


/**
* PdfToCairo constructor.
*
Expand All @@ -28,22 +42,31 @@ public function __construct($pdfFile = '', array $options = [])

public function utilOptions()
{
return $this->pageRangeOptions();
return array_merge(
$this->pageRangeOptions(),
$this->htmlOptions(),
$this->credentialOptions(),
$this->encodingOptions()
);
}

public function utilOptionRules()
{
return [];
return [
'alt' => [],
];
}

public function utilFlags()
{
return [];
return $this->textFlags();
}

public function utilFlagRules()
{
return [];
return [
'alt' => [],
];
}

public function outputExtension()
Expand Down Expand Up @@ -78,4 +101,4 @@ protected function pageRangeOptions()
C::_L => C::T_INTEGER,
];
}
}
}
18 changes: 18 additions & 0 deletions src/PopplerPhp/PopplerOptions/InfoFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace NcJoes\PopplerPhp\PopplerOptions;

use NcJoes\PopplerPhp\Constants as C;

trait InfoFlags
{
public function setBox()
{
return $this->setFlag(C::_BOX);
}

protected function infoFlags()
{
return [C::_BOX];
}
}
23 changes: 23 additions & 0 deletions src/PopplerPhp/PopplerOptions/TextFlags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace NcJoes\PopplerPhp\PopplerOptions;

use NcJoes\PopplerPhp\Constants as C;

trait TextFlags
{
public function setBboxLayout()
{
return $this->setFlag(C::_BBOX_LAYOUT);
}

public function setLayout()
{
return $this->setFlag(C::_LAYOUT);
}

protected function textFlags()
{
return [C::_BBOX_LAYOUT, C::_LAYOUT];
}
}
38 changes: 35 additions & 3 deletions src/PopplerPhp/PopplerUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ abstract class PopplerUtil
{
protected $bin_file;
protected $output_file_extension;
protected $output_file_suffix = '';
protected $require_output_dir = true;
protected $require_sub_dir = true;
protected $output_file_suffix = '';
private $binary_dir;
private $flags = [];
private $options = [];
private $source_pdf;
private $output_sub_dir;
private $output_file_name;


/**
* PopplerUtil constructor.
*
* @param string $pdfFile
* @param array $options
* @throws PopplerPhpException
*/
public function __construct($pdfFile = '', array $options = [])
{
Expand Down Expand Up @@ -111,7 +113,7 @@ public function getOutputSubDir()
*/
public function getOutputPath()
{
return Config::getOutputDirectory().C::DS.$this->getOutputSubDir();
return Config::getOutputDirectory().C::DS.($this->isSubDirRequired() ? $this->getOutputSubDir() : '');
}

/**
Expand Down Expand Up @@ -408,6 +410,36 @@ public function getOutputFilenamePrefix()
return $default_name;
}

/**
* @param bool $bool
* @return $this
*/
public function setRequireOutputDir($bool)
{
$this->require_output_dir = $bool;

return $this;
}

/**
* @return bool
*/
public function isSubDirRequired()
{
return $this->output_sub_dir;
}

/**
* @param bool $bool
* @return $this
*/
public function setSubDirRequired($bool)
{
$this->output_sub_dir = $bool;

return $this;
}

/**
* @return mixed
*/
Expand Down

0 comments on commit 615603f

Please sign in to comment.