-2

I need to print many documents and I don't want to go to each selecting it and printing all. These documents have revisions and are all in the same folder. I want to print the latest revision for these documents. The format for these documents is

630-0-110
9A-0-9 
44-0-190
44-0-191

Of these four pdf files, 44-0-191 is a later revision than 44-0-190 so I would like to print 630-0-110, 9A-0-9, 44-0-191

I need to print numbers starting with 6-0-(revision no.) up to 699A-0-(revision no.) and some of them have A,B,C in the beginning as well.

Is there a way to create a shell to print these automatically? Or do I have to manually ctrl+click all of them to print them?

If I can create a shell how do I Do it?

  • 2
    bash, cmd and powershell are 3 different things. I would say, if you are on Windows, bash is sort of out of the question. – Jason Jul 09 '18 at 13:15
  • 2
    Please review https://stackoverflow.com/help/how-to-ask. Please paste the code you are trying to make work into the question. If you do not have any code and need to hire a programmer, you might try https://www.stackoverflowbusiness.com/talent. – lit Jul 09 '18 at 13:20
  • I'm on windows. What's best to use – Danny Janani Jul 09 '18 at 13:21
  • 2
    A search machine. Or you hire a programmer. StackOverflow is not a free code/script writing service, neither does it take over your research. So you have to try to implement your task on your own, and when stuck, come back here, providing a [mcve]! Read also the [tour]! – aschipfl Jul 09 '18 at 14:26
  • I'm not asking for code. I am asking if this can be done and if so what do I need to do? – Danny Janani Jul 09 '18 at 14:39
  • 1
    Yes, it can be done. I would use powershell, but a more recent version than 2.0. Get 5.1 from Microsoft or 6 from https://github.com/PowerShell/PowerShell. – lit Jul 09 '18 at 14:57

1 Answers1

1

Your task requires several steps

  • List documents, use a RegEx to split name from revision,
  • group the documents by name,
  • per group sort by revision numerically,
  • get only the highest rev. (last one)

  • select a printer / or use a defined one / default standard printer

Since your revision numbers have a diverging count of places you need to sort numerical, this is realized with $ToNatural

To test the sorting I used an extended sample (revisions to print are marked **)

44-0-19.pdf      
44-0-190.pdf
44-0-191.pdf    **
44-0-2.pdf
630-0-110.pdf   **
630-0-90.pdf
9A-0-10.pdf     **
9A-0-9.pdf

## Q:\Test\2018\07\09\SO_51246286.ps1
#Requires -Version 3

## To sort numbers with a different places count use:
## $ToNatural from Roman Kuzmin source https://stackoverflow.com/a/5429048/6811411
$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20,"0") }) }

Push-Location "X:\start\folder"

$PDFsToPrint = (Get-ChildItem *.pdf -File |
  Where-Object BaseName -match '^([0-9]+[A-C]?-\d+)-(\d+)$'|
    Group-Object {$Matches[1]} |
      Foreach-Object {
        $_.Group | Sort-Object $ToNatural | Select-Object -Last 1
      } ).FullName
# $PDFsToPrint

Pop-Location

$Printer = Get-Printer | Select-Object Name,Drivername,PortName |
   Out-GridView -Title "Select the printer for output" -OutputMode Single

#Adobe SDK: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf
$Acrobat = 'C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe'

ForEach($Pdf in $PDFsToPrint) {
    $ArgList=' /S /T "{0}" "{1}" "{2}" {3}' -f `
        $Pdf,
        $Printer.Name,
        $Printer.DriverName,
        $Printer.PortName

    Start-Process $Acrobat -ArgumentList $ArgList
    #Start-Sleep -Seconds 60  #optional delay    
}