I had a bunch of music lyrics that I wanted to print and I didn't want to manually drive gedit. I did, however, want to retain the document formatting. I found a hint in Re^2: using Brother QL-570 printer with Perl and also found sample commands in an Ubuntu Community Documentation post for using the Open Office command line interface for batch printing or viewing. The are also posts out there for doing a similar thing with MS-Word.

The following is what I threw together. It does the job for me, YMMV. I needed to print UTF-8 text files, but Open Office will try to print whatever file you give it using the file extension as a guide to the file format. I have also printed .odt files.

#! /home/xxxx/CitrusPerl/perl/bin/perl # BatchFilePrinter.pl # Batch print text files under linux # Prints ALL of the files in the specified directory # Uses the Open Office Command Line interface # Pass a directory path as a command line argument(@ARGV) or # hard code a default directory path. # Print to a local(default(-p filename) or named(-pt printername filen +ame)) printer # soffice -nologo -p file.txt # Print to default prin +ter # soffice -nologo -pt namedprinter file.txt # Print to named +printer # soffice -nologo -view file.txt # View a read-only v +ersion of the file # Note: The file extension clues Open Office as to the file format(I k +now duh!). # If no extension is present or if the file format doesn't match + the "usual" # usage/definition of said extension, Open Office will pop up an # "ASCII Filter Options" dialog box to ask for the file type inf +ormation. # This messes with unattended printing. So, make sure the extens +ions match # the document types. The print files queue faster than my Deskj +et can print. # Hint and example commands from a post by Jorge Castro on Ubuntu Comm +unity Documentation. # Last Modified: May 15, 2013 by James M. Lynes, Jr. use strict; use warnings; use File::Find; use Data::Dumper; my $directory = shift @ARGV || "/home/xxxx/Guitar-Music/"; my @files; find({ wanted => \&wanted, no_chdir => 1 }, $directory); @files = sort @files; print "\n\n"; foreach my $file(@files) { print "Printing file: $file\n"; `soffice -nologo -pt Deskjet-3900-2 $directory . $file`; } sub wanted { if($_ eq '.') {return}; if($_ eq '..') {return}; push (@files, $File::Find::name); }

James

There's never enough time to do it right, but always enough time to do it over...


In reply to Batch Printing in Linux by jmlynesjr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.