This is a follow up to Get write18 to execute after file parsing
With the code
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,grffile}
\newcommand{\filename}{}
\newcommand{\croppedfilename}{}
\makeatletter
\newcommand{\includecroppedgraphics}[1]{%
\filename@parse{#1}%
\edef\croppedfilename{\filename@area\filename@base.cropped.\filename@ext}%
\immediate\write18{pdfcrop #1 \croppedfilename}%
\fbox{\includegraphics[width=\linewidth]{\croppedfilename}}%
}
\makeatother
\begin{document}
\includecroppedgraphics{mypath/myimage.pdf}
\end{document}
I tried to crop a PDF. This did not work for my mutli-page PDF. What did work was the script
#!/bin/bash
temdirname="./croppedpages"
mkdir "$temdirname"
pdftk "$1" burst output "$temdirname"/Page_%03d.pdf
while read -d $'\0' pdfpage ; do
krop --go --autotrim -o "$pdfpage" "$pdfpage"
done < <(find "$temdirname" -print0)
pdftk "$temdirname"/*.pdf output "$2"
rm -R "$temdirname"
that I wrote based on
But it only works so far from the command line. Now I want to include it into the LaTeX script, but the call does not work. I thought I could simply change
\immediate\write18{pdfcrop #1 \croppedfilename}%
to
\immediate\write18{splitcropmerge.sh #1 \croppedfilename}%
In the log it says
runsystem(splitcropmerge.sh Pakete-Uebersicht/Pakete-Uebersicht.pdf Pakete-Uebe rsicht/Pakete-Uebersicht.cropped.pdf)...executed.
LaTeX Warning: File `Pakete-Uebersicht/Pakete-Uebersicht.cropped.pdf' not found on input line 187.
Krop was installed from package from arminstraub.com/downloads/krop/krop_0.5.0-1_all.deb according to https://www.linuxbabe.com/ubuntu/krop-debian-8-ubuntu-16-04-pdf-crop-tool with
sudo dpkg -i krop_0.5.0-1_all.deb
\immediate\write18{splitcropmerge.sh #1 \croppedfilename}%. You should specify the shell before the script name:\immediate\write18{bash splitcropmerge.sh #1 \croppedfilename}%– Phelype Oleinik Feb 26 '18 at 15:06