<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slackwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Allend</id>
	<title>SlackWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.slackwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Allend"/>
	<link rel="alternate" type="text/html" href="https://www.slackwiki.com/Special:Contributions/Allend"/>
	<updated>2026-04-08T02:52:36Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://www.slackwiki.com/index.php?title=PDF_Printing&amp;diff=833</id>
		<title>PDF Printing</title>
		<link rel="alternate" type="text/html" href="https://www.slackwiki.com/index.php?title=PDF_Printing&amp;diff=833"/>
		<updated>2013-03-15T16:23:37Z</updated>

		<summary type="html">&lt;p&gt;Allend: /* PDF Printing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tips]]&lt;br /&gt;
== PDF Printing ==&lt;br /&gt;
&lt;br /&gt;
While many applications offer exporting output to portable document format (PDF) files, many others do not.&lt;br /&gt;
It is easy to add a virtual PDF printer to CUPS by installing the cups-pdf package that is available at http://www.slackbuilds.org&lt;br /&gt;
&lt;br /&gt;
This works well for single documents, but if you print multiple documents that are parsed as having the same name then the older documents will be overwritten.&lt;br /&gt;
A solution to this is to run a script that watches for the creation of the PDF document in the spool directory (/var/spool/cups-pdf/&amp;lt;username&amp;gt; by default) and then moves the document to another directory (USERS_DIR). The script below (watch_for_spooled_pdf.sh kept in /home/xx/pdf_printing) also prepends a date and time string to keep the document names unique.&lt;br /&gt;
A user xx should start this script as a background process i.e. /home/xx/pdf_printing/watch_for_spooled_pdf.sh &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Script to watch for creation of .pdf files by CUPS-PDF in spool directory&lt;br /&gt;
#  and move to users directory prepending the creation date and time.&lt;br /&gt;
#&lt;br /&gt;
# This script uses the -m option to inotifywait and should never exit.&lt;br /&gt;
&lt;br /&gt;
SPOOL_DIR=/var/spool/cups-pdf/xx/&lt;br /&gt;
USERS_DIR=/home/xx/Desktop/PDF_Files/&lt;br /&gt;
&lt;br /&gt;
inotifywait  -mq --timefmt '%Y%m%d %H%M%S' --format '%T %f' \&lt;br /&gt;
  -e close_write $SPOOL_DIR \&lt;br /&gt;
  | while read date time file; do&lt;br /&gt;
      mv $SPOOL_DIR${file} $USERS_DIR${date}${time}_${file}&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What if printed PDF documents should be combined into one large PDF document?&lt;br /&gt;
A user could move the files to be combined to a new subdirectory and then run the script (combine.sh) shown below.&lt;br /&gt;
This script creates a single PDF document with bookmark entries to each of the individual documents using the facilities in the pdfpages and hyperref packages of LaTeX. The page order is in the order of creation date and time.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
# Script to combine .pdf files into a single bookmarked .pdf file&lt;br /&gt;
# Intended to be run from within a directory containing files to be concatenated.&lt;br /&gt;
# The directory name is accepted as a parameter&lt;br /&gt;
&lt;br /&gt;
# If the directory name has been passed, then make it the working directory.&lt;br /&gt;
if [[ $1 ]]; then cd $1; fi&lt;br /&gt;
&lt;br /&gt;
# Filename for the .tex file that will be processed using pdflatex&lt;br /&gt;
OUTFILE=$PWD/out2.tex&lt;br /&gt;
# Starting values for bookmark creation&lt;br /&gt;
BKMK_TEXT=Contents&lt;br /&gt;
BKMK_ANCHOR=Beginning&lt;br /&gt;
BKMK_LEVEL=0&lt;br /&gt;
# Variable containing ASCII code for centre dot character&lt;br /&gt;
CENTREDOT=$(echo -e &amp;quot;\xB7&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Function to sanitise filenames by:&lt;br /&gt;
#  Changing space characters to underscore characters&lt;br /&gt;
#  and changing all but last period characters to centre dot (0xB7)&lt;br /&gt;
#  Necessary for \includepdf to parse filenames correctly&lt;br /&gt;
sanitise_filenames () {&lt;br /&gt;
for FILENAME in *.[Pp][Dd][Ff] ; do&lt;br /&gt;
  PREFIX=${FILENAME%.*}&lt;br /&gt;
  SUFFIX=${FILENAME##*.}&lt;br /&gt;
  NEWPREFIX=${PREFIX// /_}&lt;br /&gt;
  NEWPREFIX=${NEWPREFIX//./$CENTREDOT}&lt;br /&gt;
  if [ &amp;quot;$PREFIX&amp;quot; != &amp;quot;$NEWPREFIX&amp;quot; ]; then&lt;br /&gt;
    mv &amp;quot;$FILENAME&amp;quot; &amp;quot;$NEWPREFIX.$SUFFIX&amp;quot;&lt;br /&gt;
  fi&lt;br /&gt;
done&lt;br /&gt;
return&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Function to create a bookmark entry&lt;br /&gt;
do_bookmark_entry () {&lt;br /&gt;
  BKMK_TEXT=${FILENAME%.*}&lt;br /&gt;
  BKMK_TEXT=${BKMK_TEXT:15}&lt;br /&gt;
  #  NB. Need to substitute 'space' for 'underscore' to be valid bookmark text.&lt;br /&gt;
  BKMK_TEXT=${BKMK_TEXT//_/ }&lt;br /&gt;
  # Create a unique anchor point based on date and time prepended to filename&lt;br /&gt;
  BKMK_ANCHOR=${FILENAME:0:14}&lt;br /&gt;
  echo &amp;quot;\pdfbookmark[&amp;quot;$BKMK_LEVEL&amp;quot;]{&amp;quot;$BKMK_TEXT&amp;quot;}{&amp;quot;$BKMK_ANCHOR&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
return&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
# Function to add all pdf files in current directory to the output file&lt;br /&gt;
add_pdf_files () {&lt;br /&gt;
for FILENAME in *.[Pp][Dd][Ff] ; do&lt;br /&gt;
  do_bookmark_entry&lt;br /&gt;
  echo &amp;quot;\includepdf[pages=-,fitpaper]{&amp;quot;$PWD&amp;quot;/&amp;quot;$FILENAME&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
done&lt;br /&gt;
return&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\documentclass{article}&amp;quot; &amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\usepackage{pdfpages}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\usepackage[bookmarks,bookmarksopen,bookmarksopenlevel=1,pdfpagelayout={SinglePage},pdfview={Fit}]{hyperref}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\begin{document}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\pdfbookmark[&amp;quot;$BKMK_LEVEL&amp;quot;]{&amp;quot;$BKMK_TEXT&amp;quot;}{&amp;quot;$BKMK_ANCHOR&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
sanitise_filenames&lt;br /&gt;
(( BKMK_LEVEL++ ))&lt;br /&gt;
for FNAME in * ; do&lt;br /&gt;
  if [ -d $FNAME ]; then&lt;br /&gt;
    FILENAME=$FNAME&lt;br /&gt;
    do_bookmark_entry&lt;br /&gt;
    cd $FNAME&lt;br /&gt;
    (( BKMK_LEVEL++ ))&lt;br /&gt;
    sanitise_filenames&lt;br /&gt;
    add_pdf_files&lt;br /&gt;
    (( BKMK_LEVEL-- ))&lt;br /&gt;
    cd ..&lt;br /&gt;
  elif [ -f $FNAME ] &amp;amp;&amp;amp; [[ ${FNAME##*.} == [Pp][Dd][Ff] ]] ; then&lt;br /&gt;
    FILENAME=$FNAME&lt;br /&gt;
    do_bookmark_entry&lt;br /&gt;
    echo &amp;quot;\includepdf[pages=-,fitpaper]{&amp;quot;$PWD&amp;quot;/&amp;quot;$FILENAME&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
  fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\end{document}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
# Now process the .tex file&lt;br /&gt;
# Do a second run so that bookmark entries are resolved&lt;br /&gt;
pdflatex $OUTFILE; pdflatex $OUTFILE&lt;br /&gt;
wait&lt;br /&gt;
&lt;br /&gt;
# Rename the created .pdf file&lt;br /&gt;
mv ${OUTFILE%.*}.pdf $(date +%Y%m%d%H%M%S)_All.pdf&lt;br /&gt;
&lt;br /&gt;
# Cleanup files left by pdflatex processing&lt;br /&gt;
rm ${OUTFILE%.*}*&lt;br /&gt;
&lt;br /&gt;
# Cleanup trigger file if this script has been started from watch_for_combine_start.sh script&lt;br /&gt;
if [ -f combine.start ]; then rm combine.start; fi&lt;br /&gt;
&lt;br /&gt;
# Remove this script&lt;br /&gt;
rm $0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a convenience, the user could also have a second background process running the script (watch_for_combine_start.sh) shown below. This script watches for the creation of a 'trigger' file (combine.start) in the directory tree and then executes the 'combine.sh' script shown above. This is useful in a network environment, so that a Windows user manipulating the files via a Samba share can create the combined PDF file without having to log in to the Slackware Linux server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Script to watch for creation of a trigger file in a directory tree.&lt;br /&gt;
#  This event causes another script to be copied into the tree subdirectory and run.&lt;br /&gt;
#  The tree subdirectory name is passed as a parameter.&lt;br /&gt;
#&lt;br /&gt;
# This script should never exit&lt;br /&gt;
&lt;br /&gt;
WATCH_DIR=/home/xx/Desktop/PDF_Files&lt;br /&gt;
TRIGGER_FILE=combine.start&lt;br /&gt;
SCRIPT_FILE=/home/xx/pdf_printing/combine.sh&lt;br /&gt;
&lt;br /&gt;
inotifywait  -mqr --timefmt '%Y%m%d %H%M%S' --format '%T %w %f' \&lt;br /&gt;
  -e close_write $WATCH_DIR \&lt;br /&gt;
  | while read date time path file; do&lt;br /&gt;
      if [ ${file} == $TRIGGER_FILE ]; then&lt;br /&gt;
        cp $SCRIPT_FILE ${path}&lt;br /&gt;
        sh ${path}/$(basename $SCRIPT_FILE) ${path} &amp;gt; /dev/null &amp;amp;&lt;br /&gt;
      fi&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Allend</name></author>
	</entry>
	<entry>
		<id>https://www.slackwiki.com/index.php?title=PDF_Printing&amp;diff=296</id>
		<title>PDF Printing</title>
		<link rel="alternate" type="text/html" href="https://www.slackwiki.com/index.php?title=PDF_Printing&amp;diff=296"/>
		<updated>2010-02-17T16:14:59Z</updated>

		<summary type="html">&lt;p&gt;Allend: Created page with 'Category:Tips == PDF Printing ==  While many applications offer exporting output to portable document format (PDF) files, many others do not. It is easy to add a virtual PDF ...'&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Tips]]&lt;br /&gt;
== PDF Printing ==&lt;br /&gt;
&lt;br /&gt;
While many applications offer exporting output to portable document format (PDF) files, many others do not.&lt;br /&gt;
It is easy to add a virtual PDF printer to CUPS by installing the cups-pdf package that is available at http://www.slackbuilds.org&lt;br /&gt;
&lt;br /&gt;
This works well for single documents, but if you print multiple documents that are parsed as having the same name then the older documents will be overwritten.&lt;br /&gt;
A solution to this is to run a script that watches for the creation of the PDF document in the spool directory (/var/spool/cups-pdf/&amp;lt;username&amp;gt; by default) and then moves the document to another directory (USERS_DIR). The script below (watch_for_spooled_pdf.sh kept in /home/xx/pdf_printing) also prepends a date and time string to keep the document names unique.&lt;br /&gt;
A user xx should start this script as a background process i.e. /home/xx/pdf_printing/watch_for_spooled_pdf.sh &amp;amp;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Script to watch for creation of .pdf files by CUPS-PDF in spool directory&lt;br /&gt;
#  and move to users directory prepending the creation date and time.&lt;br /&gt;
#&lt;br /&gt;
# This script uses the -m option to inotifywait and should never exit.&lt;br /&gt;
&lt;br /&gt;
SPOOL_DIR=/var/spool/cups-pdf/xx/&lt;br /&gt;
USERS_DIR=/home/xx/Desktop/PDF_Files/&lt;br /&gt;
&lt;br /&gt;
inotifywait  -mq --timefmt '%Y%m%d %H%M%S' --format '%T %f' \&lt;br /&gt;
  -e close_write $SPOOL_DIR \&lt;br /&gt;
  | while read date time file; do&lt;br /&gt;
      mv $SPOOL_DIR${file} $USERS_DIR${date}${time}_${file}&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What if printed PDF documents should be combined into one large PDF document?&lt;br /&gt;
A user could move the files to be combined to a new subdirectory and then run the script (combine.sh) shown below.&lt;br /&gt;
This script creates a single PDF document with bookmark entries to each of the individual documents using the facilities in the pdfpages and hyperref packages of LaTeX. The page order is in the order of creation date and time.&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Script to combine .pdf files&lt;br /&gt;
# Intended to be run from within a directory containing files to be concatenated.&lt;br /&gt;
# The directory name is accepted as a parameter&lt;br /&gt;
&lt;br /&gt;
# First create a .tex file  for processing using pdflatex&lt;br /&gt;
OUTFILE=out2.tex&lt;br /&gt;
BKMK_TEXT=Contents&lt;br /&gt;
BKMK_ANCHOR=Beginning&lt;br /&gt;
BKMK_LEVEL=0&lt;br /&gt;
&lt;br /&gt;
# If the directory name has been passed, then make it the working directory.&lt;br /&gt;
if [[ $1 ]]; then cd $1; fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\documentclass{article}&amp;quot; &amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\usepackage{pdfpages}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\usepackage[bookmarksopen]{hyperref}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\begin{document}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
echo &amp;quot;\pdfbookmark[&amp;quot;$BKMK_LEVEL&amp;quot;]{&amp;quot;$BKMK_TEXT&amp;quot;}{&amp;quot;$BKMK_ANCHOR&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
BKMK_LEVEL=1&lt;br /&gt;
for FILENAME in $( ls ./*.pdf ); do&lt;br /&gt;
# Create the text to be used in the bookmark entry.&lt;br /&gt;
#  NB. Need to substitute 'space' for 'underscore' to be valid bookmark text.&lt;br /&gt;
  BKMK_TEXT=$(echo $FILENAME | cut -b1-17 --complement | sed s/_/\ /g | sed s/\.pdf$//g)&lt;br /&gt;
# Create a unique anchor point based on date and time prepended to filename&lt;br /&gt;
  BKMK_ANCHOR=$(echo $FILENAME | cut -b3-16)&lt;br /&gt;
  echo &amp;quot;\pdfbookmark[&amp;quot;$BKMK_LEVEL&amp;quot;]{&amp;quot;$BKMK_TEXT&amp;quot;}{&amp;quot;$BKMK_ANCHOR&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
  echo &amp;quot;\includepdf[pages=-,fitpaper]{&amp;quot;$FILENAME&amp;quot;}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;\end{document}&amp;quot; &amp;gt;&amp;gt; $OUTFILE&lt;br /&gt;
&lt;br /&gt;
# Now process the .tex file&lt;br /&gt;
# Do a second run so that bookmark entries are resolved&lt;br /&gt;
pdflatex $OUTFILE; pdflatex $OUTFILE&lt;br /&gt;
wait&lt;br /&gt;
&lt;br /&gt;
# Rename the created .pdf file&lt;br /&gt;
mv $(basename $OUTFILE .tex).pdf $(date +%Y%m%d%H%M%S)_All.pdf&lt;br /&gt;
&lt;br /&gt;
# Cleanup files left by pdflatex processing&lt;br /&gt;
rm $(basename $OUTFILE .tex)*&lt;br /&gt;
&lt;br /&gt;
# Cleanup trigger file if this script has been started from watch_for_combine_start.sh script&lt;br /&gt;
if [ -f combine.start ]; then rm combine.start; fi&lt;br /&gt;
&lt;br /&gt;
# Remove this script&lt;br /&gt;
rm $0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a convenience, the user could also have a second background process running the script (watch_for_combine_start.sh) shown below. This script watches for the creation of a 'trigger' file (combine.start) in the directory tree and then executes the 'combine.sh' script shown above. This is useful in a network environment, so that a Windows user manipulating the files via a Samba share can create the combined PDF file without having to log in to the Slackware Linux server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
# Script to watch for creation of a trigger file in a directory tree.&lt;br /&gt;
#  This event causes another script to be copied into the tree subdirectory and run.&lt;br /&gt;
#  The tree subdirectory name is passed as a parameter.&lt;br /&gt;
#&lt;br /&gt;
# This script should never exit&lt;br /&gt;
&lt;br /&gt;
WATCH_DIR=/home/xx/Desktop/PDF_Files&lt;br /&gt;
TRIGGER_FILE=combine.start&lt;br /&gt;
SCRIPT_FILE=/home/xx/pdf_printing/combine.sh&lt;br /&gt;
&lt;br /&gt;
inotifywait  -mqr --timefmt '%Y%m%d %H%M%S' --format '%T %w %f' \&lt;br /&gt;
  -e close_write $WATCH_DIR \&lt;br /&gt;
  | while read date time path file; do&lt;br /&gt;
      if [ ${file} == $TRIGGER_FILE ]; then&lt;br /&gt;
        cp $SCRIPT_FILE ${path}&lt;br /&gt;
        sh ${path}/$(basename $SCRIPT_FILE) ${path} &amp;gt; /dev/null &amp;amp;&lt;br /&gt;
      fi&lt;br /&gt;
    done&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Allend</name></author>
	</entry>
</feed>