# Print PDF to another PDF with powershell

**URL:** <https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287>\
**Category:** PowerShell Help\
**Created:** [January 4, 2023, 6:00pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287 "2023-01-04T18:00:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 4, 2023, 6:00pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/1 "2023-01-04T18:00:05Z")

</div>

Hi everyone

I have many PDFs file with image in the folder and need they solved in PDF again to be opened on Word.

Script command used  
Get-ChildItem -Path C:\Users\username\Downloads\PDF\* -Include invoice.pdf, mypdf.pdf | ForEach-Object {Start-Process $_.FullName -Verb Print}  
Get-ChildItem -Path C:\Users\username\Downloads\PDF\*.pdf | ForEach-Object {Start-Process $_.FullName -Verb Print}

How to create to save with the same name or “name+prefix” without having to keep typing each file?

I have this is script command too:  
$VerbosePreference = “Continue”  
add-type -AssemblyName microsoft.VisualBasic  
add-type -AssemblyName System.Windows.Forms  
$newext = “.pdfa”  
$Directory = "C:\Users\username\Downloads\PDF"  
$files = Get-ChildItem -Path $Directory -Include invoice.pdf, mypdf.pdf |  
ForEach-Object {Start-Process $\_.FullName -Verb Print}  
$focus = 2000

```
#Foreach ($File in $Files) 
for ($i=0; $i -lt 5; $i++) {
$newfile = $files.BaseName + $newext     
Start-Process $files.FullName -verb Print | out-printer -name "Page Segment Print File"  
start-sleep -Milliseconds $focus
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait($newfile)
start-sleep -Milliseconds 250
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -Milliseconds 1500
$focus = 250

```

}  
Write-Verbose “Print Files Generated”

Tks

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 4, 2023, 6:24pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/2 "2023-01-04T18:24:33Z")

</div>

Anderson,  
Welcome to the forum. 👋🏽

> [@Andymesmo](#):
>
> How to create to save with the same name or “name+prefix” without having to keep typing each file?

Instead of the built in Windows GUI elements I’d use a command line tool able to do what you need.

---

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 4, 2023, 6:39pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/3 "2023-01-04T18:39:40Z")

</div>

Thank you, @Olaf

I’m using this method why I’ll delivery to the user to run on .bat file later

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 4, 2023, 6:43pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/4 "2023-01-04T18:43:34Z")

</div>

> [@Andymesmo](#):
>
> I’m using this method why I’ll delivery to the user to run on .bat file later

Hmmm … I’m unsure if I get what you want to say. Some things can not be fully automated without using third party tools.

---

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 4, 2023, 6:52pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/5 "2023-01-04T18:52:19Z")

</div>

I’m not very open to using third-party tools due to company policies. I chose to use PS because it is a repetitive task for the user in this case. So, as he obtains many files in PDF but scanned (image), today he is opening each file and choosing the print option to be chosen “Microsoft Print to PDF” and saving again because when doing that, the analyst can open it in Word and follow up on what meets the requested requirements.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 4, 2023, 6:58pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/6 "2023-01-04T18:58:37Z")

</div>

> [@Andymesmo](#):
>
> I’m not very open to using third-party tools due to company policies.

If a third party tool is needed to accomplish what you or your colleagues are tasked you may ask for a policy change or an exception. 😉

> [@Andymesmo](#):
>
> I chose to use PS because it is a repetitive task for the user in this case.

OK. But if the task you want to automate does not have any API or CLI it will be at least unreliable and error prone to do it this way anyway. 🤷🏽‍♂️

> [@Andymesmo](#):
>
> So, as he obtains many files in PDF but scanned (image), today he is opening each file and choosing the print option to be chosen “Microsoft Print to PDF” and saving again because when doing that, the analyst can open it in Word and follow up on what meets the requested requirements.

What changes actually on this files when you re-print them with the MSFT PDF printer? Wouldn’t be even better to have a proper scan solution able to do the PDF right in the first place?

---

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 4, 2023, 7:12pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/7 "2023-01-04T19:12:57Z")

</div>

We receive files that way, including government files.  
I need help so that, through the shared powershell script command, I can respond to the request, also accepting the modification of the shared powershell script command or a new solution provided that a directory containing PDF files and save as another PDF file. The other steps to be completed, I have already developed a powershell script command to meet the analyst’s request.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 4, 2023, 8:25pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/8 "2023-01-04T20:25:12Z")

</div>

> [@Andymesmo](#):
>
> I need help so that, through the shared powershell script command, I can respond to the request, also accepting the modification of the shared powershell script command or a new solution provided that a directory containing PDF files and save as another PDF file.

You may wait for someone else to respond to your question here and I’ll keep my fingers crossed for you but I highly recommend for you to at least evaluate another approach using a third party PDF printer with a documented API or Command Line Interface.

---

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 5, 2023, 11:05am UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/9 "2023-01-05T11:05:52Z")

</div>

Thank you very much @Olaf ,  
I’ll look into the possibility of a PDF printer with the responsible department, although it’s quite bureaucratic.

Still, anyone who is interested and can help with the scriptp powershell command that I shared will be welcome and of great aggregation.

Thanks

---

<div class="post-metadata">

**Author:** ![Andymesmo](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andymesmo](https://forums.powershell.org/u/Andymesmo)\
**Post date:** [January 6, 2023, 7:48pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/10 "2023-01-06T19:48:56Z")

</div>

[SOLVED] - PDF to PDF

Here is the code where I got what I needed.  
Thank you, community.

```auto
$orders = $SourceFolder
$orders = "C:\Users\ **username** \Downloads\PDF\"
$newext = '_1.pdf'
$items = Get-ChildItem -Path $orders -Filter "*.pdf"
$focus = 1500

$i=0;

foreach ($item in $items) {     
    $newfile = $item.BaseName + $newext 
    Start-Process -FilePath $orders\$item -verb Print | out-printer -name "Microsoft Print to PDF"   
    start-sleep -Milliseconds $focus
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    start-sleep -Milliseconds 1500
    #[System.Windows.Forms.SendKeys]::SendWait($(Join-Path $destination $newfile)) 
    [System.Windows.Forms.SendKeys]::SendWait($newfile)
    start-sleep -Milliseconds 1800
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    start-sleep -Milliseconds $focus
    $focus = 1500
    Write-Output ($item.BaseName + "_converted" )
    $i++
} 

Write-Output "$i file(s) converted."
Start-Sleep -Seconds 2

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 6, 2023, 8:37pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/11 "2023-01-06T20:37:00Z")

</div>

> [@Andymesmo](#):
>
> Here is the code where I got what I needed.

Great that you’ve found a solution. And thanks for sharing. 👍🏽

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/print-pdf-to-another-pdf-with-powershell/21287/12 "2024-05-16T20:16:07Z")

</div>


