如何使用IronPrint與ChatGPT Codex

Curtis Chau
Curtis Chau
已更新: 2026年10月26日

倉庫每晚為每筆訂單列印揀貨單。 某些訂單需要一份給揀貨員,其他需要一份給包裝員以及一份給發票文員。 當副本數錯誤時,沒有任何失敗。 包裝員找到沒有配對副本的單張,或發票辦公桌收到某筆訂單的九個單張,而列印記錄仍然報告這些訂單已寄出。

ChatGPT Codex,OpenAI的編碼代理,編輯存儲庫的文件,運行dotnet run和其他命令,並報告其所做的事情。 它可在ChatGPT桌面應用、IDE、終端和雲端中工作。 IronPrint,Iron Software的.NET列印程式庫,將PDF和圖像文件傳送到已安裝的印表機,靜默地或通過操作系統的列印對話框,設定紙張尺寸、方向、DPI、灰階和副本數量於一個PrintSettings物件中。

Codex接收一晚的揀貨單訂單和預期結果的清單。 Codex報告的每一副本數都來自CSV文件,並且整批在任何工作傳送到印表機之前就已計劃。

快速開始
NuGet使用NuGet安裝

PM > Install-Package IronPrint

在 NuGet 包管理器控制台中運行上述命令安裝 IronPrint,或在 NuGet 包管理器中搜索該包。

在.NET控制台專案中運行Codex,檔案應用於Orders資料夾。

$ironprint Install IronPrint 2026.10.1 from NuGet in this console project.
Program.cs should then plan the six orders in Orders/sample/ without sending a job.

Give each sample PDF a row in out/quickstart.csv. The columns are:

- file
- copies, from that order's row in Orders/manifest.csv
- printer, the PrinterName in appsettings.json
- found, yes or no, whether Printer.GetPrinterNames lists that printer

Read the total copies back from that CSV and show it.
Program.cs gets the key from IRONPRINT_LICENSE_KEY by itself.
Don't show the key's value anywhere, and don't list environment variables.
Keep the PrintCapture.Install line first in Program.cs.
Don't call Print, PrintAsync or ShowPrintDialog yet.
Stop after three failed builds or runs, and tell me what came out.
Text

$ironprint的提及將IronPrint的技能加載到會話中。



什麼是ChatGPT Codex,它如何適合於.NET列印工作?

Codex的CLI文檔解釋安裝和終端使用,源代碼和發布版在GitHub上。

Codex依賴於訓練數據和其上下文中的文件以支持IronPrint,錯誤的成員名稱將使構建失敗。

IronPrint支持Windows、macOS、iOS和Android。 本指南中的專案目標是net9.0-windows。

如何書寫IronPrint提示並為其設置Codex?

IronPrint批次提示命名輸入(每個訂單在Orders/manifest.csv中)、打印機及其名稱的來源(appsettings.json,經Printer.GetPrinterNames檢查),每個工作的設置(來自清單的副本數、紙張尺寸、縱向、灰階和150 DPI),證明(每個訂單一行的計劃CSV),真實值(清單中的預期狀態)和約束(精確的打印機名稱且不調用ShowPrintDialog)。

Codex搜索工作目錄及其上方的每個目錄,直至存儲庫根目錄,尋找.agents/skills資料夾。 每個技能資料夾持有一個SKILL.md文件,其前置材料給出名稱和描述。 將IronPrint的skill.md複製到.agents/skills/IronPrint/SKILL.md,$ironprint的提及可解決。 技能中的單文件示例固定在IronPrint 2026.8.1,快速入門安裝2026.10.1。

在任何工作之前,Codex載入了從存儲庫根到工作文件夾路徑中的AGENTS.md文件。 每目錄只讀取一個文件,且在兩者衝突時,距離工作文件夾最近的文件優先。 運行/init產生起始草案。

測試機器沒有一個能在無對話框的情況下完成工作的打印機,而對話框會阻止無人值守運行。 因此,測試存儲庫包含了一個小型捕獲類,攔截IronPrint發送到Windows的工作並將其寫入XPS文件,這樣沒有工作被排入隊列。 具有運行打印機的專案將其排除在外。

Write a root-level AGENTS.md containing a section called Nightly picking lists.
These are its rules:

- IronPrint is the only printing library. Its package and namespace are both IronPrint.
- The target framework stays net9.0-windows.
- For the API, check the ironprint skill in .agents/skills/ironprint/.
- The installed IronPrint.xml settles any doubt about a member.
- Orders/ is read-only.
- The printer name comes from appsettings.json and has to appear in Printer.GetPrinterNames.
- The first line of Program.cs installs PrintCapture. It stays first, and Capture/ stays as it is.
- Print and PrintAsync run only from Program.cs, after that line.
- Tests never call them, and code that runs never calls ShowPrintDialog.
- The key lives in IRONPRINT_LICENSE_KEY. No output, log or file ever contains its value.
- A count in a reply has to come from a CSV that the same turn wrote.
- Name that CSV in the reply.

Show me the file once it's written.
Text

如何請求Codex添加IronPrint並檢查授權?

Show me the IronPrint PackageReference in PickingBatch.csproj and the version that restore picked.
Then quote each IronSoftware package from the output of dotnet list package --include-transitive.
Don't touch any package reference.
Text

在nuget.org上,IronPrint 2026.10.1列出了三個依賴項,IronSoftware.Common 2026.4.2,IronSoftware.Abstractions 2026.1.2和IronSoftware.System.Drawing 2026.8.2。在我們的運行中,恢復還增加了IronSoftware.Drawing.Abstractions 2026.1.2。每次構建都將IronPrint的本機運行時文件複製到輸出文件夾中。 在固定版本之前查看IronPrint變更記錄。

Printer.GetPrinterNames,Printer.GetPrinterTrays和新的PrintSettings無需金鑰即成功,因此打印機清單無法證明授權。 無金鑰的打印調用在創建工作之前拋出授權異常,信息為需要生產授權。 同步Print將其包裹在AggregateException中,而PrintAsync直接拋出。 IronPrint 2026.10.1以外的程式碼無法引用授權例外類型。 因此一個處理器捕捉Exception並比較類型名稱。

Create Startup.ApplyIronPrintKey and make it the call right after PrintCapture in Program.cs.
It copies IRONPRINT_LICENSE_KEY into License.LicenseKey and reports License.IsLicensed.

Next, show me what IronPrint does with no key.
Run the program twice as child processes with the variable cleared for that child only:

1. A --licence-check run that lists the printers and builds a PrintSettings for PL-1023.
2. A --licence-check --send run that also calls Printer.Print once on Orders/sample/PL-1023.pdf.

Both runs use the printer from appsettings.json.
Log every call in out/licence-check.csv.
Its columns are run, call, result, exception type, inner type and message.
Give up after three repair attempts.
Text

IronPrint未讀取IRONPRINT_LICENSE_KEY,因此程序將其值複製到License.LicenseKey。 可以將金鑰放入appsettings.json、Web.config或App.config中,如授權金鑰頁面描述的那樣。

IronPrint如何列印多個文件副本?

副本指南設置NumberOfCopies一次並傳送一個工作,而不是在迴圈中調用Print。校準探測發送了兩頁揀貨單的三個副本,IronPrint在其列印票中構建了一個兩頁的工作副本數為3。 打印驅動生成額外的副本。 Microsoft Print to PDF將該票證轉換為一個六頁的文件,排序為1、2、1、2、1、2頁。

Make a throwaway console project in scratch/copies-probe/ on your own.
Exclude scratch/** from PickingBatch.csproj with a Compile Remove item.
Run it yourself to find what NumberOfCopies holds on a new PrintSettings.
It also tries 0, -1 and 1000 and records what reads back.

Then the explorer agent answers these from IronPrint.xml and the ironprint skill:

- What the XML says happens when a driver can't make several copies.
- What GetPrinterTrays returns for each installed printer.
- Whether PrintSettings.DefaultSettings is static or belongs to an instance.

Nobody sends a job, and Services/ and Program.cs stay as they are.
Write all the answers to out/copies-probe.csv.
Beside each answer, quote IronPrint.xml, the ironprint skill or the probe output.
Where a page and the probe disagree, say so.
Text

NumberOfCopies預設為1,屬性接受0、-1和1000。副本指南聲明0或負值回落到單副本。 列印調用在校準中拒絕了0和-1並拋出ArgumentOutOfRangeException,其信息為值必須為正,未創建工作。 因此批次在建構設置前拒絕這些訂單。 XML註釋補充道,某些平台忽略該值並列印一份副本。

每頁作為圖像以工作的DPI傳到打印機。 在探測中,150 DPI的A4頁面為1240乘以1753像素。 設置Grayscale之後,列印票的輸出顏色為單色。

如何計劃每晚的一批打印工作?

Have the worker agent write Services/PickingPrinter.cs.
It applies Orders/README.md to every row of Orders/manifest.csv and follows these rules:

- A --printer option overrides the name in appsettings.json.
- An --inbox option picks the PDF folder. Orders/inbox/ is the default.
- Check the printer name against Printer.GetPrinterNames before reading any order.
- Match the name exactly, case included.
- An unknown name stops the run with a message that lists the installed printers.
- Build a new PrintSettings for each Ready order.
- NumberOfCopies comes from the copies column, and PaperSize from the paper column.
- Every order gets portrait, grayscale and 150 DPI.
- An empty file, or one without a %PDF header, is Unreadable.

Add a --plan mode that sends nothing and writes out/print-plan.csv with these columns:

- order_id and file
- status, always one of the README's four
- NumberOfCopies, PaperSize, PaperOrientation, Dpi and Grayscale as the job would send them
- printer

Add a --send mode that awaits PrintAsync once per Ready order, in manifest order.
It writes out/send-log.csv with order_id, file and NumberOfCopies, and no plan file.
Don't run --send yet.
Run --plan over Orders/inbox/ and report the status counts from print-plan.csv.
Text

只有在打印調用讀取文件時,IronPrint才會報告損壞的文件。 在校準中,一個空文件失敗,拋出來自一個混淆命名空間的異常類型,該類型鏈接到IronPDF故障排除頁面,一個名為.pdf的文本文件失敗,InvalidDataException。 計劃中檢查PDF頭將這兩者排除在工作清單之外。

如何確認每個列印工作中攜帶的內容?

PL-1028.pdf是六個範例訂單之一,是一張兩頁的A4揀貨單,每個SKU都有一個箱子和數量,清單給其三個副本。

Now run --send with --inbox Orders/sample/.
Orders whose PDF isn't in that folder count as Missing and aren't sent.
PrintCapture writes each job to out/captured/ and adds a row to out/captured/jobs.csv.

Match send-log.csv to jobs.csv in sending order.
Then write out/sample-send.csv with one row per sent order and these columns:

- order_id and the NumberOfCopies it was sent with
- copies, pages, media and color from its jobs.csv row

Tell me whether each order went out as a single job carrying its copy count.
Text

輸出

下面的PDF是在測試運行中IronPrint為PL-1028構建的工作,並從捕獲的XPS文件逐頁轉換。

揀貨單PL-1028如IronPrint構建的該工作,捕獲到文件而不是打印機。該工作包括兩頁A4縱向以灰階顯示在150 DPI,且其列印票請求三個副本。

當打印機名稱不匹配時會發生什麼?

打印機名稱指南聲明名稱必須完全匹配操作系統,包含大小寫,且不匹配可能安靜失效或拋出錯誤。 校準工作未引發異常。 針對Warehouse Laser 01這個不存在的列隊和針對adobe pdf的工作(小寫字母)都被路由到Microsoft Print to PDF,該測試機器將其用作默認打印機。

IronPrint sends a job with an unknown printer name to the Windows default printer.
Show me that PickingPrinter refuses before that can happen.

Run --plan two times, passing each of these names with --printer:

1. "Warehouse Laser 01", a queue this machine doesn't have.
2. "adobe pdf", the installed name in the wrong case.

Neither run may change out/print-plan.csv.
Write out/printer-check.csv with the columns run, printer, exit code, message and plan rows written.
Tell me which printers the message listed.
Text

如何診斷錯誤列印的單張?

-i標誌 (--image) 將圖像附加到會議的首次提示或恢復它的提示,互動作曲家接受粘貼的圖像。

I attached a scan of a picking list with -i.
The packer found it alone, without the copies that should have come with it.
Read the order number from the image.
Look that order up in out/print-plan.csv and Orders/manifest.csv.
Tell me the copy count and paper size that the plan sends.
Also say whether the page in the image fits that paper.
Don't change any code.
Text

如何端到端追蹤不正確的批次輸出?

Find out why last night's run printed the wrong number of picking lists.
Logs/nightly-2026-10-14/print.log reports these five orders as sent.
Orders/warehouse-complaint.csv lists what the warehouse counted by hand for them.

Have the explorer agent read Jobs/NightlyPrint.cs and that log before you write anything.
Your findings go in out/nightly-diagnosis.md, covering:

- the cause behind each count in the complaint file
- the smallest fix
- a --plan command that proves the fix without sending a job

Don't run or edit any code.
Then tell me what you found.
Text

在允許編輯之前閱讀診斷。 健全的診斷還解釋為何日誌報告成功,因為日誌記錄每次調用而非列印的單張。

如何將一次性代碼轉變為可重用的、經過測試的組件?

Put the worker agent on a PrintQueueService class, built like this:

- Install Microsoft.Extensions.DependencyInjection and resolve the service from its container.
- Configure it with a PrintOptions record holding printer, DPI, grayscale and plan-only.
- Keep the README rules and the printer check from PickingPrinter.
- PrintQueueService.cs stays under 150 lines, with XML doc comments.
- Nothing calls Jobs/NightlyPrint.cs.

Run it plan-only over Orders/inbox/ into out/final-plan.csv.
Then compare every status and copy count with manifest.csv and list any difference.
Text

重構可以丟失打印機檢查但仍然可以編譯。

Add an xUnit project at tests/PickingBatch.Tests.
Keep it out of the main project's compile items, and put both projects in one solution.

Write tests on the real Orders/ files that check these:

- a 3-copy order gets NumberOfCopies 3 in a single PrintSettings
- a Letter order gets PaperSize.Letter, and an A4 order gets PaperSize.A4
- an order with copies 0 is Rejected and gets no settings
- the empty file and the text file are both Unreadable
- an unknown printer name is refused with a message naming the installed printers

Assert on settings objects and statuses.
Run the tests with dotnet test and a trx logger writing to out/tests/.
Report how many passed and how many failed, reading the trx file.
Text

對設置物件的斷言防止套件傳送工作,儘管仍需安裝已配置的打印機以進行精確名稱檢查。

$ironprint Look in the installed IronPrint.xml.
List every Printer member that sends a job or opens a dialog, then tell me:

- Which ones take a byte array instead of a path?
- Which ones show the operating system's print dialog?
- Which ones are asynchronous?

Back each member with one compiling line in a probe project under scratch/.
Build that probe with dotnet build only, and never run it.
It's the one place a ShowPrintDialog call may appear.
Then show me the line in PrintQueueService that stops plan-only mode from sending a job.
Text

如何在另一批列印工作中重用這些提示?

新的文件名、打印機名稱和副本規則,這些提示可以處理運送標籤或發票。 IronPrint AI編碼助手指南涵蓋每個助手共享的設置。

在實際運行中,這些提示產生了什麼結果?

Codex在單個會話中按順序接收上述提示。 .NET 9專案包含40個訂單、其揀貨單和每個訂單的預期狀態和副本數的清單。 分別的腳本重新檢查每個輸出文件。

  • 在批次之前,清單列出有35個準備好的訂單、有零副本的2個訂單、1個遺失文件和2個無法讀取的文件。
  • 計劃在所有40個訂單上匹配清單。
  • 計劃中的每個準備好訂單都有其清單副本數和紙張尺寸,為縱向方向以150 DPI灰階顯示。
  • 發送六個範例訂單每個產生一個捕獲工作。
  • 六個列印票中的副本數為1、2、2、1、3和3,與清單相同。
  • 六個工作持有的頁數為11頁,副本數增至20張。
  • 信函訂單被捕獲為215.9乘以279.4毫米頁,A4訂單是210乘以297毫米頁。
  • 六個捕獲工作的每頁是150 DPI的圖像沒有彩色像素,因此紅色優先帶是灰色。
  • 沒有金鑰時,程式列出了四個打印機並構建了設置,且列印調用失敗,顯示需要生產授權。
  • 兩個不正確的打印機名稱在寫入行之前就停止計劃,並且信息列出了四個已安裝的打印機。
  • 從掃描,Codex識別了PL-1024訂單並報告了來自計劃的三份A4副本。
  • 每晚的診斷追溯到一個循環,其中每次副本調用Print並已設置完整副本數。
  • 對零複製順序的紙張進行追蹤,讓夾具將0抬升到1。
  • 重構的PrintQueueService有51行,其計劃與清單在每個狀態和副本數上匹配。
  • Codex的會話中所有7個測試都通過了,並且在新的克隆中再次通過。
  • Codex列出了八個發送工作或打開對話框的打印機成員並為其建立了一個探測而未運行。
  • 一些步驟與頁面上運行的不同。 快速入門在三次失敗嘗試後停止而未寫入其CSV。一個授權檢查嘗試在金鑰仍設定的情況下運行,捕獲類攔截其列印調用。 瀏覽器從XML而不是查詢每打印機回答了托盤問題。 Codex報告計劃僅檢查在Program.cs中,而不是在PrintQueueService中。

Google Antigravity指南構建了一個等候同一異步列印調用的ASP.NET Core頁面。 在Claude Code指南中,每種類型的文件發送到其自己的打印機,並且一個子代理檢查打印機名稱檢查。 查看共享的運行記錄以獲得此運行的Codex版本、模型、測試機和時間。


疑難排解


問題?

如果您有任何疑問,請聯繫support@ironsoftware.com

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

閱讀更多

準備好開始了嗎?

NuGet 下載次數 52,106版本:2026.11剛剛發布