Tambahkan dan manipulasi tiket cetak

Buat, edit, tautkan, dan dapatkan tiket cetak file XPS melalui C#

 

Semua format Bahasa Deskripsi Halaman mendukung pencetakan. Beberapa di antaranya, seperti PDF, mendukung pencetakan berkualitas tinggi dengan berbagai ruang warna dan lingkungan yang tidak bergantung pada resolusi. Karena XPS dimaksudkan untuk dicetak pada printer kantor biasa, XPS mendukung lebih sedikit ruang warna dan hanya 2 jenis font. Solusi Aspose.Page API di antara berbagai fitur lainnya memungkinkan bekerja dengan tiket cetak. Di sini Anda akan menemukan informasi yang menjelaskan cara membuat, mengedit, mendapatkan, dan menautkannya.

Untuk memanipulasi tiket cetak file XPS, kita perlu:

  • Aspose.Page untuk .NET API yang kaya fitur, kuat, dan mudah digunakan untuk manipulasi dokumen dan API konversi untuk platform C#.

  • Buka manajer paket NuGet, cari Aspose.Page dan instal. Anda juga dapat menggunakan perintah berikut dari Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Page

Langkah-langkah membuat custom print ticket C# .NET.

  1. Atur jalur ke direktori dokumen.
  2. Buat file XPS menggunakan XpsDocument Class .
  3. Tambahkan tiket cetak pekerjaan khusus menggunakan Konstruktor JobPrintTicket .
  4. Tambahkan penginisialisasi parameter halaman kustom dan opsi resolusi halaman kustom ke tiket.
  5. Simpan dokumen XPS yang diubah menggunakan Metode XPsDocument.Save() .

Kode C# untuk membuat tiket cetak dalam file XPS

    using Aspose.Page.XPS;
    using Aspose.Page.XPS.XpsMetadata;
    using Aspose.Page.XPS.XpsModel;
    using System.Drawing;
    using System;
    // The path to the documents directory.
    string dir = RunExamples.GetDataDir_WorkingWithPrintTickets();

    // Create a new XPS document
    XpsDocument xDocs = new XpsDocument();

    // Add a custom job print ticket
    xDocs.JobPrintTicket = new JobPrintTicket(
        new PageDevModeSnaphot("SABlAGwAbABvACEAAAA="),             // Custom page parameter initializer
        new DocumentCollate(Collate.CollateOption.Collated),
        new JobCopiesAllDocuments(1),
        new PageICMRenderingIntent(PageICMRenderingIntent.PageICMRenderingIntentOption.Photographs),
        new PageColorManagement(PageColorManagement.PageColorManagementOption.None),
        new JobNUpAllDocumentsContiguously(
            new NUp.PresentationDirection(NUp.PresentationDirection.PresentationDirectionOption.RightBottom),
            new Borders(Borders.BordersOption.On) /* Custom nested feature */).AddPagesPerSheetOption(1),
        new PageMediaSize(PageMediaSize.PageMediaSizeOption.NorthAmericaLetter),
        new JobInputBin(InputBin.InputBinOption.AutoSelect),
        new JobDuplexAllDocumentsContiguously(Duplex.DuplexOption.OneSided),
        new PageOrientation(PageOrientation.PageOrientationOption.Portrait),
        new PageResolution(
            new PageResolution.PageResolutionOption("ns0000:ESDL300x300")             // Custom page resolution option
                .SetResolutionX(300).SetResolutionY(300)),
        new PageMediaType(PageMediaType.PageMediaTypeOption.Plain),
        new PageOutputColor(PageOutputColor.PageOutputColorOption.Color.Clone().SetDeviceBitsPerPixel(0).SetDriverBitsPerPixel(24)));


    // Save the document with the custom job print ticket.
    xDocs.Save(dir + "output1.xps");

Langkah-langkah mengedit tiket cetak XPS melalui C# .NET.

  1. Atur jalur ke direktori dokumen.
  2. Buka Dokumen XPS dengan mencetak tiket menggunakan XpsDocument Class.
  3. Untuk menghapus parameter yang tidak diperlukan dari tiket, gunakan Metode Remove() .
  4. Simpan dokumen dengan tiket cetak pekerjaan yang diubah melalui Metode XPsDocument.Save().

Kode C# untuk mengedit tiket cetak dalam file XPS

    // The path to the documents directory.
    string dir = RunExamples.GetDataDir_WorkingWithPrintTickets();

    // Open the XPS Document with print tickets
    XpsDocument xDocs = new XpsDocument(dir + "input3.xps");

    JobPrintTicket pt = xDocs.JobPrintTicket;

    // Remove some parameters from the job print ticket
    pt.Remove(
        "ns0000:PageDevmodeSnapshot",
        "ns0000:JobInterleaving",
        "ns0000:JobImageType");

    // Add some parameters to the job print ticket
    pt.Add(
        new JobCopiesAllDocuments(2),
        new PageMediaSize(PageMediaSize.PageMediaSizeOption.ISOA4));

    // Save the document with the changed job print ticket.
    xDocs.Save(dir + "output3.xps");

Langkah-langkah untuk mendapatkan tiket cetak melalui C# .NET.

  1. Atur jalur ke direktori dokumen.
  2. Buka Dokumen XPS dengan mencetak tiket menggunakan XpsDocument Class.
  3. Buat tiket cetak pekerjaan dengan Konstruktor JobPrintTicket.
  4. Buat tiket cetak dokumen menggunakan Metode GetDocumentPrintTicket() .
  5. Dapatkan tiket cetak halaman menggunakan Metode GetPagePrintTicket() .
  6. Simpan dokumen dengan tiket cetak pekerjaan yang diubah melalui Metode XPsDocument.Save().

Kode C# untuk mendapatkan tiket cetak dalam file XPS

    // The path to the documents directory.
    string dir = RunExamples.GetDataDir_WorkingWithPrintTickets();

    // Open the XPS Document without print tickets
    XpsDocument xDocs = new XpsDocument(dir + "input1.xps");

    // Get the job print ticket
    JobPrintTicket jobPrintTicket = xDocs.JobPrintTicket; // must be null for this document

    // Get the document print ticket
    DocumentPrintTicket docPrintTicket = xDocs.GetDocumentPrintTicket(1); // must be null for this document

    // Get the page print ticket
    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 + "output1.xps");

    // Open the saved earlier XPS Document with print tickets
    XpsDocument xDocs2 = new XpsDocument(dir + "output1.xps");

    // Print tickets must not be null

    Console.WriteLine(xDocs2.JobPrintTicket);

    Console.WriteLine(xDocs2.GetDocumentPrintTicket(1));

    Console.WriteLine(xDocs2.GetPagePrintTicket(1, 1));

Langkah-langkah untuk menautkan tiket cetak file XPS melalui C# .NET.

  1. Atur jalur ke direktori dokumen.
  2. Buat file XPS baru dan buka Dokumen XPS dengan tiket cetak menggunakan XpsDocument Class.
  3. Buka XPS Document dengan print tiket menggunakan XpsDocument Class
  4. Tautkan tiket cetak pekerjaan dengan Konstruktor JobPrintTicket.
  5. Tautkan tiket cetak dokumen menggunakan Metode GetDocumentPrintTicket() dan SetDocumentPrintTicket()
  6. Tautkan tiket cetak halaman menggunakan Metode GetPagePrintTicket() dan SetPagePrintTicket() .
  7. Simpan dokumen dengan tiket cetak pekerjaan yang diubah melalui Metode XPsDocument.Save().

Kode C# untuk menautkan tiket cetak dalam file XPS

    // The path to the documents directory.
    string dir = RunExamples.GetDataDir_WorkingWithPrintTickets();

    // Create a new XPS document
    XpsDocument xDocs1 = new XpsDocument();

    // Open the XPS Document with print tickets
    XpsDocument xDocs2 = new XpsDocument(dir + "input2.xps");

    // Link the job print ticket
    xDocs1.JobPrintTicket = xDocs2.JobPrintTicket;

    // Link the document print ticket
    xDocs1.SetDocumentPrintTicket(1, xDocs2.GetDocumentPrintTicket(2));

    // Link the page print ticket
    xDocs1.SetPagePrintTicket(1, 1, xDocs2.GetPagePrintTicket(3, 2));


    // Save the document with linked print tickets.
    xDocs1.Save(dir + "output1.xps");



Pertanyaan Umum

1. Bagaimana cara membuat tiket cetak untuk file XPS?

Untuk membuat tiket cetak (atau informasi pencetakan) pada dokumen sebelum dikirim ke printer, gunakan JobPrintTicket Kelas.

2. Operasi apa dengan tiket cetak yang tersedia dalam Solusi API Aspose.Page?

Dengan Solusi .NET ini Anda dapat membuat, mengedit, mendapatkan, dan menautkan informasi pencetakan.

3. Bagaimana cara mengedit informasi pencetakan file XPS?

Tetapkan jalur dan buka dokumen XPS dengan tiket cetak. Gunakan Metode Kelas PrintTicket.

XPS Apa itu Format File XPS

Format XPS mirip dengan format PDF. Keduanya adalah format bahasa deskripsi halaman (PDL). EPS didasarkan pada HTML dan bukan pada bahasa PostScript. File .eps mampu memuat markup struktur dokumen bersama dengan informasi tentang bagaimana dokumen itu akan terlihat. Ada juga petunjuk tambahan tentang cara mencetak dan merender dokumen. Fitur formatnya adalah memperbaiki deskripsi dokumen yang berarti akan terlihat sama tidak peduli siapa dan dari sistem operasional apa yang membukanya.