http://www.perlmonks.org?node_id=1033731

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...