[clug] Howto change /Title in PDFs?
Joshua Rich
joshua.rich at gmail.com
Wed Aug 15 05:28:28 MDT 2012
Hi Scott,
You can use ghostscript in a bash script to do this, here is a script I use
that you are free to use and adapt:
#!/bin/bash
GS_OPTS='-q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPAPERSIZE=a4
-dPDFSETTINGS=/printer'
if [[ $# == 0 ]]; then
echo "Usage: $0 <article.pdf>"
exit -1
fi
for input_file in $*; do
if [[ $(file ${input_file} | grep PDF) == 1 ]]; then
echo "${input_file} not a PDF, ignoring..."
else
title=$(basename ${input_file} .pdf)
pdfmarks_file=$(tempfile)
output_file_temp=${title}_tmp.pdf
echo "[ /Title (${title}) /DOCINFO pdfmark" > ${pdfmarks_file}
gs ${GS_OPTS} -sOutputFile=${output_file_temp} ${input_file}
${pdfmarks_file}
mv -f ${output_file_temp} ${input_file}
fi
done
Note, I haven't used this for quite some time since switching jobs around a
bit. I don't think ghostscript has changed its parameters much though so
should still work. Still have it in my ~/scripts directory for when needed
:)
Regards,
Joshua Rich
On 15 August 2012 13:05, Scott Ferguson <scott.ferguson.clug at gmail.com>wrote:
> Any suggestions for simple methods to change/create the Title for PDFs?
>
> ImageMagick export allow the creation of a "title" or "caption" for
> images, but doesn't seem to apply them to PDF files created with "convert".
> e.g.:-
> convert: unrecognised option `-title' @
> error/convert.c/ConvertImageCommand/2777.
>
> Instead Title uses the path/file-name of the image file from which the
> PDF was converted e.g. from "strings":-
> /Title (/tmp/scanimage.pdf)
>
> The Title I wish to apply to the PDFs is the same as the PDF file-name
> minus the .pdf extension, `date "+%H%M_%d-%m-%Y"`
>
> Preferred solution would be as close to current process as possible
> (i.e. not require installing mono libraries or calling script wrappers).
>
> scanbuttond (get button push) > scanimage (GRAY 8-bit) > imagemagick
> (convert to jpg) > imagemagick (convert to small pdf)
>
> Version of ImageMagick being used is 6.6.0.4-3
> The PDFs being produced are simple, single page, A4 (image only).
>
> Thanks in anticipation
> --
> linux mailing list
> linux at lists.samba.org
> https://lists.samba.org/mailman/listinfo/linux
>
More information about the linux
mailing list