convert Publisher to PDF (or other)

Pete Stafford-Honeyball 0 Reputation points
2026-09-04T10:38:10.84+00:00

Hi,

I have your message re Publisher ending and suggested conversion to PDF - or other. Please advise if there is a tool whereby I can convert all my Publisher stuff in one hit rather than having to go thru the whole lot one at a time.

Thanks

Pete

Microsoft 365 and Office | Publisher | For home
0 comments No comments

2 answers

Sort by: Newest
  1. Marcin Policht 106.8K Reputation points MVP Volunteer Moderator
    2026-09-04T14:42:34.4933333+00:00

    Refer to https://learn.microsoft.com/en-nz/answers/questions/5960846/help-converting-publisher-files-to-pdfs

    This includes the adjusted script that addresses some limitation of the Microsoft provided tooling

    PowerShell

    <#
    .SYNOPSIS
    	Converts Microsoft Publisher .pub files to PDF format.
    .DESCRIPTION
    	This script automates the conversion of Microsoft Publisher (.pub) files to PDF format using the Microsoft Office Interop Publisher library.
    	It processes all files matching the specified filter, checks if a PDF already exists for each file, and skips conversion if the PDF is present.
    	The script logs successful conversions and any errors encountered during the process.
        Updated to fully support Windows Long Paths (>260 characters) and wildcard filters.
    .PARAMETER Filter
    	Specifies the file filter to select Publisher files for conversion.
    	This can be a specific file name (e.g., "document.pub") or a wildcard pattern (e.g., "*.pub").
    .PARAMETER Recurse
    	If specified, searches for Publisher files recursively in all subdirectories that match the filter. If omitted, only the current directory is searched.
    #>
    param
    (
    	[ValidateNotNullOrEmpty()]
    	[string]
    	$Filter,
    	[switch]
    	$Recurse
    )
    if (-not $PSBoundParameters.ContainsKey('Filter')) {
    	Write-Error "The -Filter parameter is required."
    	exit 1
    }
    if (-not ($Filter -like "*.pub")) {
    	Write-Error "The filter must specify .pub files (e.g., '*.pub' or 'file.pub').";
    	exit 1;
    }
    try {
    	# Safely determine the search directory and file pattern without letting GetFullPath choke on wildcards
    	$resolvedFilter = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Filter)
    	
    	if ([System.IO.Directory]::Exists($resolvedFilter)) {
    		$searchDir = $resolvedFilter
    		$searchPattern = "*.pub"
    	} else {
    		# Split the path into directory and file pattern parts safely
    		$searchDir = [System.IO.Path]::GetDirectoryName($resolvedFilter)
    		$searchPattern = [System.IO.Path]::GetFileName($resolvedFilter)
    		
    		# If the directory part still contains wildcards, strip them to find the base path
    		if ($searchDir -like "*[*?]*") {
    			Write-Error "Wildcards are only supported in the filename/extension part of the filter, not in folder names."
    			exit 1
    		}
    	}
    	if (-not [System.IO.Directory]::Exists($searchDir)) {
    		Write-Error "The directory does not exist: $searchDir"
    		exit 1
    	}
    	# Use modern dotnet enumeration which natively ignores the 260 character path limit
    	$searchOption = if ($Recurse) { [System.IO.SearchOption]::AllDirectories } else { [System.IO.SearchOption]::TopDirectoryOnly }
    	try {
    		$rawFiles = [System.IO.Directory]::EnumerateFiles($searchDir, $searchPattern, $searchOption)
    		$files = @()
    		foreach ($f in $rawFiles) {
    			$files += New-Object System.IO.FileInfo($f)
    		}
    	} catch {
    		Write-Error "Error finding files: $_"
    		exit 1
    	}
    	if ($files.Count -eq 0) {
    		Write-Error "No Publisher files found for the filter: $Filter";
    		exit 1;
    	}
    	Write-Output "Running...";
    	Add-type -AssemblyName Office;
    	Add-type -AssemblyName Microsoft.Office.Interop.Publisher;
    	try {
    		$app = New-Object -ComObject Publisher.Application;
    	} catch {
    		Write-Error "Microsoft Publisher is not installed or accessible.";
    		exit 1;
    	}
    	$successCount = 0;
    	$failCount = 0;
    	foreach ($file in $files) {
    		if ($file.Extension -eq ".pub") {
    			$fileFullName = $file.FullName;
    			
    			# Prepend long path escape prefix if the path length exceeds standard limits
    			if ($fileFullName.Length -ge 240 -and -not $fileFullName.StartsWith("\\?\")) {
    				if ($fileFullName.StartsWith("\\")) {
    					# Network UNC paths
    					$fileFullName = "\\?\UNC\" + $fileFullName.Substring(2)
    				} else {
    					# Local drive paths
    					$fileFullName = "\\?\" + $fileFullName
    				}
    			}
    			$pdfFilePath = [System.IO.Path]::ChangeExtension($fileFullName, '.pdf')
    			
    			# Use dotnet's Exists check to circumvent standard Test-Path path length limitations
    			if ([System.IO.File]::Exists($pdfFilePath)) {
    				Write-Error "PDF file already exists: $pdfFilePath";
    				$failCount++;
    				Continue;
    			}
    			# Open the file
    			try {
    				$doc = $app.Open($fileFullName);
    			} catch {
    				$failCount++;
    				Write-Error "Error opening file: $fileFullName $_";
    				Continue;
    			}
    			if (-not($doc)) {
    				$failCount++;
    				Write-Error "Failed to open file: $fileFullName";
    				Continue;
    			}
    			try {
    				# Export file as PDF
    				$doc.ExportAsFixedFormat([Microsoft.Office.Interop.Publisher.PbFixedFormatType]::pbFixedFormatTypePDF, $pdfFilePath);
    				if ([System.IO.File]::Exists($pdfFilePath)) {
    					Write-Output "Exported to $pdfFilePath.";
    					$successCount++;
    				} else {
    					$failCount++;
    					Write-Error "Failed to export file: $fileFullName";
    				}
    			} catch {
    				$failCount++;
    				Write-Error "Error during export: $_";
    			}
    			$doc.Close();
    		}
    	}
    	#Log output
    	Write-Output "Converted $successCount files with $failCount errors.";
    }catch{
    	Write-Error $_;
    }finally {
    	if ($app) {
    		#Quit Publisher
    		$app.Quit();
    	}
    }
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-09-04T10:38:24.9066667+00:00

    Yes. A sample PowerShell script is available to bulk export Publisher files instead of converting them one by one.

    Requirements:

    1. A working and licensed version of Publisher installed on the computer.
    2. The sample script downloaded to the computer.
    3. A PowerShell window opened with the required execution policies.

    How to use it:

    1. Download the sample script: Convert-PubFileToPDF.ps1
    2. Modify the script as needed.
    3. Run it against a file, folder, or folder tree.

    Examples:

    • Convert one file: Convert-PubFileToPDF.ps1 -Filter "C:\Documents\MyFile.pub"
    • Convert all Publisher files in the current folder: Convert-PubFileToPDF.ps1 -Filter "*.pub"
    • Convert all Publisher files in the current folder and subfolders: Convert-PubFileToPDF.ps1 -Filter "*.pub" -Recurse
    • Convert all Publisher files in a specific folder: Convert-PubFileToPDF.ps1 -Filter "C:\Documents\\*.pub"
    • Convert all Publisher files in a specific folder and subfolders: Convert-PubFileToPDF.ps1 -Filter "C:\Documents\\*.pub" -Recurse

    Notes:

    • The script is provided for instructional purposes and should be tested and adjusted for the environment before running it broadly.
    • If a PDF with the same name already exists, the file will not be exported; rename or delete the conflicting file and run the script again.
    • Microsoft also recommends converting existing Publisher files before October 2026. For editing after conversion, one supported path is Publisher to PDF, then open the PDF in Word.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.