• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Using PowerShell with Acrobat 24.1 - Printing

New Here ,
May 06, 2024 May 06, 2024

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

437

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

LATEST

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.

 

Using PDFSharp

PDFSharp is a .NET library that can manipulate PDF files. Here's a simple example of how you might use it:

  1. 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.

  2. 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

Using Adobe Acrobat via COM

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:

  1. Ensure Acrobat is Installed: Verify that Adobe Acrobat is installed and that you have access to the COM objects.

  2. 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()

Fixing Gray Print Issue

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:

  1. Check Printer Settings: Ensure that the print quality settings in the printer preferences are set to a high quality or black-and-white option.

  2. 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.

  3. Update Acrobat: Ensure that you have the latest version of Adobe Acrobat, as updates often fix bugs and improve functionality.

  4. 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.

opinion.jpgElisabeth

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines