Google AntigravityとIronPrintの使い方
ホテルのフロントデスクでは、到着したゲストがカウンターで署名するための登録カードを印刷します。 係の者がブラウザでPrintをクリックすると、ジョブはWebサーバーから送られ、間違ったプリンターや用紙サイズで送られても成功メッセージが返されます。 これらの問題はビルドログには表示されません。
Google Antigravityは係の者と同じようにページを確認できます。 その /browser コマンドは サンドボックス化されたChromeサブエージェント を開始し、各Printボタンをクリックして結果のスクリーンショットを撮ることができます。 IronPrintはサーバーからプリンターにPrinter.PrintAsyncでカードPDFを送ります。このアプローチはIronPrintのASP.NET Webアプリケーションガイドで説明されています。 以下のステップでは、両方のツールを使用してページを構築し、既知の結果を持つ6回の到着に対してテストします。
対象者は、AIエージェントがWebサーバーから印刷するコードを作成する.NET開発者です。 プリンターのハードウェアの選択と印刷キューの設定は対象外です。
クイックスタートAntigravityでFrontDeskプロジェクトを開き、到着ページを説明します。
/plan Add an /Arrivals page to the FrontDesk .NET 9 MVC site.
Each row's Print registration card button prints that card from the server with IronPrint.
Set up the project first:
- Add the IronPrint package, version 2026.10.1. Its namespace is IronPrint.
- Target net9.0-windows.
The page works like this:
- It lists today's guests from App_Data/arrivals.csv.
- Each card is App_Data/cards/<ReservationId>.pdf.
- The Print action awaits Printer.PrintAsync, never Wait or Result.
- Cards print on A5, two copies, grayscale, with PaperOrientation.Automatic.
- Check the printer name in Printing:PrinterName against Printer.GetPrinterNames before any job.
- Refuse a missing card, or a file that doesn't start with %PDF-, before IronPrint opens it.
- Each click shows its outcome on the page.
- Add the page to the nav bar.
Every printer here opens a Save As dialog. Send no real job.
With Printing:DryRunFolder set, write each job to a JSON file there.
The file holds the reservation, card path, printer and every setting.
appsettings.Development.json already sets the folder.
At startup, set IronPrint.License.LicenseKey once from IRONPRINT_LICENSE_KEY.
The app reads the variable itself, so you never need the value.
Check only that it's set and its length.
Don't print, log or save the key, or list the environment variables.
Answer three questions in the Implementation Plan:
- What does IronPrint do with a printer name it can't find?
- How does the name check compare names?
- What does the page show when IronPrint throws?
Stop when dotnet build reports zero errors.
成功したビルドは3つの回答をテストしないので、承認する前に各計画を確認してください。
IronPrintはIRONPRINT_LICENSE_KEYを読み取りません。 我々のテストでは変数が設定され、License.IsLicensedはコードがLicense.LicenseKeyに割り当てるまでfalseのままでした。 他のオプションについてはライセンスキーガイドで説明されています。例えばappsettings.jsonやWeb.configです。
最小限のワークフロー(5ステップ)
- NuGetからC#印刷ライブラリをダウンロードする
- net9.0-windowsのASP.NET Coreプロジェクトを作成します
- 毎回のジョブの前に、構成されたプリンター名とインストールされたプリンターを照合します
- /browserに各Printボタンをクリックさせ、印刷をドライランとして実行します
- 記録された各ジョブを期待リストと比較し、各IronPrintメンバーをAPIリファレンスと照合します
Google Antigravityとは何か、そしてチャットアシスタントとはどう違うのか?
Googleの概要では、デスクトップ用Antigravityアプリは、開発者が自律エージェントチームを立ち上げ、調整し、検査する単独のプログラムです。 チャットアシスタントがテキストで答える場合、Antigravityのエージェントはアーティファクト、例えば実現計画、ウォークスルー、スクリーンショットを生成します。
記憶からパッケージの名前を付けるエージェントは、攻撃者によって公開された似たもののインストールが可能で、これをスロップスクワッティングと呼びます。 IronPrint パッケージ名とバージョンを依存関係を追加するプロンプトに指定してください。 エージェント用のIronPrintのドキュメントファイルはAIコーディングアシスタントガイドにリストされており、ワンプロンプト受け入れテストもあります。
計画、コード変更、ウォークスルーで何を確認すべきですか?
IronPrintが未知のプリンター名を拒否すると予想した計画は、名前チェックの存在理由を見落としています。 コード変更では、プリンター名比較を見つけ、各IronPrintメンバーをAPIリファレンスで確認します。
スクリーンショットは、各クリックにつき一枚期待してくださいるウォークスルーです。 デスクトップアプリはスクリーンショットをすべて画像アーティファクトとして保存し、コメントが可能です。 誤ったメッセージのスクリーンショットにコメントを付けると、エージェントはどの行が失敗したかを知ることができ、新しいプロンプトは不要です。
実際のブラウザーで印刷ボタンをテストする方法は?
/browserプロンプトは、すべてのボタンをクリックすることでのみ埋めることができるテーブルを要求します。
/browser Start the site in the background with dotnet run and go to /Arrivals.
The http profile serves it on http://localhost:5318.
Click Print registration card on every row, top to bottom:
1. Click the button.
2. Wait for the outcome message.
3. Take a screenshot.
TestData/expected-jobs.csv says what each click should produce.
A row marked job should leave one new JSON file in print-jobs.
A row marked refused should leave no file, and the page should say why.
Sum up the clicks in a Walkthrough table with these columns:
- reservation
- expected outcome
- message on the page
- job file written
- paper size, orientation, copies and grayscale from that file
- pass or fail
Before you touch the code, find the log line or exception behind each failed row.
Write it under the table, or say nothing was logged.
Fix the cause, restart the site and click every row again.
Stop that dotnet process by its PID at the end.
6つの到着のうち、2つはシングルページのA5カードで、3番目はハウスルールの2ページ目を持っています。 グループ予約はA4横長のカード、一つの予約はカードなし、カードファイルの一つには失敗したエクスポートのテキストが含まれており、PDFではありません。
/Arrivalsページでは、予約1047のクリックの後、エージェントの最終ウォークスルーで7枚のスクリーンショットの一つです。
印刷要求はどのプリンタに到達しますか?
IronPrint 2026.10.1はプリンタ名を検証しません。 知らない名前、adobe pdfを小文字で書かれたもの、名前なしのジョブを作成しました。 IronPrintはすべてを例外なしにWindowsの既定のプリンタに向けました。 PrintSettings.PrinterNameに任意の文字列を割り当てても成功します。 設定ミスの読み間違いによりカードがサーバーの既定のプリンタに印字されます。
テスト機では既定のプリンタがMicrosoft Print to PDFで、ファイル名を保存するダイアログで求められます。 ASP.NETガイドの高度な例も同じプリンタにジョブを送ります。 Webサーバー上のユーザーがダイアログに応答せず、プローブ内で人がファイル名を入力した後のみジョブがそのプリンタで終了しました。
各ジョブの前に構成名をPrinter.GetPrinterNamesと比較することで、両方の結果を防ぎます。 比較は序数で行う必要があり、IronPrintはキュー名を正確に大文字小文字も含めて一致させます。
Antigravityで作業できるプロジェクトをどのように設定するのか?
エージェントに既にコンパイルしてページを提供するリポジトリを与えます。 dotnet new mvc -f net9.0がFrontDeskプロジェクトを生成し、最初のプロンプトの前に1回クリーンビルドされました。 Properties/launchSettings.jsonのhttp起動プロファイルはポート5318をリッスンし、/browserプロンプトが開きます。
対象:net9.0-windows プレーンnet9.0用に構築されたコンソールプローブは警告なしでコンパイルされましたが、Adobe PDFプリンターの「Automatically Select」を「AutoSelect」に変えたり、欠落ファイルにPlatformNotSupportedExceptionを挙げたりしました。
Which IronPrint version does FrontDesk.csproj reference? Quote the PackageReference line.
Then tell me where the code applies the key.
Read the code for this, and don't start the app.
Check the project against these rules for the key:
- It reaches the app only through IRONPRINT_LICENSE_KEY at startup.
- No appsettings file has an IronPrint.LicenseKey entry.
- Properties/launchSettings.json holds no key.
- With the variable missing, startup writes a single warning naming the variable, with no value.
Change Program.cs only if that warning isn't there.
Don't edit anything else.
ライセンスキーなしで、IronPrint 2026.10.1は4台のインストールされたプリンターとそのトレイをリストしました。 ファイルを読み取る前にPrinter.PrintAsyncがLicensingException「Production License Required」を投げたため、印刷キューはジョブを受け取りませんでした。 テストページの最初の未ライセンスのクリックは998ミリ秒でそのメッセージを返し、その後のクリックは19〜30ミリ秒で返しました。 例外タイプは公開されておらず、catch (LicensingException)はエラーCS0122でコンパイルに失敗します。
ページのルールを後続のタスクにどのように適用しますか?
すべての行が合格したら、セッションの決定をルールとして保存します。 Antigravityのルール文書では、エージェントがファイルから読み取ったり編集したりしたファイルまで、ワークスペースのルートに向かうパスにある各フォルダーのAGENTS.mdまたはGEMINI.mdファイルを読み込みます。 /learnはセッションで行った訂正からルールとスキルを提案し、承認後にのみファイルを書きます。
/learn Write the decisions of this session to a new AGENTS.md in the repository root.
Use the heading "Front desk printing" and cover:
- the target framework IronPrint needs here
- how the printer name is checked, and why
- the settings every registration card prints with
- the dry-run folder, and that no real job goes out from this machine
- where IRONPRINT_LICENSE_KEY comes from, and that it never goes into a file
- that a change is finished only when every row of TestData/expected-jobs.csv passes in /browser
Tell me the rules before you save them.
印刷ジョブをページからキューするにはどうしますか?
ASP.NETガイドは大量印刷のためのキューを推奨します。
/plan Show me the Implementation Plan Artifact and wait for my go-ahead before editing.
Move the printing code out of the controller into Services/CardPrinter.cs.
Register it with dependency injection.
Here's how CardPrinter behaves:
- BuildSettings returns the PrintSettings for a card, so tests can read them without printing.
- A printer name passes only on an exact match with Printer.GetPrinterNames, case included.
- A missing card, a non-PDF file or an unknown printer comes back as a refusal with a reason.
- IronPrint's LicensingException isn't public, so match it by type name.
- That exception becomes a message saying the key is missing.
- With Printing:DryRunFolder set, it still writes the JSON job file and sends nothing.
Then add a Print all cards button to /Arrivals.
The new button works this way:
- It puts one job per arrival on a Channel that a BackgroundService reads.
- Jobs run one at a time.
- The request returns straight away.
- The page lists each job as queued, done or refused.
Finish with the /browser table again, then click Print all cards and add its rows.
Wait until no job shows as queued before that last screenshot.
プロンプトはIronPrint 2026.10.1に対してコンパイルされるこの例に近いサービスを求めます。
using IronPrint;
public sealed record PrintOutcome(bool Printed, string Message);
public sealed class CardPrinter(IConfiguration config, IWebHostEnvironment env)
{
public static PrintSettings BuildSettings(string printerName) => new()
{
PrinterName = printerName,
PaperSize = PaperSize.A5,
PaperOrientation = PaperOrientation.Automatic,
NumberOfCopies = 2,
Grayscale = true,
};
public async Task<PrintOutcome> PrintCardAsync(string reservationId)
{
string card = Path.Combine(env.ContentRootPath, "App_Data", "cards", reservationId + ".pdf");
if (!File.Exists(card))
return new(false, $"No registration card for reservation {reservationId}.");
var header = new byte[5];
using (var stream = File.OpenRead(card))
stream.ReadExactly(header);
if (System.Text.Encoding.ASCII.GetString(header) != "%PDF-")
return new(false, $"Card {reservationId} is not a PDF.");
// IronPrint sends a job for an unknown name to the Windows default printer, so match the name here.
string printer = config["Printing:PrinterName"] ?? "";
List<string> installed = await Printer.GetPrinterNamesAsync();
if (!installed.Contains(printer, StringComparer.Ordinal))
return new(false, $"Printer '{printer}' is not installed on this server.");
try
{
await Printer.PrintAsync(card, BuildSettings(printer));
return new(true, $"Card {reservationId} sent to {printer}.");
}
catch (Exception ex) when (ex.GetType().Name == "LicensingException")
{
return new(false, "IronPrint has no license key. Set IRONPRINT_LICENSE_KEY on the server.");
}
}
}
例はドライランの分岐を省略しています。 見出しチェックをせずにIronPrintに渡すと、1047の予約カードは「Unsupported file type」によるInvalidDataExceptionを引き起こしました。
デスクプリンタは各カードに何を受け取りますか?
テスト機の4台のプリンタのいずれも無監視でジョブを完了しませんでした。 したがって、記録された各ジョブはIronPrintの内部ジョブビルダーで再構築され、そのページと印刷チケットはキューに送られるのではなくXPSファイルに書き込まれました。
| 予約 | カードファイル | ジョブ内のページ | プリンタに送られたページ |
|---|---|---|---|
| 1042 | A5縦、1ページ | 1 | A5縦、148 x 210 mm |
| 1043 | A5縦、2枚 | 2 | A5縦、148 x 210 mm |
| 1044 | A4横、1ページ | 1 | A5横、210 x 148 mm |
| 1045 | None | 0 | ページに拒否されました |
| 1046 | A5縦、1ページ | 1 | A5縦、148 x 210 mm |
| 1047 | テキスト、PDFではない | 0 | ページに拒否されました |
PaperOrientation.Automaticはグループカードを横長のA5ページにし、フィットするようにスケーリングしました。 PaperOrientation.Portraitを使うと、同じカードが縦のページ幅に縮小され、シートの107.9 mmが空白になりました。 既定のPaperSize.PrinterDefaultを使うと、A5カードがプリンタの既定のA4ページに大きくされました。
NumberOfCopiesは印刷チケットの要求であり、ジョブは各ページを1回含みます。 GrayscaleはPDFページをグレーでレンダリングし、チケットの色をモノクロに設定しました。 300から150にDpiを下げると、1枚のカードのためのシミュレーションジョブのサイズが170,257バイトから74,526バイトになりました。
1042と1043の予約のための入力カードはApp_Data/cardsから来ています。
出力
以下の2つのPDFは、最終アプリケーションでのそのカードのシミュレーションジョブからのページ画像を含み、無変更で各印刷チケットのページサイズで提供されます。
IronPrintがジョブを構築した登録カード1042で、プリンタの代わりにファイルにキャプチャされた300 DPIでA5縦の1ページです。
IronPrintがジョブを構築した登録カード1043で、プリンタの代わりにファイルにキャプチャされた300 DPIでA5縦の2ページです。
複数のエージェントを派遣するのはいつですか?
ブラウザーが不要なチェックのために2番目のエージェントを追加します。 ここで1つのエージェントがコード内の設定をテストし、もう1つは係のクリックを繰り返します。
Agent A: create an xUnit project called FrontDesk.Tests on net9.0-windows, like the web project.
Its tests cover CardPrinter and never send a job:
1. For each job row in TestData/expected-jobs.csv, check the settings BuildSettings returns.
2. Check that reservations 1045 and 1047 are refused, and why.
3. Check that "adobe pdf" in lower case is refused as a printer name.
FrontDesk.csproj is in the repository root, so exclude FrontDesk.Tests from its compile items.
Run them with dotnet test FrontDesk.Tests.
Agent B: wait for Agent A's tests to pass on the current code.
Then use /browser to click every Print button and Print all cards.
Add one screenshot per click to the Walkthrough, and mention there that the tests ran first.
IISにページを展開する方法は?
IronPrintのNuGetページにはLinuxサポートは記載されておらず、Windows、macOS、iOSおよびAndroidのみですが、フロントデスクサーバーはWindowsを動作させます。 ASP.NETガイドはアプリケーションプールアイデンティティがプリンタにアクセスする必要があると追加しています。
This app will run under IIS on a Windows Server 2022 machine at the front desk.
Leave the C# alone.
IIS isn't installed here, so publish only.
Do these in order:
1. Run dotnet publish -c Release -r win-x64 --self-contained false -o out/iis.
2. List every native DLL in out/iis with the NuGet package that brought it in.
3. Confirm that web.config in out/iis carries no license key.
Then tell me where IIS should set IRONPRINT_LICENSE_KEY for this app.
公開フォルダにはサーバーが受け取るものが保存されており、そのチェックにはIISは不要です。 校正アプリのwin-x64公開は40 MBで235ファイルを保持していました。 唯一のネイティブライブラリはIronPrintInterop.dll(9,926,400バイト)とqpdf.dll(2,802,432バイト)で、どちらもIronPrintパッケージからです。 生成されたweb.configにはライセンスキーが含まれていませんでした。 IIS 10はアプリケーションプールの環境変数を通じてワーカープロセスにキーを渡すことができます。 プロジェクトフォルダからの公開により、print-jobsからのドライランジョブファイルも出力にコピーされました。
プロンプトが実運用で生成したものは何ですか?
7つのプロンプトすべてが監視なしに1つのAntigravity CLIの会話で実行され、すべての許可プロンプトが省略されました。 ライセンスキーの唯一のソースはIRONPRINT_LICENSE_KEYでした。 すべてのブラウザーパスがドライランとして実行され、印刷キューは空のままでした。 すべての行が最初のプロンプトの後と最終アプリケーションで独立してクリックされました。
- 最初のプロンプトの前に、プロジェクトはnet9.0を対象とし、NuGetパッケージを参照していませんでした。
- 最初のプロンプトの後、それはnet9.0-windowsを対象にし、IronPrint 2026.10.1を参照しました。
- 実現計画は、IronPrintが未知のプリンタ名のジョブをデフォルトのプリンタに送信することを測定しました。
- 最初のプロンプトのコードでは、Printer.PrintAsyncをAwaitし、WaitやResult呼び出しがありませんでした。
- ページは1045と1047の予約を拒否し、両方のチェックで他の4つのジョブを記録しました。
- 記録された各ジョブはA5紙、2部、グレースケール、自動向きを要求しました。
- 4つのシミュレーションジョブは5枚のA5ページを持ち、グループカードのページは横向きでした。
- すべてのカードを印刷し、4つのジョブが完了し、2つが拒否され、2秒以内に6つの到着を完了しました。
- すべてのプロンプトがエラー0のビルドを残しました。
- 最終アプリケーションは警告0でリリースビルドされました。
- キーなしで開始された最終アプリケーションは、IRONPRINT_LICENSE_KEY名を1つの警告としてロギングしました。
- すべてのxUnitテストがライセンスキーなしで合格しました。
- 実行のwin-x64公開は同じ2つのネイティブライブラリとキーのないweb.configを持ちました。
- 一部のステップはページと異なる方法で実行されました。 Antigravityの/browserサブエージェントがChromeに接続に失敗したため、エージェントは各ブラウザーパスで独自のPuppeteerスクリプトを通じてChromeを制御しました。 計画最初のプロンプトは計画後の承認を待ちました。 /learnはアーティファクトの6つのポイントを提案し、AGENTS.mdを書きませんでした。 2エージェントプロンプトでは、メインの会話がエージェントAのテストを実行し、エージェントBサブエージェントが失敗した後、自身で行をクリックしました。 エージェントはリポジトリのルートにChromeログ、クッキーファイルおよびスクリーンショットを残しました。
ChatGPT Codexはその作業をエクスプローラーとワーカーサブエージェントの間で分割します。 GitHub Copilotでは、バッチジョブも各フォームの設定をログし、印刷呼び出しをしないドライランがあります。 Antigravityのバージョン、モデル、実行時間、テスト機は実行記録で共有されています。
トラブルシューティング
- ASP.NET Webアプリケーションでの印刷はこのページが従うコントローラパターン
- プリンタ名の取得方法では、ジョブが間違ったプリンタに届く場合
- 印刷設定は用紙サイズ、向き、コピー数、DPIのため
- Web.configでのライセンスキーの設定は、サーバーでキーが適用されない場合
- Print()メソッドがWPFとWinFormsでハングする場合は、印刷呼び出しがスレッドをブロックする際
質問ありますか?
質問がある場合は、support@ironsoftware.com にお問い合わせください。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。