# The Prompt: Batch-Convert Microsoft Publisher Files to PDF (with AI) Microsoft is retiring Publisher on **October 1, 2026**. If you were an avid Publisher user like me, you might have a lot of .PUB files which will all of a sudden be unusable. I needed a solution to convert .PUB files into PDFs, which is the official MS advice for how to keep the files usable more long-term. From the PDF format they can then be converted into Word documents for editing, if needed. I wanted a solution that could search for the PUB files on a drive and convert them, so that the PDF would be sitting right next to it in the same directory if I ever needed it. I used Claude, and after a number of hurdles we got a solution in the form of a batch file which I can point at a drive of my choice. It can also skip PUB files that already have a PDF version of it in the folder. Below is the prompt I've distilled from that process — written so you can hand it to an AI assistant (Claude, ChatGPT, Copilot, etc.) and get a working batch converter on the first real try, instead of the trial-and-error it took me to get there. --- ## The Prompt ``` I need a Windows solution to batch-convert Microsoft Publisher (.pub) files to PDF ahead of Publisher's retirement (support ends October 1, 2026). CONTEXT: - I have a large number of .pub files (potentially hundreds) scattered across folders/subfolders, possibly a whole drive. - Microsoft Publisher is installed on the machine that will run this. - I want to hand this off to other non-technical people to run, so it needs a simple double-click launcher, not just a raw script. REQUIREMENTS: 1. Use PowerShell with Microsoft Publisher's COM automation object (Publisher.Application) to do the actual conversion — this produces the same quality PDF as using File > Export inside Publisher itself. Use the document's ExportAsFixedFormat method. IMPORTANT — get these COM constants right, as they are commonly mis-documented or confused: - The fixed format TYPE for PDF is PDF = 2 (not 0 or 1). - The export INTENT should be "printing quality" = 3 (not "screen" quality), since these are being archived, not just viewed on screen. Please verify these constant values make sense together and test the logic for off-by-one errors before finalizing — this was the single biggest source of failed conversions when this was built previously. 2. Recursively scan a folder (default to the whole C:\ drive if no path is given) for all .pub files. 3. Save each PDF in the SAME folder as its source .pub file, using the same filename with a .pdf extension. 4. RELIABILITY — this is critical for large batches: - A single corrupted or oversized .pub file can hang Publisher's COM object indefinitely, freezing the entire batch. Run each file's conversion in its own background job (Start-Job / Wait-Job) with a configurable timeout (default 120 seconds). If a file doesn't finish in time, forcibly stop the job AND kill any orphaned MSPUB.exe process, log it as "Timed Out", and move on to the next file automatically — do not let one bad file stop the whole run. - Also kill any stray MSPUB.exe processes before starting the batch and after the whole batch finishes, in case a previous run left something running. 5. LOGGING: - Log every file's result (OK / Skipped / Timed Out / Error, plus any error message) to a CSV file on the Desktop. - Save/update the CSV log every 10 files as you go (not just at the very end), so if the batch is interrupted partway through, the log up to that point isn't lost. 6. RESUMABILITY: include a -SkipExisting switch/flag that skips a .pub file if a same-named .pdf already exists next to it — so if a run gets interrupted, re-running it only processes what's left. 7. EASE OF USE: also create a simple .bat file that: - Prompts the user (with plain-English text) for which drive or folder to scan, defaulting to C:\ if they just press Enter. - Asks Y/N whether to skip files that already have a PDF. - Runs the PowerShell script with the right flags automatically, using -ExecutionPolicy Bypass so the user doesn't have to change any Windows security settings themselves. - When accepting a folder path from the user, strip a trailing backslash if present — a path like "E:\" immediately before a closing quote in a batch file can break argument parsing on Windows. Handle this edge case. - Tells the user where to find the log file when it's done. Please write out the full PowerShell script and the full .bat launcher, and briefly explain the reasoning behind the timeout/background-job approach so I understand why it's necessary (i.e. what fails without it). ``` --- ## Why this prompt works The reason a plain "write me a script to convert Publisher files to PDF" request usually goes sideways is that the failure modes only show up at scale, and the COM constants aren't intuitive: - **The COM constants are the #1 trap.** Publisher's `ExportAsFixedFormat` takes numeric constants for format type and quality/intent that aren't obvious from the method name, and it's easy for an AI (or a human skimming old documentation) to guess plausible-but-wrong values. A wrong constant doesn't always throw a clear error — sometimes it just produces a bad or empty PDF. Naming the correct values up front short-circuits that whole guessing process. - **One file can hang the whole batch.** Publisher's COM automation has no reliable built-in timeout, so a single oversized or corrupted file can freeze a script indefinitely with no error at all — you'd just come back hours later to a stuck terminal. The background-job-with-timeout pattern is the fix, and it's not something most AI-generated first drafts include unless asked. - **Stray processes pile up.** Every timeout or crash can leave an invisible `MSPUB.exe` process running in the background, which then blocks the *next* file from opening cleanly. Explicitly killing stray processes before/after prevents a slow buildup of zombie processes over a long batch. - **Real batches get interrupted.** Laptops sleep, people close windows by accident. Incremental log-saving and a skip-existing flag mean you never lose progress or have to start over from file one. If you're doing this yourself: the two scripts and README used in the original solution are the actual working files — feel free to link/attach those rather than regenerating from the prompt, if your platform allows it. The prompt above is designed for anyone who can only share a prompt, not the files themselves. --- ## Step-by-step 1. I had a large number of .PUB files that would become unusable once Microsoft retired Publisher, so I needed to convert them to PDF — Microsoft's own recommended format for keeping the files usable long-term. 2. I wanted a solution that could search a whole drive for .PUB files and convert each one automatically, saving the PDF right next to the original in the same folder. 3. I used Claude to build the solution, working through a number of hurdles — including getting the exact Microsoft Publisher COM export settings right, since the wrong values fail silently instead of throwing a clear error. 4. Together we built in reliability features needed for a large batch: a timeout on each file so a single corrupted file can't hang the whole run, automatic cleanup of any stray Publisher processes left behind, and a log file that saves progress every few files in case the run is interrupted. 5. We packaged the final solution as a simple double-click batch file, so I can point it at any drive or folder, and it will skip any .PUB file that already has a matching PDF next to it. 6. I distilled the whole process into a single reusable prompt so others facing the same Publisher retirement deadline can get a working solution without hitting the same hurdles. ## Tools used - Claude --- *Publisher's official retirement date is October 1, 2026. If you've still got .pub files sitting around, now's the time.*