如何使用IronPrint与ChatGPT Codex
仓库每晚为每个订单打印一份拣货单。 某些订单需要一份给拣货员,其他需要第二份给包装员,第三份给发票员。 当副本数量错误时,没有任何失败。 包装员找到一张没有伴侣副本的纸,或者发票台收到九张一个订单的纸,而打印日志仍报告那些订单已发送。
ChatGPT Codex,OpenAI的编码代理,编辑了一个存储库的文件,运行dotnet run和其他命令,并报告了它的所作所为。 它在ChatGPT桌面应用程序、IDE、终端和云中工作。 IronPrint是Iron Software的.NET打印库,将PDF和图像文件发送到已安装的打印机,通过静默或操作系统的打印对话框实现,设置纸张大小、方向、DPI、灰度和份数在一个PrintSettings对象上。
Codex接收到一晚的拣货单订单和预期结果的清单。 Codex报告的每份副本数量来自一个CSV文件,整个批次在任何作业发送到打印机之前都已计划好。
快速入门在一个.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.
$ironprint提到加载IronPrint的技能到会话中。
最小工作流程(5 个步骤)
- 从NuGet下载C#打印库
- 将IronPrint的技能保存为.agents/skills/ironprint/SKILL.md,以便
$ironprint提到能够解析 - 提交一个AGENTS.md,命名打印机名称和要求每个数量的CSV。
- 针对
Printer.GetPrinterNames的精确匹配后,为每个订单构建一个PrintSettings,其副本计数。 - 在任何作业发送之前将计划文件与清单进行比较。
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,Quickstart安装了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.
如何要求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.
在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.
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.
NumberOfCopies默认为1,并且属性接受0,-1和1000。拷贝指南说明0或负值将回退到单个副本。 在校准中,打印调用拒绝了0和-1,抛出一条消息为Value must be positive的ArgumentOutOfRangeException,并且没有作业被创建。 因此在构建任何设置之前,批次会拒绝这些订单。 XML备注补充说明某些平台忽略其值并打印一份副本。
每个页面都作为作业DPI中的图像发送到打印机。 在探头中,一个150 DPI的A4页面为1240 x 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.
只有在打印调用读取损坏的文件时,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.
输出
下面的PDF是IronPrint在测试运行中为PL-1028构建的作业,从捕获的XPS文件中逐页转换。
拣货单PL-1028为IronPrint构建作业,捕捉到文件中而不是打印机。作业包含两页150 DPI灰度的A4纵向页面,其打印票据请求三份副本。
当打印机名称不匹配时会发生什么?
打印机名称指南指出,名称必须完全匹配操作系统,包括大小写,并且不匹配“将会悄无声息地失败或抛出错误”。 校准作业没有引发异常。 为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.
如何诊断打印错误的纸张?
-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.
如何从头到尾调试不正确的批处理输出?
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.
在允许编辑之前读取诊断信息。 合理的诊断还解释了为什么日志报告成功,因为日志记录每次调用而不是打印的纸张。
如何将一次性代码转化为可重用的、经过测试的组件?
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.
重构可能丢失打印机检查并仍然编译。
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.
对设置对象的断言阻止套件发送作业,尽管确切名称检查仍需要安装配置的打印机。
$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.
如何在另一个打印批次中重用这些提示?
使用新的文件名称、打印机名称和副本规则,相同的提示可以处理运输标签或发票。 IronPrint AI编码助手指南涵盖每个助手共享的设置。
在实际运行中这些提示生成了什么?
Codex按顺序在一个会话中接收到上述提示。 .NET 9项目持有40个订单,它们的拣货单和包含每个订单的预期状态和副本计数的清单。 单独的脚本重新检查每个输出文件。
- 在批处理之前,清单列出了35个备单,2个0份订单,1个丢失文件和2个不可读取文件。
- 计划与所有40个订单的清单匹配。
- 计划中的每个备单订单都有其清单副本计数和纸张大小,以150 DPI灰度纵向排列。
- 发送六个样本订单为每个生成了一个捕获的作业。
- 六个打印票据中的副本数量为1、2、2、1、3和3,与清单中相符。
- 六个作业包含了11页,副本数量增加到20张纸。
- 按字母顺序的订单被捕获为215.9 x 279.4毫米页面,A4订单为210 x 297毫米页面。
- 六个捕获作业的每一页都是150 DPI无色像素图像,因此红色优先带为灰色。
- 没有钥匙,程序列出四个打印机并构建设置,打印调用因生产许可证要求而失败。
- 两个错误的打印机名称在任何行写入之前停止计划,消息列出四个已安装的打印机。
- 从扫描中,Codex识别了订单PL-1024,并报告了计划中的A4三份副本。
- 夜间诊断将9、4和18张纸追溯到一个循环,该循环每份副本调用一次打印,副本数已设置完整。
- 它将0份订单的纸张追溯到一个将0提升到1的夹子。
- 重构后的PrintQueueService有51行,其计划在每个状态和副本计数与清单匹配。
- 在Codex的会话中所有7个测试通过,并再次在新克隆中通过。
- Codex列出发送作业或打开对话框的八个Printer成员,并为他们构建探头而未运行。
- 有些步骤与页面中的运行不一样。 Quickstart在三次失败尝试后停止,未写入其CSV。一次许可证检查尝试运行时密钥仍然设置,并且捕捉类拦截了其打印调用。 浏览器从XML中回答托盘问题,而不是查询每个打印机。 Codex报告说仅计划检查在Program.cs中,而不在PrintQueueService中。
Google Antigravity指南构建一个ASP.NET Core页面,等待相同的异步打印调用。 Claude Code指南中,每种文档类型都发送到自己的打印机,并且一个子代理检查打印机名称检查。 有关本次运行的Codex版本、型号、测试机器和时间,请参见共享运行记录。
故障排除
- 如果副本数量被忽略,如何打印多份副本
- 如果作业是去默认打印机,如何指定打印机名称
- 如果接口在打印调用期间停止响应,Print()方法在WPF和WinForms中挂起
- 如果每次打印调用失败都会出现相同的许可消息,web.config许可设置
有问题吗?
如果您有任何问题,请联系support@ironsoftware.com
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。