ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCountPDFPages Class Reference

Class ilCountPDFPages. More...

+ Collaboration diagram for ilCountPDFPages:

Public Member Functions

 __construct ()
 
 isAvailable ()
 
 extractAmountOfPagesByRID (ResourceIdentification $rid)
 
 extractAmountOfPagesByPath (string $path_to_pdf)
 

Private Attributes

Services $irss
 @readonly More...
 
bool $postscript_available = false
 
bool $imagick_available = false
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCountPDFPages::__construct ( )

Definition at line 38 of file class.ilCountPDFPages.php.

39 {
40 global $DIC;
41 $this->irss = $DIC->resourceStorage();
42 $this->postscript_available = (defined('PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !== "");
43 $this->imagick_available = class_exists('Imagick');
44 }
global $DIC
Definition: shib_login.php:26

References $DIC.

Member Function Documentation

◆ extractAmountOfPagesByPath()

ilCountPDFPages::extractAmountOfPagesByPath ( string  $path_to_pdf)

Definition at line 66 of file class.ilCountPDFPages.php.

66 : ?int
67 {
68 if (!$this->postscript_available && !$this->imagick_available) {
69 return null;
70 }
71
72 // first we try using Imagick
73 if ($this->imagick_available) {
74 $pages = null;
75 try {
76 $imagick = new Imagick();
77 $imagick->pingImage($path_to_pdf);
78
79 return $imagick->getNumberImages();
80 } catch (Throwable) {
81 // Imagick is not available or another error occured
82 }
83 }
84
85 if ($this->postscript_available) {
86 $arg = "-q -dNODISPLAY -dNOSAFER -c \"($path_to_pdf) (r) file runpdfbegin pdfpagecount = quit\";";
87 $return = ilShellUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $arg);
88 if (!isset($return[0]) || ($pages = (int) $return[0]) === 0) {
89 return null;
90 }
91
92 return $pages;
93 }
94
95 return null;
96 }
static execQuoted(string $cmd, ?string $args=null)

References ilShellUtil\execQuoted().

Referenced by extractAmountOfPagesByRID().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extractAmountOfPagesByRID()

ilCountPDFPages::extractAmountOfPagesByRID ( ResourceIdentification  $rid)

Definition at line 51 of file class.ilCountPDFPages.php.

51 : ?int
52 {
53 if (!$this->postscript_available) {
54 return null;
55 }
56 $revision = $this->irss->manage()->getCurrentRevision($rid);
57 $info = $revision->getInformation();
58 if ($info->getMimeType() !== MimeType::APPLICATION__PDF) {
59 return null;
60 }
61 $consumer = $this->irss->consume()->stream($rid);
62 $path_to_pdf = $consumer->getStream()->getMetadata('uri');
63 return $this->extractAmountOfPagesByPath($path_to_pdf);
64 }
extractAmountOfPagesByPath(string $path_to_pdf)
$info
Definition: entry_point.php:21

References $info, and extractAmountOfPagesByPath().

+ Here is the call graph for this function:

◆ isAvailable()

ilCountPDFPages::isAvailable ( )

Definition at line 46 of file class.ilCountPDFPages.php.

46 : bool
47 {
48 return $this->postscript_available || $this->imagick_available;
49 }

References $imagick_available.

Field Documentation

◆ $imagick_available

bool ilCountPDFPages::$imagick_available = false
private

Definition at line 36 of file class.ilCountPDFPages.php.

Referenced by isAvailable().

◆ $irss

Services ilCountPDFPages::$irss
private

@readonly

Definition at line 34 of file class.ilCountPDFPages.php.

◆ $postscript_available

bool ilCountPDFPages::$postscript_available = false
private

Definition at line 35 of file class.ilCountPDFPages.php.


The documentation for this class was generated from the following file: