Copy link to clipboard
Copied
Hey Hivemind.
Working with Windows 11 Powershell. When I scan oversized files (9x12 or 11x17) and need to get them to 8.5 x 11 - i have to manually open them all, print to PDF, select shrink oversized pages, etc. Very time consuming.
I'd like to set up a PowerShell script to read all the .pdf files in a folder and process them all.
Normally with products, you have to load a module/library. I was looking to use AcrobatDC.AcrobatDCCom.App. (looks like that should have been used for older versions, not CC.
But it's erroring.
Any thoughts on how to do this?
Follow up: When I do save the PDF, the print is very gray compared to the original black/white that was scanned. I don't recall this being an issue before.
Copy link to clipboard
Copied
To automate the process of resizing PDF files in a folder using PowerShell, you'll need to use a library that can handle PDF manipulation.
I recommend using a more modern and versatile library, such as PDFSharp or iText7, which can be controlled from PowerShell via .NET. However, if you need to stick with Acrobat, I’ll guide you on that as well.
PDFSharp is a .NET library that can manipulate PDF files. Here's a simple example of how you might use it:
Install PDFSharp: You need to download and install PDFSharp. You can get it via NuGet if you are comfortable using .NET CLI tools, or you can download the binaries directly from their website.
PowerShell Script: Create a PowerShell script that uses PDFSharp to resize PDFs.
Add-Type -Path "path\to\PdfSharp.dll"
function Resize-PDF {
param (
[string]$inputFolder,
[string]$outputFolder
)
[PdfSharp.Pdf.IO.PdfReader]::Open($inputFile, [PdfSharp.Pdf.IO.PdfDocumentOpenMode]::Import) | ForEach-Object {
$doc = $_
$newDoc = New-Object PdfSharp.Pdf.PdfDocument
foreach ($page in $doc.Pages) {
$newPage = $newDoc.AddPage()
$newPage.Width = [PdfSharp.PageSize]::A4.Width
$newPage.Height = [PdfSharp.PageSize]::A4.Height
$gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($newPage)
$gfx.DrawImage($page, 0, 0, $newPage.Width, $newPage.Height)
}
$outputFile = Join-Path $outputFolder ($doc.PageCount.ToString() + ".pdf")
$newDoc.Save($outputFile)
$doc.Close()
$newDoc.Close()
}
}
$inputFolder = "C:\Path\To\Input"
$outputFolder = "C:\Path\To\Output"
Resize-PDF -inputFolder $inputFolder -outputFolder $outputFolder
If you prefer to use Adobe Acrobat via COM automation, make sure you have the necessary permissions and that Acrobat is properly installed. Here’s how you might use PowerShell to automate Acrobat:
Ensure Acrobat is Installed: Verify that Adobe Acrobat is installed and that you have access to the COM objects.
PowerShell Script: Create a PowerShell script that uses Acrobat’s COM interface.
$inputFolder = "C:\Path\To\Input"
$outputFolder = "C:\Path\To\Output"
# Load Acrobat COM
$acroApp = New-Object -ComObject AcroExch.App
# Process each PDF in the input folder
Get-ChildItem -Path $inputFolder -Filter *.pdf | ForEach-Object {
$inputFile = $_.FullName
$outputFile = Join-Path $outputFolder $_.Name
$avDoc = New-Object -ComObject AcroExch.AVDoc
$avDoc.Open($inputFile, "")
$pdDoc = $avDoc.GetPDDoc()
# Print with options
$jsObject = $pdDoc.GetJSObject()
$jsObject.print({
bUI: false,
bSilent: true,
bShrinkToFit: true,
nStart: 0,
nEnd: $pdDoc.GetNumPages() - 1,
printerName: "Adobe PDF"
})
$pdDoc.Close()
$avDoc.Close(False)
}
$acroApp.Exit()
The gray print issue could be related to the print settings or the quality settings used when printing to PDF. Here are a few steps to troubleshoot and potentially resolve this:
Check Printer Settings: Ensure that the print quality settings in the printer preferences are set to a high quality or black-and-white option.
Adjust PDF Settings: When saving the PDF, make sure the settings do not downscale the quality. Look for options related to color management or output quality.
Update Acrobat: Ensure that you have the latest version of Adobe Acrobat, as updates often fix bugs and improve functionality.
Check for Compression: Ensure that the settings for compression in the PDF save options are not set to excessively compress the file, which could reduce print quality.
By using the appropriate tools and settings, you should be able to automate the resizing of your PDF files and maintain high print quality.