เพิ่มและจัดการพิมพ์ตั๋ว

สร้าง แก้ไข เชื่อมโยง และรับพิมพ์ตั๋วของไฟล์ XPS ผ่าน C#

 

รูปแบบภาษาคำอธิบายหน้าทั้งหมดรองรับการพิมพ์ บางส่วน เช่น PDF รองรับการพิมพ์คุณภาพสูงด้วยช่องว่างสีที่หลากหลายและสภาพแวดล้อมที่ไม่ขึ้นกับความละเอียด เนื่องจาก XPS ตั้งใจให้พิมพ์บนเครื่องพิมพ์สำนักงานทั่วไป จึงรองรับพื้นที่สีน้อยลงและฟอนต์เพียง 2 ประเภทเท่านั้น โซลูชัน Aspose.Page API ท่ามกลางคุณสมบัติอื่นๆ ที่แตกต่างกันช่วยให้สามารถทำงานกับตั๋วพิมพ์ได้ ที่นี่คุณจะพบข้อมูลที่อธิบายวิธีสร้าง แก้ไข รับและเชื่อมโยง

ในการจัดการตั๋วพิมพ์ของไฟล์ XPS เราต้องการ:

  • Aspose.Page สำหรับ .NET API ซึ่งเป็น API การจัดการและการแปลงเอกสารที่มีคุณลักษณะหลากหลาย มีประสิทธิภาพ และใช้งานง่ายสำหรับแพลตฟอร์ม C#

  • เปิดตัวจัดการแพ็คเกจ NuGet และค้นหา Aspose.Page และติดตั้ง คุณสามารถใช้คำสั่งต่อไปนี้จาก Package Manager Console

Package Manager Console Command


    PM> Install-Package Aspose.Page

ขั้นตอนในการสร้างตั๋วพิมพ์แบบกำหนดเอง C# .NET

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. สร้างไฟล์ XPS โดยใช้ XpsDocument Class
  3. เพิ่มตั๋วพิมพ์งานที่กำหนดเองโดยใช้ JobPrintTicket Constructor
  4. เพิ่มตัวเริ่มต้นพารามิเตอร์หน้าแบบกำหนดเองและตัวเลือกการแก้ไขหน้าแบบกำหนดเองให้กับตั๋ว
  5. บันทึกเอกสาร XPS ที่เปลี่ยนแปลงโดยใช้เมธอด XPsDocument.Save()

รหัส C# สำหรับพิมพ์ตั๋วในไฟล์ 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");

ขั้นตอนในการแก้ไขตั๋วพิมพ์ XPS ผ่าน C# .NET

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. เปิดเอกสาร XPS ด้วยการพิมพ์ตั๋วโดยใช้ XpsDocument Class
  3. หากต้องการลบพารามิเตอร์ที่ไม่จำเป็นออกจากตั๋ว ให้ใช้เมธอด Remove()
  4. บันทึกเอกสารด้วยตั๋วพิมพ์งานที่เปลี่ยนแปลงโดยใช้วิธีการ XPsDocument.Save()

รหัส C# เพื่อแก้ไขตั๋วพิมพ์ในไฟล์ 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");

ขั้นตอนในการรับตั๋วพิมพ์ผ่าน C# .NET

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. เปิดเอกสาร XPS ด้วยการพิมพ์ตั๋วโดยใช้ XpsDocument Class
  3. สร้างตั๋วพิมพ์งานด้วยตัวสร้าง JobPrintTicket
  4. สร้างตั๋วพิมพ์เอกสารโดยใช้เมธอด GetDocumentPrintTicket()
  5. รับตั๋วพิมพ์หน้าโดยใช้วิธี GetPagePrintTicket()
  6. บันทึกเอกสารด้วยตั๋วพิมพ์งานที่เปลี่ยนแปลงโดยใช้วิธีการ XPsDocument.Save()

รหัส C# เพื่อรับตั๋วพิมพ์ในไฟล์ 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));

ขั้นตอนในการเชื่อมโยงตั๋วพิมพ์ของไฟล์ XPS ผ่าน C# .NET

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. สร้างไฟล์ XPS ใหม่และเปิดเอกสาร XPS ด้วยตั๋วพิมพ์โดยใช้ XpsDocument Class
  3. เปิดเอกสาร XPS ด้วยการพิมพ์ตั๋วโดยใช้ XpsDocument Class
  4. เชื่อมโยงตั๋วพิมพ์งานกับตัวสร้าง JobPrintTicket
  5. เชื่อมโยงตั๋วพิมพ์เอกสารโดยใช้วิธีการ GetDocumentPrintTicket() และ SetDocumentPrintTicket()
  6. เชื่อมโยงตั๋วพิมพ์หน้าโดยใช้วิธีการ GetPagePrintTicket() และ SetPagePrintTicket()
  7. บันทึกเอกสารโดยเปลี่ยนตั๋วงานพิมพ์โดยใช้วิธี XPsDocument.Save()

รหัส C# เพื่อเชื่อมโยงตั๋วพิมพ์ในไฟล์ 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");



คำถามที่พบบ่อย

1. ฉันจะสร้างตั๋วพิมพ์สำหรับไฟล์ XPS ได้อย่างไร

หากต้องการพิมพ์ตั๋ว (หรือข้อมูลการพิมพ์) ไปยังเอกสารก่อนส่งไปยังเครื่องพิมพ์ ให้ใช้ JobPrintTicket คลาส

2. การดำเนินการใดบ้างที่มีตั๋วพิมพ์พร้อมใช้งานภายในโซลูชัน Aspose.Page API

ด้วยโซลูชัน .NET นี้ คุณสามารถสร้าง แก้ไข รับ และลิงก์ข้อมูลการพิมพ์ได้

3. ฉันจะแก้ไขข้อมูลการพิมพ์ของไฟล์ XPS ได้อย่างไร

กำหนดเส้นทางและเปิดเอกสาร XPS พร้อมตั๋วพิมพ์ ใช้วิธีการของคลาส PrintTicket

XPS XPS รูปแบบไฟล์คืออะไร

รูปแบบ XPS คล้ายกับรูปแบบ PDF ทั้งสองรูปแบบเป็นภาษาคำอธิบายหน้า (PDL) EPS อิงตาม HTML ไม่ใช่ภาษา PostScript ไฟล์ .eps สามารถใส่มาร์กอัปของโครงสร้างของเอกสารพร้อมกับข้อมูลเกี่ยวกับลักษณะของเอกสารได้ นอกจากนี้ยังมีคำแนะนำเพิ่มเติมเกี่ยวกับวิธีการพิมพ์และแสดงผลเอกสาร คุณสมบัติของรูปแบบคือ แก้ไขคำอธิบายของเอกสาร ซึ่งหมายความว่าจะมีลักษณะเหมือนกันไม่ว่าใครจะเปิดจากระบบปฏิบัติการใด