<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wolfgang Mitterbucher</title>
    <description>The latest articles on DEV Community by Wolfgang Mitterbucher (@wolfgang_mitterbucher).</description>
    <link>https://dev.to/wolfgang_mitterbucher</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4247911%2F33b959fc-281b-43bc-bb06-ad641099ee3d.jpg</url>
      <title>DEV Community: Wolfgang Mitterbucher</title>
      <link>https://dev.to/wolfgang_mitterbucher</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wolfgang_mitterbucher"/>
    <language>en</language>
    <item>
      <title>What broke when I tested my AI coding setup: 7 gotchas from hooks, PowerShell and permissions</title>
      <dc:creator>Wolfgang Mitterbucher</dc:creator>
      <pubDate>Wed, 25 Nov 2026 12:54:29 +0000</pubDate>
      <link>https://dev.to/wolfgang_mitterbucher/what-broke-when-i-tested-my-ai-coding-setup-7-gotchas-from-hooks-powershell-and-permissions-55jp</link>
      <guid>https://dev.to/wolfgang_mitterbucher/what-broke-when-i-tested-my-ai-coding-setup-7-gotchas-from-hooks-powershell-and-permissions-55jp</guid>
      <description>&lt;p&gt;I recently published a two-part guide on AI-driven development (AIDD): &lt;a href="https://www.mitterbucher.com/en/articles/aidd-ai-driven-software-development/" rel="noopener noreferrer"&gt;part 1&lt;/a&gt; covers the building blocks – project instructions, skills, hooks, MCP, memory –, &lt;a href="https://www.mitterbucher.com/en/articles/aidd-vs-code-setup/" rel="noopener noreferrer"&gt;part 2&lt;/a&gt; sets it all up step by step in VS Code on Windows, including PowerShell hooks and a runner that works through a queue of work packages in the background.&lt;/p&gt;

&lt;p&gt;Guides like that get copied line by line. So before publishing, I had every script from part 2 run in an isolated test repository – by Claude Code itself, in real sessions rather than dry runs: hooks firing on real tool calls, memory being written, the runner implementing actual work packages and opening (fake) pull requests. Most of it worked. Seven things didn't, or didn't work the way I had assumed.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The hook that "blocks" – but doesn't
&lt;/h2&gt;

&lt;p&gt;Claude Code hooks can veto a tool call. The rule is simple: &lt;strong&gt;exit code 2 blocks&lt;/strong&gt;, and whatever the script writes to stderr goes back to the agent as the reason. Any other non-zero code, including 1, is just a non-blocking error – the agent carries on.&lt;/p&gt;

&lt;p&gt;My protection hook for generated EF Core migrations ended with &lt;code&gt;exit 2&lt;/code&gt;. Registered like this, it never blocked anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"shell"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"powershell"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp; \"$env:CLAUDE_PROJECT_DIR/.claude/hooks/protect.ps1\""&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason is PowerShell, not Claude Code. When you run a script via &lt;code&gt;-Command&lt;/code&gt; and it exits with 2, the PowerShell &lt;em&gt;process&lt;/em&gt; still exits with 1 – &lt;code&gt;$LASTEXITCODE&lt;/code&gt; inside is 2, but that is not what the caller sees. I checked both Windows PowerShell 5.1 and PowerShell 7.7: exit code 1 in both. The fix is one statement at the end of the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&amp;amp; \"$env:CLAUDE_PROJECT_DIR/.claude/hooks/protect.ps1\"; exit $LASTEXITCODE"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, the hook returns 2, the write to &lt;code&gt;Migrations/&lt;/code&gt; is blocked, and the agent receives the message from stderr. If you write hooks in PowerShell, test the exit code from the outside – a hook that silently doesn't block is worse than no hook, because you think you're protected.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Mojibake in the agent's context
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;SessionStart&lt;/code&gt; hook prints the last session handoff, so a new session starts where the previous one stopped. Whatever such a hook writes to stdout goes straight into the context. My handoffs are in German, and the session transcript showed what the agent actually received:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SessionStart:startup hook success: Letzte Sitzungs�bergabe …
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A probe hook made it obvious. It printed &lt;code&gt;äöü ß&lt;/code&gt; and its own console encoding – the transcript recorded &lt;code&gt;��� �&lt;/code&gt; and &lt;code&gt;ibm850&lt;/code&gt;. Claude Code reads hook output as UTF-8; PowerShell on Windows writes in the old console code page. Any non-ASCII character is affected – German umlauts, accented names, typographic dashes. The fix goes at the top of every hook script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$utf8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UTF8Encoding&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;InputEncoding&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$utf8&lt;/span&gt;   &lt;span class="c1"&gt;# paths in the JSON on stdin&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;OutputEncoding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$utf8&lt;/span&gt;   &lt;span class="c1"&gt;# what the agent reads&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when the script reads files, &lt;code&gt;Get-Content -Encoding UTF8&lt;/code&gt; – Windows PowerShell 5.1 otherwise assumes ANSI for files without a BOM. A side finding from the same probe: with &lt;code&gt;"shell": "powershell"&lt;/code&gt;, Claude Code ran the hook in &lt;strong&gt;PowerShell 7&lt;/strong&gt; because it was installed, not in Windows PowerShell 5.1. Write hooks that work in both.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Your allow rules don't apply in a folder you haven't trusted
&lt;/h2&gt;

&lt;p&gt;The project's &lt;code&gt;.claude/settings.json&lt;/code&gt; allowed &lt;code&gt;dotnet build&lt;/code&gt;, &lt;code&gt;dotnet test&lt;/code&gt; and &lt;code&gt;dotnet format&lt;/code&gt; without prompting. In my headless runs, Claude Code printed this instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ignoring 3 permissions.allow entries from .claude/settings.json: this workspace
has not been trusted. Run Claude Code interactively here once and accept the
trust dialog …
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a deliberate safety feature – a cloned repository must not be able to grant itself permissions. Deny rules and hooks still apply in an untrusted folder; allow rules don't. It matters for automation, because &lt;strong&gt;every new git worktree is a new folder&lt;/strong&gt; that nobody has trusted. My runner creates one worktree per work package, so it passes the tool list on the command line instead of relying on the project file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;claude&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="s1"&gt;'Implement the work package from the input completely. Commit in small steps.'&lt;/span&gt; &lt;span class="sb"&gt;`
    --permission-mode acceptEdits `&lt;/span&gt;
    &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;allowedTools&lt;/span&gt; &lt;span class="s1"&gt;'Read,Edit,Write,Grep,Glob,Bash(dotnet build *),Bash(dotnet test *),Bash(git add *),Bash(git commit *)'&lt;/span&gt; &lt;span class="sb"&gt;`
    --max-turns 80 --max-budget-usd 5 --output-format json
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Path-scoped rules are lazy – and my first test was wrong
&lt;/h2&gt;

&lt;p&gt;Rules in &lt;code&gt;.claude/rules/&lt;/code&gt; can carry a &lt;code&gt;paths&lt;/code&gt; filter in their front matter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;---
paths:
  &lt;span class="k"&gt;- &lt;/span&gt;"tests/**/*.cs"
---
&lt;span class="gu"&gt;# Tests
&lt;/span&gt;&lt;span class="k"&gt;- &lt;/span&gt;Test names: Method_Situation_Expectation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My first test said they didn't work at all: after reading a test file, the agent knew nothing about the naming convention. Even an unconditional rule without &lt;code&gt;paths&lt;/code&gt; was missing. The debug log (&lt;code&gt;claude --debug&lt;/code&gt;) explained it – one line per file: &lt;em&gt;"not loading … CLAUDE.md: it … is in a session's scratchpad"&lt;/em&gt;. I had built the test repository inside Claude Code's own temporary scratch folder, and Claude Code deliberately doesn't load project instructions from there.&lt;/p&gt;

&lt;p&gt;Moved to a normal folder, everything behaved as documented:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;&lt;code&gt;CLAUDE.md&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;rule without &lt;code&gt;paths&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;rule with &lt;code&gt;paths&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no file read&lt;/td&gt;
&lt;td&gt;loaded&lt;/td&gt;
&lt;td&gt;loaded&lt;/td&gt;
&lt;td&gt;not loaded&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;after reading &lt;code&gt;tests/…/SmokeTests.cs&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;loaded&lt;/td&gt;
&lt;td&gt;loaded&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;loaded&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two lessons: path-scoped rules only appear when the agent reads or edits a matching file – so "the agent ignores my rule" may just mean it hasn't touched such a file yet. And when a test of your harness fails, read the debug log before you believe the result.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. One character that silently disabled a permission rule
&lt;/h2&gt;

&lt;p&gt;This one wasn't in the guide but in my own settings. I had allowed ssh commands to my server with a rule like this (host and key changed here):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"allow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"Bash(ssh -i * deploy@203.0.113.10:*)"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It never matched. The &lt;code&gt;:*&lt;/code&gt; suffix is an alternative spelling of a trailing wildcard – but only at the very end &lt;em&gt;and&lt;/em&gt; only if it is the rule's only wildcard. With a &lt;code&gt;*&lt;/code&gt; in the middle, the colon is taken literally, so the rule required &lt;code&gt;deploy@203.0.113.10:&lt;/code&gt; followed by something. Claude Code does log a warning about it at startup – I only found it in the debug log.&lt;/p&gt;

&lt;p&gt;Fixing the syntax exposed a second problem: the &lt;code&gt;*&lt;/code&gt; in the middle matches &lt;em&gt;any&lt;/em&gt; text, including extra ssh options such as &lt;code&gt;-o ProxyCommand=…&lt;/code&gt; – which makes ssh run an arbitrary local program. So the key path is now pinned, the wildcard sits only at the end, and two deny rules close the remaining gap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"allow"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"Bash(ssh -i ~/.ssh/id_deploy deploy@203.0.113.10 *)"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="nl"&gt;"deny"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"Bash(ssh *ProxyCommand*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Bash(ssh *proxycommand*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="s2"&gt;"Bash(ssh *LocalCommand*)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Bash(ssh *localcommand*)"&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both spellings are there because ssh treats option names case-insensitively, while permission rules are case-sensitive text patterns. I tested it without touching the server: &lt;code&gt;-o ProxyCommand=echo&lt;/code&gt; is denied in both spellings, while &lt;code&gt;ssh … -V&lt;/code&gt; (prints the version, opens no connection) still runs – proof that the allow rule matches and the denials come from the deny rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Two Claude Code installations on one machine
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;claude --version&lt;/code&gt; in the terminal said 2.1.202. The VS Code extension was running 2.1.331. An old global npm installation was on the PATH, while the extension ships its own binary – so terminal and editor were running different versions with different fixes and behaviour, and nothing told me.&lt;/p&gt;

&lt;p&gt;The fix: remove the npm package and use the native installer, which updates itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt; &lt;span class="n"&gt;uninstall&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="nd"&gt;@anthropic&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;claude&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="n"&gt;irm&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;claude&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ps1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;iex&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The installer put &lt;code&gt;claude.exe&lt;/code&gt; into &lt;code&gt;~\.local\bin&lt;/code&gt; – and warned that this folder was not on the PATH. Without that step, the terminal has no &lt;code&gt;claude&lt;/code&gt; at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$bin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Join&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt; &lt;span class="s1"&gt;'.local\bin'&lt;/span&gt;
&lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Path'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'User'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt; &lt;span class="s1"&gt;';'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;notcontains&lt;/span&gt; &lt;span class="nv"&gt;$bin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nc"&gt;SetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Path'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TrimEnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;';'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;";$bin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'User'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open terminals – including VS Code's integrated one – only see the change after a restart.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. One from the docs: shortcuts Windows keeps for itself
&lt;/h2&gt;

&lt;p&gt;Not a test failure, but something I noticed while checking every detail against the documentation: the VS Code extension's shortcuts for "Focus Input" (&lt;code&gt;Ctrl+Esc&lt;/code&gt;) and "Open in New Tab" (&lt;code&gt;Ctrl+Shift+Esc&lt;/code&gt;) collide with the Windows shortcuts for the Start menu and Task Manager. On Windows, rebind those two commands in VS Code's keyboard shortcuts. &lt;code&gt;Alt+K&lt;/code&gt; – insert the current selection as an &lt;code&gt;@file#lines&lt;/code&gt; reference – works fine and is the one I use most.&lt;/p&gt;

&lt;h2&gt;
  
  
  What worked: the background runner
&lt;/h2&gt;

&lt;p&gt;The part I was most curious about worked on the first run. The runner is a PowerShell loop that takes Markdown work packages from an inbox folder, creates a git worktree per package, lets &lt;code&gt;claude -p&lt;/code&gt; implement it, runs &lt;code&gt;dotnet test&lt;/code&gt; itself and opens a &lt;strong&gt;draft&lt;/strong&gt; pull request only if the tests are green. The test had two packages – a real one (volume discounts with a fixed interface and permitted paths) and a control package with a deliberately failing test:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Check&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;discount package implemented&lt;/td&gt;
&lt;td&gt;3 commits, 3 policy classes + tests, only in the permitted paths&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;verdict&lt;/td&gt;
&lt;td&gt;independent &lt;code&gt;dotnet test&lt;/code&gt; green → pushed, draft PR opened&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;control package with red test&lt;/td&gt;
&lt;td&gt;moved to &lt;code&gt;failed&lt;/code&gt;, not pushed, worktree kept for analysis&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;time&lt;/td&gt;
&lt;td&gt;about 3 minutes for both&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;cost from &lt;code&gt;total_cost_usd&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;about 0.80 US dollars for the real package, 0.30–0.35 for the control package, at API prices&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;all checks&lt;/td&gt;
&lt;td&gt;11 of 11, for the German and the English version of the script&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The one design decision I'd recommend regardless of tooling: &lt;strong&gt;the agent never decides whether it is done.&lt;/strong&gt; It may build, test and commit – pushing, the test verdict and the pull request belong to the script, and the merge belongs to a human.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;None of these issues would have shown up by reading the scripts. Each one needed a real run and a look at what actually arrived – the exit code seen from outside, the bytes in the transcript, the debug log. Treat your AI harness like any other code: version it, test it, and don't trust a check you haven't seen fail.&lt;/p&gt;

&lt;p&gt;The complete setup – directory layout for rules and memory, all hook scripts, the runner, VS Code tasks and the security notes – is in the guide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Part 1:&lt;/strong&gt; &lt;a href="https://www.mitterbucher.com/en/articles/aidd-ai-driven-software-development/" rel="noopener noreferrer"&gt;AIDD in practice: harness, skills, MCP and memory&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2:&lt;/strong&gt; &lt;a href="https://www.mitterbucher.com/en/articles/aidd-vs-code-setup/" rel="noopener noreferrer"&gt;Setting up the AI development environment in VS Code&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'd like to hear which gotchas you ran into with your own agent setup – especially on Windows.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claudecode</category>
      <category>powershell</category>
      <category>productivity</category>
    </item>
    <item>
      <title>PostScript to PDF without Ghostscript: lessons from a virtual printer</title>
      <dc:creator>Wolfgang Mitterbucher</dc:creator>
      <pubDate>Mon, 23 Nov 2026 13:09:49 +0000</pubDate>
      <link>https://dev.to/wolfgang_mitterbucher/postscript-to-pdf-without-ghostscript-lessons-from-a-virtual-printer-4lem</link>
      <guid>https://dev.to/wolfgang_mitterbucher/postscript-to-pdf-without-ghostscript-lessons-from-a-virtual-printer-4lem</guid>
      <description>&lt;p&gt;Virtual PDF printers are among the most inconspicuous tools on Windows: you print from any application, and out comes a PDF. Most of them have used the same recipe for decades – a PostScript printer driver produces PostScript, and Ghostscript turns it into a PDF. In my open-source printer &lt;a href="https://github.com/Mibuw/miPDFconvert" rel="noopener noreferrer"&gt;miPDFconvert&lt;/a&gt;, I have now replaced Ghostscript with the PostScript interpreter of my .NET library &lt;a href="https://github.com/Mibuw/miPDFlib" rel="noopener noreferrer"&gt;miPDFlib&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This post covers the result, the surprises the Windows print path had in store – and why virtual printers on Windows will have to be built quite differently in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  How a virtual PDF printer works on Windows
&lt;/h2&gt;

&lt;p&gt;The classic design has four parts, only two of which you write yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Printer driver:&lt;/strong&gt; Microsoft's PostScript class driver (&lt;code&gt;pscript5&lt;/code&gt;) ships with Windows. What it produces is defined by a printer description in PPD format: paper sizes, resolution, color – and which fonts the "printer" supposedly has built in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spooler:&lt;/strong&gt; it accepts the job and passes the PostScript on to a port.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Print monitor:&lt;/strong&gt; a DLL loaded by the spooler. It writes the job to a file and starts the program that turns it into a PDF – in the session of the user who printed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conversion:&lt;/strong&gt; PostScript is a programming language; turning it into a PDF takes a PostScript interpreter. Until now, that was Ghostscript.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ghostscript is mature, but it is a native program with its own installation, licensed under the AGPL or a commercial license. For miPDFconvert this meant: Ghostscript had to be installed separately at first, later it was bundled with the installer – which grew to 19 MB as a result – and the whole project was under the AGPL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Out with Ghostscript, in with miPDFlib
&lt;/h2&gt;

&lt;p&gt;miPDFlib's add-on package &lt;code&gt;miPDFlib.PostScript&lt;/code&gt; contains a PostScript interpreter (LanguageLevel 3) in pure managed code. In miPDFconvert it replaces the call to an external program with a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package miPDFlib.PostScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;MiPdf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;MiPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PostScript&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PostScriptOptions&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;AutoRotatePages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                &lt;span class="c1"&gt;// orientation comes from the driver&lt;/span&gt;
    &lt;span class="nc"&gt;Timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;// limit for hanging jobs&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OpenRead&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spoolFile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PostScriptConverter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToPdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;pdf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;A PostScript error comes back as a &lt;code&gt;PostScriptException&lt;/code&gt; with the error name, the offending command and the program's output – what a real printer would print on its error page. The interpreter runs in a sandbox without access to the file system or the network, with limits on run time and memory.&lt;/p&gt;

&lt;p&gt;The result in numbers: the installer shrank from &lt;strong&gt;19 MB to 3.4 MB&lt;/strong&gt;, a four-page Word document with a table, an image, shapes and a chart is converted in &lt;strong&gt;less than 0.3 seconds&lt;/strong&gt;, and there is no native dependency left. Since the print monitor, the printer setup and the printer description were rewritten at the same time, miPDFconvert is now licensed under the &lt;strong&gt;Apache License 2.0&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lessons from practice
&lt;/h2&gt;

&lt;p&gt;The first tests with hand-written PostScript worked right away. Things only got interesting with real print jobs from Word and Excel.&lt;/p&gt;
&lt;h3&gt;
  
  
  Printer fonts in the PPD
&lt;/h3&gt;

&lt;p&gt;The first Word printout stopped with a PostScript error. The cause was not in the interpreter but in the printer description: the previous PPD came from Ghostscript and declared 47 built-in printer fonts. The driver then replaces TrueType fonts with these printer fonts – Arial with Helvetica, Courier New with Courier – and patches a euro sign into copies of them. That requires the complete programs of the 14 standard fonts, which miPDFlib deliberately does not ship.&lt;/p&gt;

&lt;p&gt;The fix was a new PPD without printer fonts. The driver now embeds every TrueType font used, and the PDF contains the original fonts – Calibri stays Calibri. Under Ghostscript this was never the case, by the way: Arial came out as Helvetica.&lt;/p&gt;
&lt;h3&gt;
  
  
  Fonts that arrive bit by bit
&lt;/h3&gt;

&lt;p&gt;With the new PPD all jobs went through – but the PDFs from Word had &lt;strong&gt;no visible text&lt;/strong&gt;. Tables, lines and images were there, the letters were missing. A look at the embedded fonts showed an empty glyph table.&lt;/p&gt;

&lt;p&gt;The reason: the Windows driver downloads TrueType fonts incrementally. It first sends the font skeleton with an empty &lt;code&gt;glyf&lt;/code&gt; table and later adds each glyph actually needed, one by one, to the font's &lt;code&gt;GlyphDirectory&lt;/code&gt;. miPDFlib already handled this for CID fonts, but not for simple TrueType (Type 42) fonts.&lt;/p&gt;

&lt;p&gt;A second, smaller detail followed: the driver names the fonts it downloads &lt;code&gt;TT476t00&lt;/code&gt; and the like, and keeps the real name and style in &lt;code&gt;OrigFontName&lt;/code&gt; and &lt;code&gt;OrigFontStyle&lt;/code&gt; of the font's &lt;code&gt;FontInfo&lt;/code&gt;. Use those, and a PDF viewer shows &lt;code&gt;Arial,Bold&lt;/code&gt; instead of &lt;code&gt;TT476t00&lt;/code&gt;. Both fixes are in miPDFlib 1.5.1 and 1.5.2.&lt;/p&gt;

&lt;p&gt;The lesson: a PostScript interpreter for print jobs has to be tested with &lt;strong&gt;real driver output&lt;/strong&gt;. The easiest way to get it is to print through the installed driver into a file – for example with &lt;code&gt;PrintDocument&lt;/code&gt; and &lt;code&gt;PrintToFile&lt;/code&gt; in .NET:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Drawing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Drawing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Printing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PrintDocument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrinterSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrinterName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"miPDFconvert"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrinterSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrintToFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrinterSettings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrintFileName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; @&lt;span class="s2"&gt;"C:\temp\job.ps"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PrintPage&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Graphics&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DrawString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Font&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Arial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Brushes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Black&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Word's &lt;code&gt;PrintOut&lt;/code&gt; has an &lt;code&gt;OutputFileName&lt;/code&gt; parameter for the same purpose.&lt;/p&gt;
&lt;h3&gt;
  
  
  The comparison with Ghostscript
&lt;/h3&gt;

&lt;p&gt;I then converted the same driver output with both interpreters and rendered the pages: the images are practically identical. Even quirks such as rasterized transparency come out the same with both – those are produced by the driver, not the interpreter.&lt;/p&gt;
&lt;h3&gt;
  
  
  The spooler has its own rules
&lt;/h3&gt;

&lt;p&gt;Rewriting the print monitor and the setup revealed a few pitfalls that the documentation does not make obvious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Even a monitor without configuration&lt;/strong&gt; has to offer the functions for reading and configuring the port (&lt;code&gt;ReadPort&lt;/code&gt;, &lt;code&gt;XcvOpenPort&lt;/code&gt;, &lt;code&gt;XcvDataPort&lt;/code&gt;, &lt;code&gt;XcvClosePort&lt;/code&gt;); otherwise &lt;code&gt;AddMonitor&lt;/code&gt; rejects it as lacking the required functions. Empty implementations are enough.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Installing the driver:&lt;/strong&gt; letting &lt;code&gt;AddPrinterDriverEx&lt;/code&gt; copy the driver files from a folder (&lt;code&gt;APD_COPY_FROM_DIRECTORY&lt;/code&gt;) was rejected on my test system with "driver must be downloaded". What works reliably is the classic way: copy the files into the printer driver directory, then call &lt;code&gt;AddPrinterDriver&lt;/code&gt;. The setup takes the PostScript class driver from the driver store of the target computer – Microsoft's files no longer have to be in the installer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which session?&lt;/strong&gt; The monitor runs in the spooler service. It starts the PDF program with the token of the session the job was printed from (&lt;code&gt;WTSQueryUserToken&lt;/code&gt;), and only the printing user can read the job file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Save As dialog in the background:&lt;/strong&gt; because the print service starts the program, Windows' foreground lock keeps its windows behind the active one. Only attaching to the input queue of the foreground window (&lt;code&gt;AttachThreadInput&lt;/code&gt;) before &lt;code&gt;SetForegroundWindow&lt;/code&gt; brings the dialog to the front reliably.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Outlook: virtual printers without drivers
&lt;/h2&gt;

&lt;p&gt;All of this works today – but the approach has an expiry date. In 2023, Microsoft announced the &lt;a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/print/end-of-servicing-plan-for-third-party-printer-drivers-on-windows" rel="noopener noreferrer"&gt;end of servicing for third-party printer drivers&lt;/a&gt;. For Windows 11 and Windows Server 2025:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;15 January 2026:&lt;/strong&gt; new printer drivers are no longer published to Windows Update.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1 July 2026:&lt;/strong&gt; driver ranking always prefers the built-in IPP class driver.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1 July 2027:&lt;/strong&gt; third-party driver updates are only allowed for security fixes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is aimed mainly at drivers for physical printers. Windows continues to allow separate installation packages, and according to Microsoft there are no plans to disable features of the legacy driver model. So a classic virtual printer can still be installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows Protected Print Mode&lt;/strong&gt; is a different matter. It exists since Windows 11 24H2, and administrators can enable it via Group Policy or Intune. In this mode, the &lt;a href="https://techcommunity.microsoft.com/blog/microsoft-security-blog/a-new-modern-and-secure-print-experience-from-windows/4002645" rel="noopener noreferrer"&gt;spooler no longer loads third-party drivers, and only Microsoft-signed modules&lt;/a&gt;. A print monitor DLL, which practically every classic virtual printer needs, is ruled out there. The reasoning makes sense: the spooler runs with high privileges, and loadable DLLs like these were exactly the entry point for attacks such as PrintNightmare.&lt;/p&gt;
&lt;h3&gt;
  
  
  The future: the virtual printer as an app
&lt;/h3&gt;

&lt;p&gt;Microsoft's replacement is &lt;a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/print-support-app-v4-design-guide" rel="noopener noreferrer"&gt;Print Support App v4&lt;/a&gt; with an architecture for virtual printers, available from Windows 11 24H2. Instead of a driver and a print monitor, an app packaged as MSIX registers one or more printers in its manifest; a Microsoft monitor takes care of the port. When printing, a background task of the app receives the print data. A sketch based on the &lt;a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/devapps/msix-manifest-specification-print-support-virtual-printer" rel="noopener noreferrer"&gt;manifest specification&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;printsupport2:Extension&lt;/span&gt; &lt;span class="na"&gt;Category&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"windows.printSupportVirtualPrinterWorkflow"&lt;/span&gt;
                         &lt;span class="na"&gt;EntryPoint&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Tasks.VirtualPrinterTask"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;printsupport2:PrintSupportVirtualPrinter&lt;/span&gt; &lt;span class="na"&gt;DisplayName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"miPDFconvert"&lt;/span&gt;
      &lt;span class="na"&gt;PreferredInputFormat&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/postscript"&lt;/span&gt;
      &lt;span class="na"&gt;PdcFile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Config\printer-capabilities.xml"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;printsupport2:SupportedFormats&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;printsupport2:SupportedFormat&lt;/span&gt; &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"application/pdf"&lt;/span&gt; &lt;span class="na"&gt;MaxVersion&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1.7"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/printsupport2:SupportedFormats&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/printsupport2:PrintSupportVirtualPrinter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/printsupport2:Extension&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Three details matter for a PDF printer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;PreferredInputFormat&lt;/code&gt;&lt;/strong&gt; may only be &lt;code&gt;application/oxps&lt;/code&gt; or &lt;code&gt;application/postscript&lt;/code&gt;. Choosing PostScript gives you the same format as today – so a PostScript interpreter remains the right building block.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;SupportedFormats&lt;/code&gt;&lt;/strong&gt; lets applications that produce PDF themselves – Microsoft mentions Edge – pass their PDF through unchanged. Then no conversion is needed at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;OutputFileTypes&lt;/code&gt;&lt;/strong&gt; turns the printer into a file printer; Windows then shows the Save As dialog itself. For handing the PDF to a target application, as miPDFconvert does, you leave the attribute out and process the data in the app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One question is still open for me: how to hand the PDF to an arbitrary desktop application most cleanly from the isolated background task of an app. I will settle that before committing to an architecture.&lt;/p&gt;
&lt;h2&gt;
  
  
  What this means for miPDFconvert
&lt;/h2&gt;

&lt;p&gt;The classic printer stays for Windows 10 and for systems without Protected Print Mode. Alongside it comes an edition of miPDFconvert as a virtual printer based on the new model for Windows 11 24H2 and later – with PostScript as the input format, conversion by miPDFlib and PDF passthrough for applications that deliver PDF themselves. Both are on the &lt;a href="https://github.com/Mibuw/miPDFconvert#roadmap" rel="noopener noreferrer"&gt;project's roadmap&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;p&gt;miPDFconvert is open source (Apache-2.0) and free:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;winget install mipdfconvert
&lt;span class="c"&gt;# or&lt;/span&gt;
choco install mipdfconvert
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Mibuw" rel="noopener noreferrer"&gt;
        Mibuw
      &lt;/a&gt; / &lt;a href="https://github.com/Mibuw/miPDFconvert" rel="noopener noreferrer"&gt;
        miPDFconvert
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Virtual PDF printer for Windows (Apache-2.0) - print to PDF and hand it to a configurable target application. Converts with miPDFlib, no Ghostscript needed.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;p&gt;
  &lt;a rel="noopener noreferrer" href="https://github.com/Mibuw/miPDFconvert/assets/miPDFconvert_logo.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FMibuw%2FmiPDFconvert%2FHEAD%2Fassets%2FmiPDFconvert_logo.png" width="120" alt="miPDFconvert logo"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;miPDFconvert&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://github.com/Mibuw/miPDFconvert/releases/latest" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/bd2c9eb59d0e85ba7706ae711c2f0308d64a38af941b6655c86b533ea6d8f11a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f4d696275772f6d69504446636f6e76657274" alt="GitHub release"&gt;&lt;/a&gt; &lt;a href="https://github.com/Mibuw/miPDFconvert/LICENSE" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/886bb00dbf781bf4a65d2444847455b013522eb2f40f6e9bf18b11b901620ae5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4170616368655f322e302d626c75652e737667" alt="License: Apache 2.0"&gt;&lt;/a&gt; &lt;a href="https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Mibuw/miPDFconvert" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/cff69005a94e621996158317219aad2d87c8da4377774314bb62cf5c95f464e0/68747470733a2f2f696d672e736869656c64732e696f2f77696e6765742f762f4d696275772e6d69504446636f6e766572743f6c6162656c3d77696e676574" alt="winget"&gt;&lt;/a&gt; &lt;a href="https://community.chocolatey.org/packages/mipdfconvert" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/a1e91751b30f7802130e28b339581c4376f36345c789dfa765ec773722d8ba1b/68747470733a2f2f696d672e736869656c64732e696f2f63686f636f6c617465792f762f6d69706466636f6e766572743f6c6162656c3d63686f636f6c61746579" alt="Chocolatey"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A virtual PDF printer for Windows. Install it and a new printer named &lt;strong&gt;miPDFconvert&lt;/strong&gt;
appears in Windows. Anything you print to it is converted to a PDF, which is then either
handed to a configurable &lt;strong&gt;target application&lt;/strong&gt; or offered to you through a &lt;em&gt;Save As&lt;/em&gt; dialog.&lt;/p&gt;
&lt;p&gt;The PDF conversion uses &lt;a href="https://github.com/Mibuw/miPDFlib" rel="noopener noreferrer"&gt;miPDFlib&lt;/a&gt;, a PDF library with its
own PostScript interpreter in managed code — no Ghostscript or other external engine is needed
miPDFconvert is released under the &lt;strong&gt;Apache License 2.0&lt;/strong&gt; — see &lt;a href="https://github.com/Mibuw/miPDFconvert#licensing" rel="noopener noreferrer"&gt;Licensing&lt;/a&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How it works&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;
&lt;pre class="notranslate"&gt;&lt;code&gt;Application  ──►  "miPDFconvert" printer  ──►  print monitor (miPDFport.dll)
                  (Microsoft PostScript class        │  writes the PostScript job to a file
                   driver + miPDFconvert PPD)        │  only the printing user can read
                                                     ▼
                              miPDFconvert (started in the user's session)
                                                     │  PostScript ──► PDF with miPDFlib
                                                     │
                        ┌────────────────────────────┴────────────────────────────┐
                        ▼                                                         ▼
        TARGET_APPLICATION is set:                               TARGET_APPLICATION is empty
        the PDF is passed to that app                            a "Save&lt;/code&gt;&lt;/pre&gt;…&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Mibuw/miPDFconvert" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;If you want to convert PostScript or EPS files in your own .NET application, the &lt;a href="https://github.com/Mibuw/miPDFlib/blob/main/docs/guide/postscript.md" rel="noopener noreferrer"&gt;PostScript guide of miPDFlib&lt;/a&gt; covers all the options:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Mibuw" rel="noopener noreferrer"&gt;
        Mibuw
      &lt;/a&gt; / &lt;a href="https://github.com/Mibuw/miPDFlib" rel="noopener noreferrer"&gt;
        miPDFlib
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Open-source PDF library for .NET 8/10 (Apache-2.0): create, edit, merge, forms, text extraction, redaction, encryption, PAdES signatures (B-B to B-LTA), PDF/A, PDF/UA, ZUGFeRD, barcodes – no native dependencies
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;p&gt;
  &lt;a rel="noopener noreferrer nofollow" href="https://raw.githubusercontent.com/Mibuw/miPDFlib/main/assets/miPDFlib_logo.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2FMibuw%2FmiPDFlib%2Fmain%2Fassets%2FmiPDFlib_logo.png" width="140" alt="miPDFlib logo"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;miPDFlib&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;strong&gt;Open-source PDF library for .NET – create, edit, sign and validate PDFs without native dependencies.&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;a href="https://www.nuget.org/packages/miPDFlib/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/1bc22095ff5148d8ce22ba9586a675746bab57c673ad58e21e67f4dd2f91cb79/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f762f6d695044466c69622e737667" alt="NuGet"&gt;&lt;/a&gt;
  &lt;a href="https://www.nuget.org/packages/miPDFlib/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/b10384a980b3629c9485821cadf8bad8fcb77a6f00265c35f39482344e0b7b43/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f64742f6d695044466c69622e737667" alt="NuGet downloads"&gt;&lt;/a&gt;
  &lt;a href="https://github.com/Mibuw/miPDFlib/blob/main/LICENSE" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/886bb00dbf781bf4a65d2444847455b013522eb2f40f6e9bf18b11b901620ae5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4170616368655f322e302d626c75652e737667" alt="License"&gt;&lt;/a&gt;
  &lt;a href="https://github.com/Mibuw/miPDFlib/actions/workflows/ci.yml" rel="noopener noreferrer"&gt;&lt;img src="https://github.com/Mibuw/miPDFlib/actions/workflows/ci.yml/badge.svg" alt="CI"&gt;&lt;/a&gt;
  &lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/4734c0bc043541297c22a378323c1e2180a51030c4b2251cdcd8b403c32a9242/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2e4e45542d382e305f2537435f31302e302d3531324244343f6c6f676f3d646f746e6574266c6f676f436f6c6f723d7768697465"&gt;&lt;img src="https://camo.githubusercontent.com/4734c0bc043541297c22a378323c1e2180a51030c4b2251cdcd8b403c32a9242/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2e4e45542d382e305f2537435f31302e302d3531324244343f6c6f676f3d646f746e6574266c6f676f436f6c6f723d7768697465" alt=".NET 8 | 10"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On NuGet:&lt;/strong&gt; &lt;code&gt;dotnet add package miPDFlib&lt;/code&gt; – optional packages: &lt;code&gt;miPDFlib.Rendering&lt;/code&gt; (pages to images) and
&lt;code&gt;miPDFlib.PostScript&lt;/code&gt; (PostScript and EPS to PDF)&lt;/p&gt;
&lt;p&gt;An open-source (Apache-2.0) PDF library for .NET 8 / .NET 10 – pure managed code, no native dependencies
Create, read, modify, merge, fill forms, extract text, encrypt and digitally sign (PAdES) PDF documents.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why miPDFlib?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Apache-2.0:&lt;/strong&gt; free in closed commercial products – no AGPL obligations, no revenue limits, no licence key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;eIDAS-ready signatures:&lt;/strong&gt; PAdES B-B to B-LTA, HSM/cloud signers and two-step signing, built on .NET cryptography
without BouncyCastle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Archiving and e-invoices:&lt;/strong&gt; PDF/A, PDF/UA and ZUGFeRD / Factur-X / XRechnung hybrid invoices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coming from iText or Syncfusion?&lt;/strong&gt; See the &lt;a href="https://github.com/Mibuw/miPDFlib/blob/main/docs/COMPARISON.md" rel="noopener noreferrer"&gt;comparison&lt;/a&gt; (also with
PDFBox, PdfPig, PDFsharp/MigraDoc and QuestPDF) and the &lt;a href="https://github.com/Mibuw/miPDFlib/blob/main/docs/MIGRATION.md" rel="noopener noreferrer"&gt;migration guide&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Status: &lt;strong&gt;1.5.2&lt;/strong&gt; (stable) – all planned feature areas are implemented and tested (743…&lt;/p&gt;
&lt;/blockquote&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Mibuw/miPDFlib" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;If a print job comes out wrong, an issue with the PostScript file is the fastest way to a fix – ideally printed through the driver into a file, as shown above.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>windows</category>
      <category>pdf</category>
    </item>
    <item>
      <title>PDF to Markdown for LLM pipelines in .NET – without Python and without native libraries</title>
      <dc:creator>Wolfgang Mitterbucher</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:38:29 +0000</pubDate>
      <link>https://dev.to/wolfgang_mitterbucher/pdf-to-markdown-for-llm-pipelines-in-net-without-python-and-without-native-libraries-436b</link>
      <guid>https://dev.to/wolfgang_mitterbucher/pdf-to-markdown-for-llm-pipelines-in-net-without-python-and-without-native-libraries-436b</guid>
      <description>&lt;h1&gt;
  
  
  PDF to Markdown for LLM pipelines in .NET – without Python and without native libraries
&lt;/h1&gt;

&lt;p&gt;Most retrieval-augmented generation (RAG) pipelines start the same way: take a PDF, pull out the text, split it into&lt;br&gt;
chunks, embed the chunks. The first step looks trivial and is where many pipelines quietly lose quality. A language&lt;br&gt;
model can only answer from what the extractor hands it – and a typical extractor hands it text in the order the&lt;br&gt;
characters happen to sit on the page.&lt;/p&gt;

&lt;p&gt;This article shows what goes wrong, and how to get structured Markdown and clean chunks out of PDFs in a .NET service&lt;br&gt;
with &lt;a href="https://github.com/Mibuw/miPDFlib" rel="noopener noreferrer"&gt;miPDFlib&lt;/a&gt;, an Apache-2.0 PDF library in pure managed code. (Disclosure: I&lt;br&gt;
wrote it.)&lt;/p&gt;
&lt;h2&gt;
  
  
  What a plain text extractor gives you
&lt;/h2&gt;

&lt;p&gt;Take an ordinary report page: a heading, two columns of text, a table, a running head at the top and a page number at&lt;br&gt;
the bottom. Read line by line, as most extractors do by default, it comes out like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Water Utility – Quarterly Report
2 Operations
Pumps in the northern plant ran at Energy use per cubic metre fell
92 percent of their rated capacity for the fourth quarter in a row. The
during the second quarter. The two largest saving came from the new
older units were replaced in May, variable-speed drives, which adjust
which cut maintenance hours by the pump speed to the demand in
almost a third. the network.
Plant Capacity Energy (kWh/m³)
North 92 % 0.41
South 87 % 0.45
Page 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every word is there, so a quick check passes. But the sentences of the two columns are interleaved ("ran at Energy use&lt;br&gt;
per cubic metre fell"), the table has lost its columns, and the running head and page number sit in the middle of the&lt;br&gt;
content – on every page. Chunk this and embed it, and the retriever finds chunks that mix two topics, the model reads&lt;br&gt;
numbers without knowing which column they belong to, and "Page 1" ends up in the vector index a few hundred times.&lt;/p&gt;
&lt;h2&gt;
  
  
  Markdown instead of text
&lt;/h2&gt;

&lt;p&gt;The structure is there on the page; it just has to be read. &lt;code&gt;PdfLayoutExport.ToMarkdown&lt;/code&gt; analyses the layout first –&lt;br&gt;
columns, blocks, headings, lists, tables, headers and footers – and writes what it finds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;MiPdf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;MiPdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PdfDocument&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"report.pdf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;markdown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PdfLayoutExport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToMarkdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;# 2 Operations
&lt;/span&gt;
Pumps in the northern plant ran at 92 percent of their rated capacity during the second quarter. The two older units were replaced in May, which cut maintenance hours by almost a third.

Energy use per cubic metre fell for the fourth quarter in a row. The largest saving came from the new variable-speed drives, which adjust the pump speed to the demand in the network.

| Plant | Capacity | Energy (kWh/m³) |
| --- | --- | --- |
| North | 92 % | 0.41 |
| South | 87 % | 0.45 |

&lt;span class="gu"&gt;## Appendix
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happened on the way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Columns are read column by column.&lt;/strong&gt; The page is split at its whitespace; a channel only separates columns when
there is running text on both sides, so tables, invoices, lists and forms keep their rows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Headings get levels&lt;/strong&gt; from their size and weight, ranked across the whole document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tables keep their cells.&lt;/strong&gt; Tables drawn with rules are found from the lines and cell backgrounds on the page,
tables without rules from the gaps their rows share; cells spanning rows or columns are recognised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Running heads and page numbers are left out&lt;/strong&gt; – they are recognised by their repetition across pages, by
page-number patterns, or as small outermost lines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hyphenated words are joined&lt;/strong&gt; ("docu- ment" becomes "document"), but "self-employed" keeps its hyphen: the
document's own vocabulary decides. Paragraphs broken by a page or column end are joined again.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Markdown is a good intermediate format for language models: headings and tables survive, and it costs far fewer&lt;br&gt;
tokens than HTML.&lt;/p&gt;
&lt;h2&gt;
  
  
  Chunking by section
&lt;/h2&gt;

&lt;p&gt;For retrieval you usually do not want one long Markdown string but chunks that each belong to one section. The layout&lt;br&gt;
analysis behind the export is available directly, so chunking by heading takes a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StringBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;PdfLayoutAnalyzer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Analyze&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blocks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nc"&gt;LayoutBlockKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Header&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;LayoutBlockKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Footer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                                         &lt;span class="c1"&gt;// running heads and page numbers&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nc"&gt;LayoutBlockKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Clear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nc"&gt;LayoutBlockKind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Cells&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GroupBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppendLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" | "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppendLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReplaceLineEndings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the sample report this gives one chunk under "2 Operations" with both paragraphs and the table rows – the heading&lt;br&gt;
can go into the chunk's metadata or be prepended to the text before embedding. Each block also has its &lt;code&gt;Bounds&lt;/code&gt;, the&lt;br&gt;
page number and its lines with word positions, so an answer can point back to the exact place in the PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  How well does it work?
&lt;/h2&gt;

&lt;p&gt;Layout analysis is heuristic, so I measured it rather than trusting a few examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reading order across columns:&lt;/strong&gt; on 42 recent arXiv papers that were &lt;em&gt;not&lt;/em&gt; used while developing the column
detection, the word order matches the order of the LaTeX source to 96.9 % on average – reading line by line
gives 84.8 %, PdfPig's layout pipeline 96.1 %. On IRS forms and instructions the median is 98.7 % (line by
line: 50.8 %); for 151 ZUGFeRD and Factur-X invoices the order stays exactly as before, no line item is lost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block kinds:&lt;/strong&gt; compared with the structure tags of tagged IRS instructions, 89 % of the headings, 88 % of the
list items and 83 % of the paragraphs are recognised.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; about 5 ms per page for the full analysis, including reading the file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same analysis also exports to hOCR, ALTO and PAGE XML, if your pipeline or an archive expects those formats.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;p&gt;Better to know them before relying on it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No OCR.&lt;/strong&gt; A scanned page without a text layer has no text to analyse; run OCR first (many scanners and OCR tools
add an invisible text layer that miPDFlib reads).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heuristics, not a vision model.&lt;/strong&gt; Magazine layouts with text flowing around images, or tables whose rows are
only separated by alignment, can still come out imperfectly. Models that look at the rendered page are more robust
there – and far more expensive per page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Formulas&lt;/strong&gt; come out as the characters they are drawn with, not as LaTeX.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why not just call Python?
&lt;/h2&gt;

&lt;p&gt;In Python, tools such as Docling or pymupdf4llm do this job, and they are good at it. For a .NET service, though, a&lt;br&gt;
Python sidecar means a second runtime, a second deployment and a process boundary – and PyMuPDF is AGPL or commercial.&lt;br&gt;
miPDFlib runs in-process, has no native dependencies (so it works the same on Windows, Linux and in containers), and is Apache-2.0, so it can go into closed commercial products. The same library also creates, fills,&lt;br&gt;
signs and archives PDFs, which helps when the documents that come out of the pipeline need to go back into a PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet add package miPDFlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://github.com/Mibuw/miPDFlib/blob/main/docs/guide/text-extraction.md" rel="noopener noreferrer"&gt;text extraction guide&lt;/a&gt; covers the&lt;br&gt;
options (columns, Markdown export settings, letters with fonts and colors, vector paths). If a PDF of yours comes out&lt;br&gt;
wrong, an issue with the file – or a synthetic copy of its layout – is the fastest way to get it fixed.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>pdf</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
