#! perl # Store help text in variable $syntax = "\nPrintPDF.pl, Version 1.00 for Windows\n"; $syntax = $syntax."Print the specified PDF files\n\n"; $syntax = $syntax."Usage: PRINTPDF.PL pdf_files\n\n"; $syntax = $syntax."Where: \"pdf_files\" is the (list of) PDF file(s) to be printed\n"; $syntax = $syntax." (separated by spaces, no wildcards allowed)\n\n"; $syntax = $syntax."Note: This script will only work if Acrobat Reader is the default\n"; $syntax = $syntax." association for PDF files.\n"; $syntax = $syntax." It usually fails on PCs with other Adobe software installed.\n\n"; $syntax = $syntax."Written by Rob van der Woude\n"; $syntax = $syntax."http://www.robvanderwoude.com\n"; # Check number of command line arguments (at least 1 required) if ( !@ARGV[0] ) { die $syntax; } # Check if arguments are valid files and build file list $pdflist = ""; foreach ( @ARGV ) { die "\nFile not found: $_\n$syntax" unless -e $_; die "\nInvalid filespec: $_\n$syntax" unless -f $_; die "\nInvalid file type: $_\n$syntax" if -d $_ or -x $_ or -T $_; $pdflist = "$pdflist \"$_\""; } # Initialize the required module use Win32API::Registry 0.21 qw( :ALL ); # Read the print command from the registry $key = ".pdf"; RegOpenKeyEx( HKEY_CLASSES_ROOT, $key, 0, KEY_READ, $handle ) || die "Cannot open HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; RegQueryValueEx( $handle, "", [], $type, $filetype, [] ) || die "Cannot read HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; RegCloseKey( $handle ) || die "Cannot close HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; $key = "$filetype\\shell\\print\\command"; RegOpenKeyEx( HKEY_CLASSES_ROOT, $key, 0, KEY_READ, $handle ) || die "Cannot open HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; RegQueryValueEx( $handle, "", [], $type, $printcmd, [] ) || die "Cannot read HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; RegCloseKey( $handle ) || die "Cannot close HKEY_CLASSES_ROOT\\$key: ".regLastError()."\n"; # Quit if Acrobat Reader is not the default association for PDF files $other = "\nThis script only works when Acrobat Reader is the default association\nfor PDF files.\n"; $other = $other."On this PC that doesn't seem to be the case, maybe because other\nAdobe software is installed as well."; die $other if index( $printcmd, "{" ); # Display a message telling the user to manually close Acrobat Reader print "\nWaiting for you to close the Acrobat Reader window manually after it has sent\nall files to the printer...\n"; # Execute the print command for all files from the list $printcmd =~ s/"%1"/$pdflist/; `$printcmd`;