GitHub CopilotでIronPrintを使用する方法
貨物デポは、トレーラーが出発するたびにキャリアの引き渡しフォームを印刷します。 デポのウェブポータルは、運転者、封印番号、パレット数、有害物のフィールドを含むPDFとして各フォームを保存し、Visual Studioソリューション内の.NETサービスがそれぞれ2部ずつ印刷します。 サービスを編集するアシスタントは、そのソリューション内でチームがすでに使用しているエディタで作業する必要があります。
GitHub Copilotは、Visual StudioおよびVS Code内でチャットとエージェントモードを提供し、ターミナル用のCopilot CLIと、アサインされたイシューにプルリクエストで応答するGitHubクラウドエージェントを提供します。IronPrintは.NETからプリンターにPDFや画像を送り、用紙サイズ、コピー数、解像度、フォームのフラット化を単一のPrintSettingsオブジェクトで設定します。 これらのCopilotサーフェスの各々は、リポジトリ内の指示ファイルからIronPrintのルールを読み取ります。
以下のプロンプトは、IronPrintに基づいて構築された印刷コードをCopilotに要求します。 プリンターのハードウェアの選択や印刷サーバーの設定はリポジトリからアシスタントが実行できない別のタスクです。 フラット化ガイドでは、これらのフォームが依存するIronPrintの設定について説明しています。
クイックスタートソリューションフォルダからcopilotを起動してプロンプトを送信します。 CLIでは、@をパスの前に設定してそのファイルを添付します。Visual Studioでは、Copilot Chatが同じ目的で#を使用します。
Fill in @src/Depot.Printing/HandoverPrinter.cs so the depot can print its handover forms.
Use IronPrint 2026.10.1, the version Directory.Packages.props already pins.
Give the class three public static members:
- InstalledPrinters() returns the names from Printer.GetPrinterNames.
- BuildSettings(string printerName) returns the PrintSettings that @docs/print-profile.md describes.
- PrintAsync(string pdfPath, string printerName) checks the name first, then sends the job.
An unknown name throws an ArgumentException whose message lists the installed printers.
Build the solution and fix every error.
Then list the files you changed.
プロンプトは個々の設定を名指ししていません。 docs/print-profile.md内の印刷プロファイルにはすべての設定がリストされており、Flattenもその中に含まれています。
ライセンスキーは、Copilotが実行される環境に設定されたIRONPRINT_LICENSE_KEYに入ります。 IronPrintそれ自体はその変数を読み取りません。 テストでは、プログラムがLicense.LicenseKeyにその値を割り当てるまで、変数が設定されたままでもLicense.IsLicensedはfalseのままでした。 キーの他のサポートされている場所はライセンスキガイドにリストされています。
最小限のワークフロー(5ステップ)
- NuGetからC#印刷ライブラリをダウンロードする
- IronPrintのルールを.github/copilot-instructions.mdと1つのパス固有の指示ファイルに書き込みます。
- すべてのフォームジョブでFlattenを設定し、各プリンタ名をインストール済みのリストと照合します。
- コードが作成するPrintSettingsをテストし、実際のジョブを送信する代わりに実行します。
- 次の変更をクラウドエージェントにイシューとして割り当て、IronPrint APIリファレンスに対してプルリクエストを検証します。
Copilot用のIronPrintの規約をどのように設定しますか?
プロジェクト全体のルールは.github/copilot-instructions.mdに属します。 GitHubのサポートマトリックスには、Visual Studio、VS Code、JetBrains IDEでのCopilot Chatと、Copilot CLI、Copilotコードレビュー、クラウドエージェントでのそのファイルのサポートが示されています。 Visual Studioは、GitHub、Copilot、Copilot Chatのカスタム指示チェックボックスが選択された場合にのみ、そのファイルをCopilot Chatリクエストに追加します。
These rules apply to printing code in this repository:
- Handover forms print through IronPrint. The NuGet package and the namespace are both IronPrint.
- Add no other printing library and no System.Drawing.Printing code.
- Keep the IronPrint version that Directory.Packages.props sets. Only an upgrade task changes it.
- IRONPRINT_LICENSE_KEY holds the license key.
- IronPrint does not read that variable, so Program.cs copies its value into License.LicenseKey.
- Never print the value, and don't dump environment variables either.
- docs/print-profile.md is the print contract. Leave it as it is and suggest changes in your reply.
- https://ironsoftware.com/print/csharp/llms.txt indexes IronPrint's docs for agents.
- No printer on this machine finishes a job without someone answering a dialog.
- Don't send a print job from a session, a test or a dry run.
Printing tests follow these rules:
- Test the PrintSettings the code builds.
- A test never calls Printer.Print or Printer.PrintAsync with a printer name that exists.
最後の印刷ルールはテストマシンから来ています。そこでは、Microsoft Print to PDFがファイル名を求め、Adobe PDFがCreate Adobe PDFウィンドウを開いたので、どちらのプリンタに送信されたジョブも対応者が応答するまで待機します。
印刷コードのルールをどのように設定しますか?
.github/instructions/printing.instructions.mdのapplyToパターンは、その規則をツリーの一部に制限し、今回はソースとテストプロジェクトに適用されます。 GitHubのCLIドキュメントには、CLIがapplyTo値が一致するファイルでの作業に対してのみパス固有のファイルをコンテキストに追加すると述べられています。 私たちの実行では、printing.instructions.mdはプロンプト1でCopilotが開いた最初のファイルでした。
---
applyTo: "src/**,tests/**"
---
Source and test code here follow these IronPrint rules:
- Set Flatten = true for every handover form.
- With Flatten false, IronPrint sends the page with four empty boxes.
- Those boxes are Driver, SealNumber, PalletCount and Hazmat.
- Check a printer name against Printer.GetPrinterNames before a job.
- IronPrint throws nothing for a name it cannot match, even by case or a trailing space.
- It prints on the Windows default printer instead.
- GetPrinterTrays returns an empty list for an unknown name, as it does for some real printers.
- So an empty tray list cannot prove that a printer exists.
- NumberOfCopies reaches the driver as a copy count.
- The job itself holds one page per PDF page.
- With no key, Printer.Print throws an AggregateException that wraps a LicensingException.
- PrintAsync throws the LicensingException itself.
- Margins takes millimeters, in the order left, top, right, bottom.
これらのルールそれぞれはIronPrint 2026.10.1で測定されました。そのうちの最初のものの背後にある測定を示すのが、Flattenとプリンター名セクションです。
フラット化なしでフォームフィールドが空で印刷される理由は?
これらの測定はシミュレートされたプリンタを使用しています。 Windowsでは、IronPrintは各ジョブをWPF印刷ダイアログのPrintDocumentコールを通じて送信します。 そのコールのフックで、各ジョブのページと印刷チケットをXPSファイルに保存し、印刷キューにはジョブが受け渡されませんでした。 4つの引き渡しフォームは、フラット化ガイドの結合例からの設定でそれを通過しました。 結果は、IronPrintがプリンタードライバーに与えるページを説明し、物理プリンタの用紙ではありません。
以下の比較では、すべてのフィールドに値が保存された引き渡しフォームHO-1001を使用します。
Flattenをデフォルトのfalseのままにした場合、ドライバー、シール番号、パレット数、ハザマットボックスはすべてのフォームで空でした。 3つのフォームはフィールドの外観ストリームを持ち、ボックスも空でした。Flatten = trueとすることで、すべての値が印刷されました。 外観ストリームなしで保存されたフォームもその値が印刷されました。- 各PDFページは、ISO A4ポートレートページ上での2479×3508ピクセルの1画像になり、これは300 DPIのA4です。 2ページのフォームは2ページを生成しました。
- 印刷チケットはコピー数を2と保持し、ドキュメントはPDFページごとに1ページ保ちました。
- 例からの10 mmの余白は画像を移動させず、画像はページの左上隅からページを満たしました。
出力
HO-1001は最初にフラット化falseで、次にフラット化trueでフックを2回通過しました。 以下の各PDFは、キャプチャされたジョブのページ画像で、修正されておらず、元のサイズです。
IronPrintがジョブを構築したとき、HO-1001はフラット化falseで、プリンターの代わりにファイルにキャプチャされました。
IronPrintがジョブを構築したとき、HO-1001はフラット化trueで、プリンターの代わりにファイルにキャプチャされました。
フラット化ガイドは、フォームレイヤーをスキップするプリンタードライバーに空白のフィールドを帰属させます。 キャプチャ内で、ドライバーが受け取る前のページですでに値が欠落していました。
ジョブを送信せずにフォルダー内のフォームを印刷するにはどうしますか?
バッチジョブはドライランを必要とし、プリンタなしでテストできます。 ドライランは各フォームが受け取る設定を記録し、レビュー担当者がそのログを印刷プロファイルと比較できます。
Turn @src/Depot.PrintJob/Program.cs into the batch job that prints forms/inbox.
It accepts two options:
- --printer <name> picks the printer for every form.
- --dry-run writes the log and sends nothing.
The job runs in this order:
1. Exit with code 2 when the printer isn't installed, and list the installed ones on the console.
2. Read every PDF in forms/inbox in file name order.
3. Get each form's settings from HandoverPrinter.BuildSettings.
4. Append a line per form to out/print-log.csv, then print the form unless it's a dry run.
Paths are relative to the solution root.
The log is semicolon-delimited, with this header line:
Form;Printer;Flatten;Copies;PaperSize;Orientation;Dpi;Grayscale
Run the job twice with --dry-run.
Use --printer "Adobe PDF" the first time and --printer "Depot Laser 2" the second.
Show me both exit codes and the log.
Adobe PDFはテストマシン上のプリンタです。独自のプリンタリストから名前を使用します。
プリンタ名が一致しない場合はどうなりますか?
IronPrintはWindowsが報告する名前とPrinterNameを文字ごとに比較し、比較が失敗した場合でもエラーを発生させません。 キャプチャされたジョブは「NoSuchPrinter 7」、小文字の「adobe pdf」、および「Adobe PDF」後にスペース付きで宛てられました。 WindowsのデフォルトプリンタであるMicrosoft Print to PDFがすべて受信し、正確な名前のみがAdobe PDFに送信されました。 未知の名前へのライセンス済みジョブは例外を発生させず、Microsoft Print to PDFの「名前を付けて保存」ダイアログが回答されるまでのみ戻りました。
GetPrinterTraysは名前チェックを置き換えられません。未知の名前、Fax、およびMicrosoft Print to PDFでも空のリストを返しました。 GetPrinterNamesはライセンスキーなしで4台のプリンタすべてを返しましたので、テストでも機能します。
印刷設定をテストするにはどうしたらいいですか?
Copilot CLIでShift+Tabを押してプランモードをアクティブにし、次のプロンプトを送信します。
Plan an xUnit project in tests/Depot.Printing.Tests and add it to the solution.
Hold off on code until I approve the plan.
Its tests cover these cases:
- Every setting BuildSettings fills in matches @docs/print-profile.md.
- PaperMargins and Tray stay null, so the printer's own defaults apply.
- PrintAsync refuses a name with the wrong case or a trailing space.
- That refusal names every printer InstalledPrinters() returns.
Once the plan is approved, add the tests and run dotnet test.
Then give me the pass and fail counts.
プランを確認すると、マシンのプリンタリストに依存する前に、スイートが実際のプリンタ名を取得する方法がわかります。
再印刷でフォームフィールドが空になるのをどう修正しますか?
メインサービスから分離された再印刷パスは、メインサービスが適用する設定を省略できます。 このシナリオでは、チームメイトのReprintServiceが独自のPrintSettingsをFlattenなしで構築しており、ドライバーは空のボックスでの再印刷を受け取ります。
Drivers say reprinted handover forms have empty Driver, Seal number and Pallet count boxes.
First prints look right. The reprint code is @src/Depot.Printing/ReprintService.cs.
Work out the cause before you edit anything:
1. Compare ReprintService.BuildSettings with HandoverPrinter.BuildSettings.
2. Open IronPrint.xml inside the IronPrint package in the NuGet cache.
3. Quote its summary for the setting that explains the empty boxes.
Then fix ReprintService.cs, and keep a reprint at one copy.
Leave the other source files alone.
Add a test for the reprint settings and run dotnet test.
Tell me the cause you found and the test result.
出荷されるIronPrint.xmlは、設定を症状に一文で接続し、フォームフィールド値を表示するのに役立つFlattenと説明しています。 それがないと値が欠落することを示していません。
クラウドエージェントが行動できる問題を作成するにはどうすれば良いですか?
Copilotは、イシューが割り当てられたときにイシュースのタイトル、説明、既存のコメントを受け取り、オプションのプロンプトフィールドのテキストも受け取ります。 GitHubのドキュメントでは、エージェントは割り当て後に投稿されたコメントに気づいていないと述べているため、完了を述べる必要があります。
Title: Log the printer each reprint was sent to
The work involves these files and settings:
- Files: src/Depot.Printing/ReprintService.cs, tests/Depot.Printing.Tests
- IronPrint version: unchanged from Directory.Packages.props
- Framework: net9.0-windows
After the change, reprints behave like this:
- Every reprint appends a line to out/reprint-log.csv.
- The line holds the form, the printer name, the time and the copy count.
- A printer name that Windows does not report stops the reprint before anything is sent.
Today, reprints leave no record, and ReprintAsync sends a job to any name it receives.
Keep to these limits:
- Keep the ReprintAsync signature.
- Follow .github/instructions/printing.instructions.md.
- Add no packages.
Acceptance means these checks pass:
- Every existing test passes.
- A new test passes "adobe pdf" in lower case and expects an ArgumentException before any job.
テストはインストールされたプリンタと大文字のみで異なる名前を使用しているため、大文字を無視するチェックでは失敗します。
クラウドエージェントのテストがIronPrintプロジェクトで失敗するのはなぜですか?
リポジトリが別のランナーを構成しない限り、エージェントの環境はUbuntu Linuxです。 IronPrintの商品ページはWindows、macOS、iOS、Androidを指定し、Linuxを指定しておらず、このソリューションのすべてのプロジェクトはnet9.0-windowsをターゲットにしています。 GitHubはクラウドエージェントのためのWindows 64ビットランナーをサポートします。 統合ファイアウォールはWindowsと互換性がないため、その場合にはGitHubはセルフホスティッドランナーまたはAzureプライベートネットワーキングを備えたより大きなGitHubホステッドランナーを推奨します。
エージェントのシークレットなしでは、その環境にはライセンスキーもありません。 プローブでは、すべての無許可の印刷コールが0.2秒以内に「本番ライセンスが必要」と吐出し、ジョブが作成される前に発生しました。
.github/workflows/copilot-setup-steps.yml内のcopilot-setup-stepsジョブは、エージェントが作業を開始する前に実行され、GitHubはデフォルトブランチにファイルが含まれた後にのみそれをトリガーします。
The cloud agent has to build this solution, so add a setup workflow for it.
Its path is .github/workflows/copilot-setup-steps.yml.
Copilot looks for one job, and it has to be named copilot-setup-steps.
The job works like this:
- Run it on windows-latest, because every project targets net9.0-windows.
- Its only permission is contents: read.
- Start it from workflow_dispatch and from pull requests that edit this workflow file.
- Its steps are a checkout, a .NET 9 SDK install, a restore and a Release build.
Printing calls need IRONPRINT_LICENSE_KEY, which is stored as an Agents secret.
The job sees that secret as an environment variable.
Add a step that tests whether the key is set:
- For pull_request and workflow_dispatch events, a missing key is a warning and the step passes.
- For every other event, a missing key fails the step with a message that names the secret.
That step goes last, since Copilot skips every setup step after one that fails.
Create the file and show me the YAML.
キーのためにエージェントのシークレットを使用します:クラウドエージェントは、Actions、Codespaces、Dependabotシークレットを読み取ることができません。 Secrets and variablesのエージェントページにIRONPRINT_LICENSE_KEYを追加します。リポジトリの設定のセキュリティグループに見つかります。 その後、エージェントは環境変数としてキーを取得します。
マージする前に何を確認すべきですか?
レビューを独自のcopilot -pコマンドとして送信します。 --continueまたは--resumeがない場合、そのコマンドはコーディングセッションの履歴がない新しいセッションを開始します。
/review the changes made since this branch's first commit.
Compare each IronPrint call with .github/instructions/printing.instructions.md.
Then compare it with the IronPrint.xml that ships in the IronPrint NuGet package.
Name every place where the code and those two sources disagree.
Flag any of these as well:
- a PrintSettings for a handover form that leaves Flatten unset or false
- a print call whose printer name was never checked against Printer.GetPrinterNames
- a test that sends a real print job
- a catch block that would miss the LicensingException a print call throws
- any line that writes IRONPRINT_LICENSE_KEY to the console or a log
Report what you find and leave every file unchanged.
プロンプトが実運用で生成したものは何ですか?
6つのプロンプトはCopilot CLIで次々に実行されるようにスケジュールされ、誰もキーボードにいません。このガイド用に構築されたデポソリューションであり、各プロンプト後にコミットが再構築され、バッチジョブが上で実行されました。 その後、各フォームの設定は印刷コールが傍受されながらIronPrintを通過し、ジョブはプリンタに達しませんでした。
- 実行の前に、HandoverPrinterは空の静的クラスであり、バッチジョブはコード1で終了したスタブでした。
- 最初のプロンプトはHandoverPrinter.csのみを変更しました。
- 最初のプロンプトの後、BuildSettingsはFlattenがオン、コピー数が2、A4、縦向き、300 DPI、グレースケールを返しました。
- トレイとマージンは未設定のままで、プリンタデフォルトが適用されました。
- PrintAsyncは大文字を区別する序数比較でプリンタ名をチェックしました。
- すべてのフィールド値が4つのフォームのキャプチャされたページに表示されました。
- 各フォームの印刷チケットには2部、ISO A4縦向き、モノクロ出力、300 DPIが含まれていました。
- 2ページのフォームにキャプチャされたジョブは2ページを保持し、他のジョブは各々1ページを保持しました。
- 2つのプロンプトの後、解決は0エラーで構築されました。
- 2番目のプロンプトの後、Adobe PDFのドライランはコード0で終了し、フォームごとに1行をログしました。
- 各ログ行は印刷プロファイルと一致し、FlattenとGrayscaleの両方がTrueでした。
- Depot Laser 2のドライランはコード2で終了し、そのコンソール出力は4台のインストールされたプリンターを命名しました。
- どちらのドライランも印刷コールを行いませんでした。
- 実行中に印刷ジョブがキュー内に表示されませんでした。
- 一部のステップはページと異なる方法で実行されました。 毎月のCopilotクォータが2回目のプロンプトで無くなりました。Copilotがジョブを構築し、その仮想実行の前にです。 代わりにどちらの仮想実行もCopilotの外部で実行されました。 プロンプト3から6は実行されませんでしたので、プランモード、再印刷修正、セットアップワークフロー、レビューにはこのページに実行結果はありません。 エージェント、クラウドエージェント、およびエージェントのシークレットはホストされたリポジトリーを必要とし、いずれもテストされませんでした。
カーソルはまたそのルールをファイルパターンに範囲を限定し、クロードコードもまた、コードの変更をする前に承認されたプランを待ちます。 共有実行記録はCLIバージョン、自動によって選択されたモデル、総実行時間、およびハードウェアを保持します。
トラブルシューティング
- 印刷前にPDFをフラット化する方法 印刷される空のフォームフィールド用
- プリンタ名の取得方法 Windowsが報告する名前のために
- ジョブが誤ったプリンタに到達する場合のプリンタ名の指定方法
- WPFとWinFormsでのPrint()メソッドがインターフェイスをフリーズする場合
- すべてのキーが設定される場所にライセンスキーを適用する方法
質問ありますか?
質問がある場合は、support@ironsoftware.com にお問い合わせください。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。