{"id":216,"date":"2016-09-13T20:51:25","date_gmt":"2016-09-13T20:51:25","guid":{"rendered":"http:\/\/blog.paranoidprofessor.com\/?p=216"},"modified":"2016-09-13T20:51:59","modified_gmt":"2016-09-13T20:51:59","slug":"lp-and-the-automation-of-printing-pdfs","status":"publish","type":"post","link":"https:\/\/blog.paranoidprofessor.com\/index.php\/2016\/09\/13\/lp-and-the-automation-of-printing-pdfs\/","title":{"rendered":"&#8220;lp&#8221; and the automation of printing PDF&#8217;s"},"content":{"rendered":"<p><a href=\"https:\/\/xmlgraphics.apache.org\/fop\/2.0\/\" target=\"_blank\">Apache FOP<\/a> is actually really neat.\u00a0 With a few jar files, an xslt file and a xml file it is possible to create PDF file which can then be viewed or printed on any PC without any loss of formatting.\u00a0 It is so easy to write programs or scripts to create PDF files, so many you might want a more automated method for printing them.<\/p>\n<p>I looked at my PDF viewer to see if it was possible to run it in a batch mode with a few parameters to automate the printing process of the PDF&#8217;s.\u00a0\u00a0\u00a0 I had been hoping a well placed command line argument would do it but I couldn&#8217;t really find anything helpful.<\/p>\n<p>Google was able to find some hints on how I could easily\u00a0 do that on Linux (sorry windows users) without a normal PDF viewer.<\/p>\n<p>The line printer command, lp, is used for the general printing of files.\u00a0 It can also be used to print PDF files as well.\u00a0 Like some Linux commands there are quite a few command line options.<\/p>\n<p><strong>LP &#8211; line printer<br \/>\n<\/strong><\/p>\n<table class=\"w3-table-all\">\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>-d &lt;dest&gt;<\/td>\n<td>The name of the printer to use.<\/td>\n<td>-d &#8220;HP-Color-LaserJet-CM1312-MFP&#8221;<\/td>\n<\/tr>\n<tr>\n<td>-n &lt;copies&gt;<\/td>\n<td>How many copies of document. Three pages in this example.<\/td>\n<td>-n 3<\/td>\n<\/tr>\n<tr>\n<td>-t &lt;job name&gt;<\/td>\n<td>Sets the job name.<\/td>\n<td>-t &#8220;birthday list&#8221;<\/td>\n<\/tr>\n<tr>\n<td>-n &lt;copies&gt;<\/td>\n<td>How many copies of document. Three pages in this example.<\/td>\n<td>-n 3<\/td>\n<\/tr>\n<tr>\n<td>-o &lt;name=value&gt;<\/td>\n<td>Pass common job options to line printer program.<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>-o number-up=&lt;count&gt;<\/td>\n<td>This will print multiple document pages to the printed page.<\/p>\n<p>Two in this case.<\/td>\n<td>-o number-up=2<\/td>\n<\/tr>\n<tr>\n<td>-o &lt;media=size&gt;<\/td>\n<td>This will allow the document to be printed to different sizes of paper. The options are A4, letter and legal.<\/td>\n<td>-o media=A4<\/td>\n<\/tr>\n<tr>\n<td>-o &lt;landscape&gt;<\/td>\n<td>This will rotate the document 90 degrees.<\/td>\n<td>\u00a0-o landscape<\/td>\n<\/tr>\n<tr>\n<td>-o &lt;landscape&gt;<\/td>\n<td>Pass common job options to line printer program.<\/td>\n<td>-o number-up=2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>For a full list of the command line options take a quick look at the man page for lp.<\/p>\n<p>The simplest case is to simply name the printer and the file.<\/p>\n<blockquote><p><strong>lp -d &#8220;HP-Color-LaserJet-CM1312-MFP&#8221; totals.pdf<\/strong><\/p><\/blockquote>\n<p>Printing is usually a very dull command as it normally just works.\u00a0 If for some reason you need to check up on it there are a few ways this can be done.\u00a0 One of the most visible ways to see the printers would be to enter the following URL.<\/p>\n<blockquote><p>http:\/\/localhost:631\/printers<\/p><\/blockquote>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1100\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers.png\" alt=\"list-of-printers\" width=\"1360\" height=\"776\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers.png 1360w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers-300x171.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers-768x438.png 768w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/list-of-printers-1024x584.png 1024w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/a><\/p>\n<p>Note:\u00a0 This assumes that cups is installed.\u00a0 If for some reason cups is not installed just install using apt-get<\/p>\n<pre class=\"tab tcy\">sudo apt-get update &amp;&amp; sudo apt-get install cups cups-client<\/pre>\n<p>This is probably more interesting when the number of printers is greater than one.\u00a0 To see the contents, simply click on the printer to bring up the actual contents of the print queue.<\/p>\n<p><a href=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1101\" src=\"http:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs.png\" alt=\"print-jobs\" width=\"1360\" height=\"864\" srcset=\"https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs.png 1360w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs-300x191.png 300w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs-768x488.png 768w, https:\/\/blog.paranoidprofessor.com\/wp-content\/uploads\/2016\/07\/print-jobs-1024x651.png 1024w\" sizes=\"(max-width: 1360px) 100vw, 1360px\" \/><\/a><\/p>\n<p>The easiest way to remove any jobs from the print queue is from this screen.\u00a0 Press the cancel job button and you will be prompted for the username and password, after which the job is deleted.<\/p>\n<p>Of course, there are command line programs which could be used as well.<\/p>\n<p><strong>LPQ &#8211; line printer queue<\/strong><\/p>\n<p>This command will display a list of all the jobs that are currently waiting to print.<\/p>\n<table class=\"w3-table-all\">\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>-P &lt;dest&gt;<\/td>\n<td>The name of the printer to use.<\/td>\n<td>-P &#8220;HP-Color-LaserJet-CM1312-MFP&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If your printer is the default printer you don&#8217;t need to give name name of the printer to the command.\u00a0 The default print queue will be displayed.<\/p>\n<p><strong>LPRM &#8211; cancel a print job<\/strong><\/p>\n<p>The lprm command will delete an entry from your print queue.<\/p>\n<table class=\"w3-table-all\">\n<tbody>\n<tr>\n<th>Option<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>-P &lt;dest&gt;<\/td>\n<td>The name of the printer to use.<\/td>\n<td>-P &#8220;HP-Color-LaserJet-CM1312-MFP&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Deleting print jobs are easily done from the command line as well.<\/p>\n<div class=\"sbody-code\">\n<pre><code>gast@asus:~$ lpq -P HP-Color-LaserJet-CM1312-MFP\r\nHP-Color-LaserJet-CM1312-MFP is ready\r\nRank Owner Job File(s) Total Size\r\n1st dock 24 YearlyAverageCurrencyExchangeRa 1429504 bytes\r\ngast@asus:~$ \r\ngast@asus:~$ lprm -P \"HP-Color-LaserJet-CM1312-MFP\" 24\r\ngast@asus:~$ \r\ngast@asus:~$ lpq\r\nHP-Color-LaserJet-CM1312-MFP is ready\r\nno entries<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>References<\/h2>\n<p><a href=\"http:\/\/www.tutorialspoint.com\/unix_commands\/lp.htm\">http:\/\/www.tutorialspoint.com\/unix_commands\/lp.htm<\/a><\/p>\n<p><a href=\"http:\/\/www.tutorialspoint.com\/unix_commands\/lpq-cups.htm\">http:\/\/www.tutorialspoint.com\/unix_commands\/lpq-cups.htm<\/a><\/p>\n<p><a href=\"http:\/\/www.tutorialspoint.com\/unix_commands\/lprm.htm\">http:\/\/www.tutorialspoint.com\/unix_commands\/lprm.htm<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache FOP is actually really neat.\u00a0 With a few jar files, an xslt file and a xml file it is possible to create PDF file which can then be viewed or printed on any PC without any loss of formatting.\u00a0 &hellip; <a href=\"https:\/\/blog.paranoidprofessor.com\/index.php\/2016\/09\/13\/lp-and-the-automation-of-printing-pdfs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[17],"_links":{"self":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/216"}],"collection":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":13,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":1254,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions\/1254"}],"wp:attachment":[{"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.paranoidprofessor.com\/index.php\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}