Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ghostscript with exiftool #1424

Merged
merged 3 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/software-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Open XDMoD requires the following software:
- [Chromium][]
- `chromium-headless` is assumed, but chromium has been known to work
- [libRsvg][]
- [ghostscript][] 9+
- [exiftool][]
- [cron][]
- [logrotate][]
- [MTA][] with `sendmail` compatibility (e.g. [postfix][], [exim][] or
Expand Down Expand Up @@ -54,7 +54,7 @@ Open XDMoD requires the following software:
[jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
[chromium]: https://www.chromium.org/Home
[librsvg]: https://wiki.gnome.org/Projects/LibRsvg
[ghostscript]: https://www.ghostscript.com/
[exiftool]: http://www.sno.phy.queensu.ca/%7Ephil/exiftool/
[cron]: https://en.wikipedia.org/wiki/Cron
[logrotate]: https://linux.die.net/man/8/logrotate
[mta]: https://en.wikipedia.org/wiki/Message_transfer_agent
Expand Down
8 changes: 4 additions & 4 deletions docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ changed in the new version. You do not need to merge
If you have manually edited this file, you should create a backup and
merge any changes after running the upgrade script.

*NOTE: This upgrade changes the dependency on `PhantomJS` to `chromium` and `libRSVG`. These new dependencies will need to be manually installed. See the [Software Requirements](software-requirements.html) for more details.
`PhantomJS` is no longer required by Open XDMoD and will need to be removed manually.*
*NOTE: This upgrade removes the `PhantomJS` and `ghostscript` dependencies; it adds dependencies of `chromium`, `libRSVG` and `exiftool`. These new dependencies will need to be manually installed. See the [Software Requirements](software-requirements.html) for more details.
`PhantomJS` s no longer required, however, it WILL NOT be removed automatically; it will need to be removed manually.*

### Verify Server Configuration Settings

Expand All @@ -108,8 +108,8 @@ enhancements and bug fixes.

You may upgrade directly from 9.0.0.

*NOTE: This upgrade changes the dependency on `PhantomJS` to `chromium` and `libRSVG`. These new dependencies will be automatically installed by the RPM.
`PhantomJS` WILL NOT be removed automatically; it will need to be removed manually.*
*NOTE: This upgrade removes the `PhantomJS` and `ghostscript` dependencies; it adds dependencies of `chromium`, `libRSVG` and `exiftool`.. These new dependencies will be automatically installed by the RPM.
`PhantomJS` s no longer required, however, it WILL NOT be removed automatically; it will need to be removed manually.*
plessbd marked this conversation as resolved.
Show resolved Hide resolved

### Configuration File Changes

Expand Down
49 changes: 9 additions & 40 deletions libraries/charting.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function getScreenFromChromium($file, $width, $height, $format){

function svg2pdf($inputFilename, $width, $height, $metaData){
$outputFilename = $inputFilename . '.pdf';
$command = 'rsvg-convert -f pdf -o ' . $outputFilename . ' ' . $inputFilename;
$command = 'rsvg-convert -w ' .$width. ' -h '.$height.' -f pdf -o ' . $outputFilename . ' ' . $inputFilename;
$pipes = array();
$descriptor_spec = array(
0 => array('pipe', 'r'),
Expand All @@ -189,67 +189,37 @@ function svg2pdf($inputFilename, $width, $height, $metaData){
if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}
$data = getPdfWithMetadata($outputFilename, $width, $height, $metaData);
$data = getPdfWithMetadata($outputFilename, $metaData);
@unlink($outputFilename);
return $data;
}

/**
* @param array $docmenta array with optional author, subject and title elements
* @return string valid pdfmark postscript for use by ghostscript
*/
function getPdfMark($docmeta)
{
$author = isset($docmeta['author']) ? addcslashes($docmeta['author'], "()\n\\") : 'XDMoD';
$subject = isset($docmeta['subject']) ? addcslashes($docmeta['subject'], "()\n\\") : 'XDMoD chart';
$title = isset($docmeta['title']) ? addcslashes($docmeta['title'], "()\n\\") :'XDMoD PDF chart export';
$creator = addcslashes('XDMoD ' . OPEN_XDMOD_VERSION, "()\n\\");

$pdfmark = <<<EOM
[ /Title ($title)
/Author ($author)
/Subject ($subject)
/Creator ($creator)
/DOCINFO pdfmark
EOM;
return $pdfmark;
}

/**
* Use ghostscript to add metadata to the PDF file and set the paper size correctly.
* Use exiftool to set document metadata.
*
* @param string $pdfFilename of PDF file
* @param int $widthPsPoints the new paper size in postscript points (72 ppi).
* @param int $heightPsPoints the new paper size in postscript points (72 ppi).
* @param array $docmeta array containing metadata fields
*
* @return string PDF document
*/
function getPdfWithMetadata($pdfFilename, $widthPsPoints, $heightPsPoints, $docmeta)
{
$command = <<<EOC
gs -o- -sstdout=/dev/stderr -sDEVICE=pdfwrite \
-dDEVICEWIDTHPOINTS=$widthPsPoints -dDEVICEHEIGHTPOINTS=$heightPsPoints \
-dPDFFitPage -dFIXEDMEDIA -dAutoRotatePages=/None -dCompatibilityLevel=1.4 \
$pdfFilename -
EOC;
function getPdfWithMetadata($fileName, $docmeta){
$author = isset($docmeta['author']) ? addcslashes($docmeta['author'], "()\n\\") : 'XDMoD';
$subject = isset($docmeta['subject']) ? addcslashes($docmeta['subject'], "()\n\\") : 'XDMoD chart';
$title = isset($docmeta['title']) ? addcslashes($docmeta['title'], "()\n\\") :'XDMoD PDF chart export';
$creator = addcslashes('XDMoD ' . OPEN_XDMOD_VERSION, "()\n\\");

$command = "exiftool -Title='$title' -Author='$author' -Subject='$subject' -Creator='$creator' -o - $fileName";
$pipes = array();
$descriptor_spec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);

$process = proc_open($command, $descriptor_spec, $pipes);

if (!is_resource($process)) {
throw new \Exception('Unable execute command: "'. $command . '". Details: ' . print_r(error_get_last(), true));
}

fwrite($pipes[0], getPdfMark($docmeta));
fclose($pipes[0]);

$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);

Expand All @@ -261,6 +231,5 @@ function getPdfWithMetadata($pdfFilename, $widthPsPoints, $heightPsPoints, $docm
if ($return_value != 0) {
throw new \Exception("$command returned $return_value, stdout: $out stderr: $err");
}

return $out;
}
5 changes: 3 additions & 2 deletions open_xdmod/modules/xdmod/xdmod.spec.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name: xdmod
name: xdmod
Version: __VERSION__
Release: __RELEASE__%{?dist}
Summary: Data warehouse and web portal for mining statistical data from resource managers
Expand All @@ -20,7 +20,7 @@ Requires: chromium-headless
Requires: librsvg2-tools
Requires: crontabs
Requires: logrotate
Requires: ghostscript
Requires: perl-Image-ExifTool
Requires: jq

%description
Expand Down Expand Up @@ -96,6 +96,7 @@ rm -rf $RPM_BUILD_ROOT
%changelog
* Tue Aug 18 2020 XDMoD <ccr-xdmod-list@listserv.buffalo.edu> 9.5.0-1.0
- Add `chromium-headless` and `librsvg2-tools` to required dependencies
- Replace `ghostscript` with `exiftool`
* Thu Aug 13 2020 XDMoD <ccr-xdmod-list@listserv.buffalo.edu> 9.0.0-1.0
- Release 9.0.0
- Add `mod_ssl` to required dependencies
Expand Down