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
useMostafaznv\PdfOptimizer\PdfOptimizer;useMostafaznv\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);
useMostafaznv\PdfOptimizer\Laravel\Facade\PdfOptimizer;useMostafaznv\PdfOptimizer\Enums\ColorConversionStrategy;useMostafaznv\PdfOptimizer\Enums\PdfSettings;# input file (optinal, could be null)$input ='input.pdf';# output file (optinal, could be null)$output ='optimized.pdf';# export script as array$command =PdfOptimizer::open($input)->settings(PdfSettings::SCREEN)->colorConversionStrategy(ColorConversionStrategy::GRAY)->colorImageResolution(50)->command($input, $output);dd($command);
To String
useMostafaznv\PdfOptimizer\PdfOptimizer;useMostafaznv\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;
useMostafaznv\PdfOptimizer\Laravel\Facade\PdfOptimizer;useMostafaznv\PdfOptimizer\Enums\ColorConversionStrategy;useMostafaznv\PdfOptimizer\Enums\PdfSettings;# input file (optinal, could be null)$input ='input.pdf';# output file (optinal, could be null)$output ='optimized.pdf';# export script as array$command =PdfOptimizer::open($input)->settings(PdfSettings::SCREEN)->colorConversionStrategy(ColorConversionStrategy::GRAY)->colorImageResolution(50)->toString($input, $output);dd($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.