印刷チケットの追加と操作

C++ 経由で XPS ファイルの作成、編集、リンク、印刷チケットの取得を行う

 

XPS ファイルのコンテキストでは、プリント チケットはドキュメントの印刷方法を指定する一連の指示です。これは基本的に、次の情報が含まれる構成ファイルです。

  • 印刷されるページの寸法と方向。
  • 用紙トレイまたはフィーダーを使用します。
  • 印刷出力の解像度と色深度。
  • 用紙の両面に印刷するかどうか。
  • ページを印刷して丁合いする順序。
  • ステープル留め、綴じ、パンチ穴などの追加の仕上げオプション。

印刷チケットを理解して活用することで、印刷プロセスを最適化し、XPS ドキュメントに必要な出力を実現できます。

さまざまな機能の中でも Aspose.Page API ソリューションを使用すると、印刷チケットを操作できます。ここでは、それらを作成、編集、取得、リンクする方法を説明する情報が見つかります。 XPS ファイルの印刷チケットを操作するには、以下が必要です。

-

Aspose.Page for C++ API は、機能が豊富で強力で使いやすいドキュメントの操作と変換です。

-

NuGet パッケージ マネージャーを開き、Aspose.Page を検索してインストールします。パッケージ マネージャー コンソールから次のコマンドを使用することもできます。

Package Manager Console Command

    PM> Install-Package Aspose.Page

カスタム印刷チケット C++ を作成する手順。

  1. ドキュメントディレクトリへのパスを設定します。
  2. XpsDocument クラス を使用して XPS ファイルを作成します。
  3. JobPrintTicket コンストラクターを使用して、カスタム ジョブの印刷チケットを追加します。
  4. カスタム ページ パラメーター初期化子とカスタム ページ解決オプションをチケットに追加します。
  5. XPsDocument.Save() メソッドを使用して、変更された XPS ドキュメントを保存します。
カスタム印刷チケットを作成する
// The path to the documents directory.
System::String dir = RunExamples::GetDataDir_WorkingWithPrintTickets();
// Create new XPS document
{
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>();
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ document});
// ------------------------------------------
try
{
// Set a custom job-level print ticket
document->set_JobPrintTicket(System::MakeObject<JobPrintTicket>(
System::MakeArray<System::SharedPtr<IJobPrintTicketItem>>({
// Specify input bin.
System::MakeObject<JobInputBin>(System::MakeArray<System::SharedPtr<InputBin::IInputBinItem>>({InputBin::InputBinOption::Manual->Clone()->Add(System::MakeArray<System::SharedPtr<InputBin::IInputBinOptionItem>>(
{InputBin::FeedFace::FaceDown, InputBin::FeedDirection::LongEdgeFirst, System::MakeObject<InputBin::MediaSheetCapacity>(100)}))})),
// Specify output bin.
System::MakeObject<JobOutputBin>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinItem>>({
System::MakeObject<OutputBin::OutputBinOption>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinOptionItem>>(
{OutputBin::BinType::Sorter})),
System::MakeObject<OutputBin::OutputBinOption>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinOptionItem>>(
{OutputBin::BinType::Stacker, System::MakeObject<OutputBin::MediaSheetCapacity>(100)}))})),
// Specify page orientation.
System::MakeObject<PageOrientation>(System::MakeArray<System::SharedPtr<PageOrientation::PageOrientationOption>>(
{PageOrientation::PageOrientationOption::Landscape})),
// Specify duplex mode for the output.
System::MakeObject<JobDuplexAllDocumentsContiguously>(System::MakeArray<System::SharedPtr<Duplex::DuplexOption>>(
{Duplex::DuplexOption::TwoSidedLongEdge(Duplex::DuplexMode::Automatic)})),
// Specify the color settings for the output.
System::MakeObject<PageOutputColor>(System::MakeArray<System::SharedPtr<PageOutputColor::IPageOutputColorItem>>(
{PageOutputColor::PageOutputColorOption::Grayscale(0, 8)}))})));
// Save the document with the custom job-level print ticket.
document->Save(dir + u"output1.xps");
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}

C++ 経由で XPS 印刷チケットを編集する手順。

  1. ドキュメントディレクトリへのパスを設定します。
  2. XpsDocument クラス を使用して、印刷チケットで XPS ドキュメントを開きます。
  3. チケットから不要なパラメータを削除するには、 Remove() メソッドを使用します。
  4. XPsDocument.Save() メソッドを使用して、変更されたジョブ印刷チケットを含むドキュメントを保存します。
印刷チケットを編集する
// The path to the documents directory.
System::String dir = RunExamples::GetDataDir_WorkingWithPrintTickets();
// Open XPS Document with print tickets
System::SharedPtr<XpsDocument> xDocs = System::MakeObject<XpsDocument>(dir + u"input3.xps");
System::SharedPtr<JobPrintTicket> pt = xDocs->get_JobPrintTicket();
// Remove some parameters from job print ticket
pt->Remove(System::MakeArray<System::String>({u"ns0000:PageDevmodeSnapshot", u"ns0000:JobInterleaving", u"ns0000:JobImageType"}));
// Add some parameters to job print ticket
pt->Add(System::MakeArray<System::SharedPtr<IJobPrintTicketItem>>({System::MakeObject<JobCopiesAllDocuments>(2),
System::MakeObject<PageMediaSize>(System::MakeArray<System::SharedPtr<PageMediaSize::IPageMediaSizeItem>>({PageMediaSize::PageMediaSizeOption::ISOA4}))}));
// Save the document with changed job print ticket.
xDocs->Save(dir + u"output3.xps");

C++ 経由で印刷チケットを取得する手順。

  1. ドキュメントディレクトリへのパスを設定します。
  2. XpsDocument クラス を使用して、印刷チケットで XPS ドキュメントを開きます。
  3. JobPrintTicket コンストラクターを使用してジョブ プリント チケットを作成します。
  4. GetDocumentPrintTicket() メソッドを使用してドキュメント印刷チケットを作成します。
  5. GetPagePrintTicket() メソッドを使用してページ印刷チケットを取得します。
  6. XPsDocument.Save() メソッドを使用して、変更されたジョブ印刷チケットを含むドキュメントを保存します。
プリントチケットを入手する
// The path to the documents directory.
System::String dir = RunExamples::GetDataDir_WorkingWithPrintTickets();
// Open XPS Document without print tickets
System::SharedPtr<XpsDocument> xDocs = System::MakeObject<XpsDocument>(dir + u"input1.xps");
// Get job print ticket
System::SharedPtr<JobPrintTicket> jobPrintTicket = xDocs->get_JobPrintTicket();
// must be null for this document
// Get document print ticket
System::SharedPtr<DocumentPrintTicket> docPrintTicket = xDocs->GetDocumentPrintTicket(1);
// must be null for this document
// Get page print ticket
System::SharedPtr<PagePrintTicket> pagePrintTicket = xDocs->GetPagePrintTicket(1, 1);
// must be null for this document
// Save the document. Default print tickets are automatically added to document while saving.
xDocs->Save(dir + u"output1.xps");
// Open saved earlier XPS Document with print tickets
System::SharedPtr<XpsDocument> xDocs2 = System::MakeObject<XpsDocument>(dir + u"output1.xps");
// Print tickets must not be null
System::Console::WriteLine(xDocs2->get_JobPrintTicket());
System::Console::WriteLine(xDocs2->GetDocumentPrintTicket(1));
System::Console::WriteLine(xDocs2->GetPagePrintTicket(1, 1));

C++ 経由で XPS ファイルの印刷チケットをリンクする手順。

  1. ドキュメントディレクトリへのパスを設定します。
  2. 新しい XPS ファイルを作成し、XpsDocument クラス を使用して印刷チケットのある XPS ドキュメントを開きます。
  3. XpsDocument クラス を使用して、印刷チケットを持つ XPS ドキュメントを開きます
  4. ジョブ印刷チケットを JobPrintTicket コンストラクターにリンクします。
  5. GetDocumentPrintTicket() メソッドと SetDocumentPrintTicket() メソッドを使用してドキュメント印刷チケットをリンクします。
  6. GetPagePrintTicket() メソッドと SetPagePrintTicket() メソッドを使用して、ページ印刷チケットをリンクします。
  7. XPsDocument.Save() メソッドを使用して、変更されたジョブ プリント チケットを含むドキュメントを保存します。
印刷チケットをリンクする
// The path to the documents directory.
System::String dir = RunExamples::GetDataDir_WorkingWithPrintTickets();
// Create new XPS document
System::SharedPtr<XpsDocument> xDocs1 = System::MakeObject<XpsDocument>();
// Open XPS Document with print tickets
System::SharedPtr<XpsDocument> xDocs2 = System::MakeObject<XpsDocument>(dir + u"input2.xps");
// Link job print ticket
xDocs1->set_JobPrintTicket(xDocs2->get_JobPrintTicket());
// Link document print ticket
xDocs1->SetDocumentPrintTicket(1, xDocs2->GetDocumentPrintTicket(2));
// Link page print ticket
xDocs1->SetPagePrintTicket(1, 1, xDocs2->GetPagePrintTicket(3, 2));
// Save the document with linked print tickets.
xDocs1->Save(dir + u"output1.xps");

XPS XPS ファイル形式とは

XPS 形式は PDF 形式に似ています。どちらもページ記述言語 (PDL) 形式です。 EPS は PostScript 言語ではなく、HTML に基づいています。 .eps ファイルには、ドキュメントの構造のマークアップと、ドキュメントがどのように見えるかに関する情報を含めることができます。また、ドキュメントを印刷およびレンダリングする方法についての説明も追加されています。この形式の特徴は、ドキュメントの説明を修正することです。つまり、誰が、どのオペレーティング システムからドキュメントを開いたとしても、同じように表示されます。