• 7 Posts
  • 390 Comments
Joined 2 years ago
cake
Cake day: June 18th, 2023

help-circle




  • I haven’t seen an official script, but found one on the MS learn site that should work.

    https://learn.microsoft.com/en-us/answers/questions/5399481/i-have-some-old-pub-files-which-i-want-to-convert

    You need to have publisher installed.

    Copy all your PUB files into a folder.

    Press Start and type in powershell, and open powershell.

    Copy the code below into notepad and replace C:\PubFiles with the path to your folder, then copy the script and paste it into the powershell window by right clicking on the window (it pastes when you right click).

    (You might need to press enter after pasting it)

    $PubFilePath = "C:\PubFiles"
    
    $publisher = New-Object -ComObject Publisher.Application
    
    $files = Get-ChildItem $PubFilePath -Recurse -Filter \*.pub
    
    foreach ($file in $files) {
    
        try{
    
            $doc $publisher.Open($file.FullName)
    
            $pdfPath = \[System.IO.Path]::ChangeExtension($file.FullName, ".pdf")
    
            $doc.ExportAsFixedFormat(\[Microsoft.Office.Interop.Publisher.PbFixedFormatType]::pbFixedFormatTypePDF$pdfPath)
    
            $doc.Close()
    
            } catch {
    
                Write-Error "Failed to convert $($file.FullName)"
    
            }
    
    }
    
    $publisher.Quit()