ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 69 of file class.ilCountPDFPages.php.

69 : ?int
70 {
71 if (!$this->postscript_available && !$this->imagick_available) {
72 return null;
73 }
74
75 // first we try using Imagick
76 if ($this->imagick_available) {
77 $pages = null;
78 try {
79 $imagick = new Imagick();
80 $imagick->pingImage($path_to_pdf);
81
82 return $imagick->getNumberImages();
83 } catch (Throwable) {
84 // Imagick is not available or another error occured
85 }
86 }
87
88 if ($this->postscript_available) {
89 $arg = "-q -dNODISPLAY -dNOSAFER -c \"($path_to_pdf) (r) file runpdfbegin pdfpagecount = quit\";";
90 $return = ilShellUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $arg);
91 if (!isset($return[0]) || ($pages = (int) $return[0]) === 0) {
92 return null;
93 }
94
95 return $pages;
96 }
97
98 return null;
99 }
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 // the same condition as in isAvailable() and extractAmountOfPagesByPath():
54 // asking for Ghostscript alone skipped the page count on every installation
55 // that only has Imagick, see https://mantis.ilias.de/view.php?id=47827
56 if (!$this->postscript_available && !$this->imagick_available) {
57 return null;
58 }
59 $revision = $this->irss->manage()->getCurrentRevision($rid);
60 $info = $revision->getInformation();
61 if ($info->getMimeType() !== MimeType::APPLICATION__PDF) {
62 return null;
63 }
64 $consumer = $this->irss->consume()->stream($rid);
65 $path_to_pdf = $consumer->getStream()->getMetadata('uri');
66 return $this->extractAmountOfPagesByPath($path_to_pdf);
67 }
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: