Agregar y manipular boletos impresos

Cree, edite, vincule y obtenga tickets de impresión de archivos XPS a través de C#

 

Todos los formatos del lenguaje de descripción de página admiten la impresión. Algunos de ellos, como PDF, admiten impresión de alta calidad con una variedad de espacios de color y entornos independientes de la resolución. Dado que XPS estaba destinado a imprimirse en impresoras de oficina comunes, admite menos espacios de color y solo 2 tipos de fuentes. La solución Aspose.Page API, entre otras características, permite trabajar con tickets impresos. Aquí encontrarás información que explica cómo crearlos, editarlos, obtenerlos y vincularlos.

Para manipular tickets de impresión de archivos XPS, necesitamos:

  • Aspose.Page para .NET API, que es una API de manipulación y conversión de documentos rica en funciones, potente y fácil de usar para la plataforma C#.

  • Abra el administrador de paquetes NuGet, busque Aspose.Page e instálelo. También puede usar el siguiente comando desde la Consola del administrador de paquetes.

Package Manager Console Command


    PM> Install-Package Aspose.Page

Pasos para crear un ticket de impresión personalizado C# .NET.

  1. Establezca la ruta al directorio de documentos.
  2. Cree un archivo XPS usando XpsDocument Class .
  3. Agregue un ticket de impresión de trabajo personalizado mediante el constructor JobPrintTicket .
  4. Agregue un inicializador de parámetros de página personalizado y una opción de resolución de página personalizada al ticket.
  5. Guarde el documento XPS modificado con el método XPsDocument.Save() .

Código C# para imprimir boletos en un archivo 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");

Pasos para editar el ticket de impresión XPS a través de C# .NET.

  1. Establezca la ruta al directorio de documentos.
  2. Abra el documento XPS con boletos impresos utilizando XpsDocument Class.
  3. Para eliminar los parámetros no necesarios del ticket, utilice el método Remove() .
  4. Guarde el documento con el ticket de impresión del trabajo modificado mediante el método XPsDocument.Save().

Código C# para editar boletos impresos en un archivo 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");

Pasos para obtener un ticket de impresión a través de C# .NET.

  1. Establezca la ruta al directorio de documentos.
  2. Abra el documento XPS con boletos impresos utilizando XpsDocument Class.
  3. Cree el ticket de impresión del trabajo con el constructor JobPrintTicket.
  4. Cree el ticket de impresión del documento con el método GetDocumentPrintTicket() .
  5. Obtenga el ticket de impresión de la página mediante el método GetPagePrintTicket() .
  6. Guarde el documento con el ticket de impresión del trabajo modificado mediante el método XPsDocument.Save().

Código C# para obtener boletos impresos en un archivo 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));

Pasos para vincular boletos de impresión del archivo XPS a través de C# .NET.

  1. Establezca la ruta al directorio de documentos.
  2. Cree un nuevo archivo XPS y abra el documento XPS con boletos impresos usando XpsDocument Class.
  3. Abra el documento XPS con boletos impresos usando XpsDocument Class
  4. Vincule el ticket de impresión del trabajo con el constructor JobPrintTicket.
  5. Vincule el ticket de impresión del documento utilizando los métodos GetDocumentPrintTicket() y SetDocumentPrintTicket()
  6. Vincule el ticket de impresión de página utilizando los métodos GetPagePrintTicket() y SetPagePrintTicket() .
  7. Guarde el documento con el ticket de impresión del trabajo modificado mediante el método XPsDocument.Save().

Código C# para vincular boletos impresos en un archivo 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");



Preguntas más frecuentes

1. ¿Cómo puedo crear un ticket de impresión para un archivo XPS?

Para realizar un ticket de impresión (o información de impresión) del documento antes de enviarlo a la impresora, utilice JobPrintTicket Clase.

2. ¿Qué operaciones con tickets impresos están disponibles en la solución API Aspose.Page?

Con esta solución .NET puede crear, editar, obtener y vincular información de impresión.

3. ¿Cómo puedo editar la información de impresión del archivo XPS?

Establezca la ruta y abra un documento XPS con boletos de impresión. Utilice métodos de la clase PrintTicket.

XPS Qué es XPS Formato de archivo

El formato XPS es similar al formato PDF. Ambos son formatos de lenguaje de descripción de página (PDL). EPS se basa en HTML y no en lenguaje PostScript. El archivo .eps puede contener un marcado de la estructura del documento junto con la información sobre cómo se vería el documento. También hay instrucciones adicionales sobre cómo imprimir y renderizar el documento. La característica del formato es que corrige la descripción del documento, lo que significa que se verá igual sin importar quién y desde qué sistema operativo lo abra.