I have a PDF document that I would like to split with each page being a separate file. I’d like to avoid installing anything to do this as I’m trying to keep the command simple for others to just copy/paste into PowerShell.

Would it also be possible to add the split command to the command below? It renames files based on the list of names found in names.txt. There is an equal number of files and names.

$names = cat "\path\to\names.txt"; $i=0; dir | % { ren $_ "$($names[$i]).pdf"}

  • DerisionConsulting@lemmy.ca
    link
    fedilink
    English
    arrow-up
    2
    ·
    15 days ago

    I can’t help you, but there’s an issue with your formatting so the code won’t show. You need the apostrophes on the same line, for the “format as code” things to work.

    $names = cat "\path\to\names.txt"; $i=0; dir | % { ren $_ "$($names[$i]).pdf"}

  • okwhateverdude@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    15 days ago

    You can manage an install-less solution with a docker container assuming you can get docker on the client machines.

    There are numerous PDF cli tools that will split pages for you, so the challenge is finding the right one that is trivial for you to use with docker.

    My internet sleuthing revealed that there is already a ready-made docker image for an older version of Apache PDFbox, but there are likely other docker containers you could use.

    You can incorporate usage into the above snippet pretty easily if you ask one of the AI chatbots. Your prompt will be something like: “Given this one-liner in Powershell (copypaste the one-liner), I want you to change it to also use this docker container (link to github) of Apache PDFBox 2.0 (link to PDFBox docs) to split PDFs into pages. Rewrite the one-liner to do this.”

  • wizardbeard@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    1
    ·
    15 days ago

    Windows should have a built in Print to PDF option under printers you can use in conjunction with the print menu to “print” individual pages to PDF.

  • pwshguy (mdowst)@programming.devM
    link
    fedilink
    arrow-up
    1
    ·
    13 days ago

    PowerShell does not have a built in PDF reader, so it is not possible without installing a module or calling a third party app. The PSWritePDF module will do what you are asking. The module can be installed from the gallery, so you could technically install and import it in a single line.