locked
Powershell with A-pdf RRS feed

  • Question

  • I am using A-pdf to split lots of pdf. All pdf files are in one folder, I am able to call pcscmd.exe from powershell but it expect parameter for filename and rulfile and output path. so one at a time is fine. Can powershell call all the files in the folders and pass it to this program with appropriate parameters ?

    Thank you,

    Kashyap

    Friday, June 2, 2017 8:01 PM

Answers

  • 1st - PLEASE format your code as code!
    2nd - that's not the code I posted. If you change the logic you should be able to debug it by yourself. Take a closer look to my example and compare it to yours.
    3rd - you really really should start to learn the basics of Powershell. Then you would understand the code and could debug it and could avoid a lot of frustration and safe a lot of wasted time

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by gurudevam Wednesday, July 5, 2017 11:48 PM
    Tuesday, June 20, 2017 11:21 PM

All replies

  • … Can powershell call all the files in the folders and pass it to this program with appropriate parameters ?

    Of course. That's a very easy task for Powershell.  ;-)

    Good luck and have a lot of fun!


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Friday, June 2, 2017 9:20 PM
  • How ?
    Monday, June 5, 2017 4:43 PM
  • We don't write scripts on request and we cannot teach you how to use Powershell.  

    If you have a specific question to a particular script you wrote or error you get you should post this script and/or this error here and we can probably help you.

    Here you can find a collection of great starting points Beginner Sites and Tutorials.

    Good luck and have a lot of fun!


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by Hello_2018 Tuesday, June 6, 2017 10:12 AM
    Monday, June 5, 2017 11:51 PM
  • Hi,

    >>Can powershell call all the files in the folders and pass it to this program with appropriate parameters ?

    Try this:

    $pdfs= Get-ChildItem -Path ".\pdfs" -Recurse
    
    foreach($pdf in $pdfs)
    {
        pcscmd.exe $pdf 
        #outfile you could use the defalut directory
        #rulefile can be defined by A-PDF content Splitters GUI
    }

    For how to use this command, i suppose you should ask on A-PDF:

    http://www.a-pdf.com/content-splitter/

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, June 6, 2017 5:54 AM
  • Thank you very much indeed.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Tuesday, June 6, 2017 9:36 AM
  • I tried and still getting an error "The term pcscmd.exe is not recognized as the name of cmdlet" also, i tried like this and it doesn't read files as well ".\pcscmd.exe $filepath$filexetention $rulefile -o$outpath. " this error out as $filepath$filextention is illegal file format !

    Wednesday, June 7, 2017 3:22 PM
  • You should start to learn the basics of Powershell. Then you're able to debug your script by yourself. Here is not the place to get teached.

    Here you can find some reasonable starting points: Beginner Sites and Tutorials


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Wednesday, June 7, 2017 7:23 PM
  • (mm) - i tried quiet a few things even thought i m using powershell 1st time, trying to help some one since i am a BI person obv i m not strong in PS. Anyway, i am just assuming that a-pdf's command line method - the pcscmd.exe doesn't recognize variable at all. If anyone can suggest, i would really appreciate it.

    Thank you,

    KaPi

    Wednesday, June 7, 2017 9:15 PM
  • (mm) - i tried quiet a few things even thought i m using powershell 1st time, trying to help some one since i am a BI person obv i m not strong in PS.

    That's obvious and logic. If you don't have a natural god given talent to understand computer programming languages without the need to learn them first. But would you expect to be able to drive a truck through a big city right away when you take a seat in it for the first time in your life?

    Anyway, i am just assuming

    That's the problem - assuming is not a proper method to get something done.

    If anyone can suggest, i would really appreciate it.

    But in the end IMHO it will not really help you when you don't understand it. You don't even deliver enough information to help you. What's the path you want start with, what's the path to you pscmd.exe, what's the options you want to use, what's the output format you want to use .....

    Try the following

    $StartDirectory = 'Path to your source files'           ## fill in the path between the quotes
    $PSCMDPath = 'Complete Path to your PSCMD executable'   ## fill in the path between the quotes
    $OutputPath = 'Output Path'                             ## fill in the path between the quotes
    $SplitMethod = '-P1'                                    ## adapt this to your needs
    $OutputFilePattern = '{basename}.{part:0000}'           ## adapt this to your needs
    
    Get-ChildItem -Path $StartDirectory -Filter '*.pdf' -recurse |
        Foreach-Object { Start-Process -FilePath $PSCMDPath -ArgumentList $_.FullName,  $SplitMethod , $OutputPath, $OutputFilePattern}
    If that does not work you should post the error messages here. And PLEASE use the code formatting option in the edit bar here in the forum.


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Wednesday, June 7, 2017 11:14 PM
    Wednesday, June 7, 2017 10:48 PM
  • Hi KaPi,

    i suppose you use psccmd.exe is enough for this requests:

    Detailed usage please see here:

    http://www.a-pdf.com/content-splitter/

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Hello_2018 Tuesday, June 13, 2017 4:31 AM
    Thursday, June 8, 2017 4:08 AM
  • @BOfH - no one knows everything since God is way above our imagination. The one who claims to know all,  indeed in PreK. Also, my assumption is on A-pdf which is for pcscmd.exe, which doesn't read the variables, it reads only hard coded values that means, what you are suggesting i tried already and it didn't work ! it just flash the pcscmd.exe on command line and that's it - no error as well, but doesn't do splitting of files based on rule files i created. Seems like limitation on executing pcscmd.

    @Andy - I checked the entire site, the QnA section as well. My goal is - i have lots of pdfs, so i can create rule file for each pdf, but right now i am testing with 2 pdfs and 2 rule files tried looping, and so far it hasn't work. The batch processing with hot directory doesn't match with my requirements because it accept only 1 rule for all files in hot directory.

    Thank you both for support -

    KaPi

    Thursday, June 8, 2017 2:49 PM
  • Also, my assumption is on A-pdf which is for pcscmd.exe, which doesn't read the variables ..... 

    It doesn't have to read the variables. Powershell does it ... and pass it to the executable.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, June 8, 2017 7:23 PM
  • @BOfH - no one knows everything since God is way above our imagination. The one who claims to know all,  indeed in PreK. Also, my assumption is on A-pdf which is for pcscmd.exe, which doesn't read the variables, it reads only hard coded values that means, what you are suggesting i tried already and it didn't work ! it just flash the pcscmd.exe on command line and that's it - no error as well, but doesn't do splitting of files based on rule files i created. Seems like limitation on executing pcscmd.

    @Andy - I checked the entire site, the QnA section as well. My goal is - i have lots of pdfs, so i can create rule file for each pdf, but right now i am testing with 2 pdfs and 2 rule files tried looping, and so far it hasn't work. The batch processing with hot directory doesn't match with my requirements because it accept only 1 rule for all files in hot directory.

    Thank you both for support -

    KaPi

    Ok, if these script above not working, i suppose the last way might be refer to the PS gallery pre-written script:

    https://gallery.technet.microsoft.com/site/search?query=split%20pdf&f%5B0%5D.Value=split%20pdf&f%5B0%5D.Type=SearchText&ac=4

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, June 9, 2017 2:37 AM
  • This is funny - i had been trying too hard with powershell, but i got the answer from command line. The way it worked is

    for %i in (mypath\*.pdf) do (for %j in (rulepath\*.rul) do pcscmd.exe %i %j) 

    this command did the job, split all pdfs which has the rule set up from pdfcs GUI.

    Still wondering, why it does not work with powershell ?

    Thank you,

    KaPi

    • Marked as answer by gurudevam Wednesday, June 14, 2017 9:14 PM
    • Unmarked as answer by gurudevam Tuesday, June 20, 2017 7:29 PM
    Wednesday, June 14, 2017 7:06 PM
  • It's quite hard to believe that a simple cammand line should not work in Powershell
    $PDFPath = 'Path to your source files'                  ## fill in the path between the quotes
    $RulePath = 'Path to your rule files'                   ## fill in the path between the quotes
    $PSCMDPath = 'Complete Path to your PSCMD executable'   ## fill in the path between the quotes
    
    $PDFS = Get-ChildItem -Path $PDFPath -Filter *.pdf | Select-Object -ExpandProperty FullName
    $Rules = Get-ChildItem -Path $RulePath -Filter *.rul | Select-Object -ExpandProperty FullName
    
    Foreach($File in $PDFS){
        Foreach($Rule in $Rules){
            Start-Process -FilePath $PSCMDPath -ArgumentList "$File $Rule"
        }
    }


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by gurudevam Tuesday, June 20, 2017 8:10 PM
    • Unmarked as answer by gurudevam Tuesday, June 20, 2017 8:37 PM
    Wednesday, June 14, 2017 9:00 PM
  • @BOf_H_666 - finally it works with powershell as well....really appreciate that you didn't give up as well. Well ! i can take out batch file process from block. another wow is - on command line it's one line of code that does the job.
    Wednesday, June 14, 2017 9:19 PM
  • If you really wanted you could put it with Powershell on one line either but it would be quite unreadable and hard to understand.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Wednesday, June 14, 2017 10:00 PM
  • Hi - One more issue - I have created about 50 rule files for 50 pdfs. In above answer using ps -

    $PDFPath = 'Path to your source files'                  ## fill in the path between the quotes
    $RulePath = 'Path to your rule files'                   ## fill in the path between the quotes
    $PSCMDPath = 'Complete Path to your PSCMD executable'   ## fill in the path between the quotes

    $PDFS = Get-ChildItem -Path $PDFPath -Filter *.pdf | Select-Object -ExpandProperty FullName
    $Rules = Get-ChildItem -Path $RulePath -Filter *.rul | Select-Object -ExpandProperty FullName

    Foreach($File in $PDFS){
        Foreach($Rule in $Rules){
            Start-Process -FilePath $PSCMDPath -ArgumentList "$File $Rule"
        }
    }

    - How can i tell powershell to use particular rul for particular pdf ? like if pdf name is abc.pdf than i have created abc.rul file, so when i run the above block of code, it should pick one file and one rule, instead of looking into all rul file.

    Tuesday, June 20, 2017 8:45 PM
  • You can simply check inside of the inner loop if the basename of the rule file matches the basename of the pdf file and run the command line only if they match.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Tuesday, June 20, 2017 8:57 PM
    Tuesday, June 20, 2017 8:56 PM
  • @BOfH_666 - u mean Foreach($Rule in $Rules){  - at this line ? so foreach($rule in foreach($file) ) - am i going correct ?

    Tuesday, June 20, 2017 9:06 PM
  • Hmmmm ... actually not ...  ;-)

    BTW: If you post code here in the forum you should format is as code please.

    $PDFPath = 'Path to your source files'                  ## fill in the path between the quotes
    $RulePath = 'Path to your rule files'                   ## fill in the path between the quotes
    $PSCMDPath = 'Complete Path to your PSCMD executable'   ## fill in the path between the quotes
    
    $PDFS = Get-ChildItem -Path $PDFPath -Filter *.pdf 
    $Rules = Get-ChildItem -Path $RulePath -Filter *.rul 
    
    Foreach($File in $PDFS){
        Foreach($Rule in $Rules){
            If($($File.BaseName) -eq $($Rule.BaseName)){Start-Process -FilePath $PSCMDPath -ArgumentList "$($File.FullName) $($Rule.FullName)"}
        }
    }

    ... AND ... I consider it as quite unfair to unmark my reply as answer because you changed the requirement of the script!  ;-)


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Tuesday, June 20, 2017 9:23 PM
    Tuesday, June 20, 2017 9:20 PM
  • it is not giving any error but it is showing me the syntex of pcscmd.exe. Also, when i run this block, it pops up lots of command prompt windows (over 100) !

    Tuesday, June 20, 2017 9:41 PM
  • Below is my code block -

    $sourcepath = 'D:\maari\apdftest\master'
    $rulepath = 'D:\\maari\apdftest\pdfcsrules'
    $exepath = 'C:\program files\a-pdf content splitter'
    $today = Get-Date -Format "MM-dd-yyyy"
    #$outpath = 'D:\maari\apdftest\masterarchive' --this doesn't work as well in -Argumentlist "$file $rule $outs"


    $pdfs = get-childitem -path $sourcepath -filter *.pdf | Select-object -expandproperty FullName
    $rules = get-childitem -path $rulepath -filter *.rul| select-object -ExpandProperty FullName

    foreach($file in $pdfs) {
    foreach($rule in $rules) {
    If($($File.BaseName) -eq $($Rule.BaseName)){Start-Process -FilePath $exepath\pcscmd.exe -ArgumentList  "$($file.FullName) $($rule.FullName)"}
    }
    }

    Tuesday, June 20, 2017 9:50 PM
  • 1st - PLEASE format your code as code!
    2nd - that's not the code I posted. If you change the logic you should be able to debug it by yourself. Take a closer look to my example and compare it to yours.
    3rd - you really really should start to learn the basics of Powershell. Then you would understand the code and could debug it and could avoid a lot of frustration and safe a lot of wasted time

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Marked as answer by gurudevam Wednesday, July 5, 2017 11:48 PM
    Tuesday, June 20, 2017 11:21 PM