Export Script

Retrieve the Ghostscript script generated by pdf-optimizer for external analysis or use. Choose between exportScriptAsString and exportScriptAsArray methods to obtain the script as a string or an array, respectively.

Retrieve the Ghostscript script or command generated by pdf-optimizer for further analysis or external use. The methods exportScriptAsString and exportScriptAsArray provide options to obtain the Ghostscript script as a string or an array, respectively.

To Array

use Mostafaznv\PdfOptimizer\PdfOptimizer;
use Mostafaznv\PdfOptimizer\Enums\ColorConversionStrategy;

# input file (optinal, could be null)
$input = 'path/to/large.pdf';

# output file (optinal, could be null)
$output = 'path/to/optimized.pdf';

# export script as array
$command = PdfOptimizer::init()
    ->compressFonts()
    ->colorImageResolution(60)
    ->colorConversionStrategy(ColorConversionStrategy::GRAY)
    ->command($input, $output);


var_dump($command);

To String

use Mostafaznv\PdfOptimizer\PdfOptimizer;
use Mostafaznv\PdfOptimizer\Enums\ColorConversionStrategy;

# input file (optinal, could be null)
$input = 'path/to/large.pdf';

# output file (optinal, could be null)
$output = 'path/to/optimized.pdf';

# export script as array
$command = PdfOptimizer::init()
    ->compressFonts()
    ->colorImageResolution(60)
    ->colorConversionStrategy(ColorConversionStrategy::GRAY)
    ->toString($input, $output);


echo $command;

Both the command and toString methods have optional parameters that allow for specifying the input and output file paths, providing a more personalized export.

Last updated