Operaciones de paquetes cruzados dentro del paquete XPS

Manipule páginas, colores y glifos dentro del paquete XPS a través de C#

 

Aspose.Page API Solution para .NET, entre otros formatos, incluye el paquete XPS como una biblioteca separada para trabajar con archivos XPS. Su rica funcionalidad contiene muchas características útiles y populares como la fusión de archivos, la conversión, el trabajo con gráficos, etc.

XPS puede contener varios archivos en un documento. Entonces, cualquier paquete XPS debe tener la funcionalidad para manipular esos archivos y sus páginas dentro del documento y entre diferentes documentos XPS. Estas manipulaciones se denominan operaciones entre paquetes. Deben explicarse por separado.

Aquí encontrará ejemplos de operaciones de paquetes cruzados tales como manipulación de páginas y adición de glifos y colores.

Pasos para manipular páginas dentro del paquete XPS C#.

  1. Establezca la ruta al directorio de documentos.
  2. Cree un archivo XPS usando XpsDocument Class .
  3. Para insertar una página activa de un documento al comienzo de otro documento, use InsertPage() Método.
  4. Para insertar una página activa de un documento al final de otro documento, utilice el método AddPage() .
  5. Para eliminar una página vacía, use el método RemovePage() .
  6. Para eliminar una página de un documento a otro documento, use InsertPage() y SelectActivePage() Métodos.
  7. Guarde los documentos XPS modificados mediante XPsDocument.Save .

Código C# para manipulaciones de paquetes cruzados con páginas

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

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument(dataDir + "input1.xps");

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument(dataDir + "input2.xps");

    // Create the third XPS Document
    XpsDocument doc3 = new XpsDocument(dataDir + "input3.xps");

    // Create the fourth XPS Document
    XpsDocument doc4 = new XpsDocument();

    // Insert the active page (1 in this case) from the second document to the beginning of the fourth document
    doc4.InsertPage(1, doc2.Page, false);

    // Insert the active page (1 in this case) from the third document to the end of the fourth document
    doc4.AddPage(doc3.Page, false);

    // Remove page 2 from the fourth document. This is an empty page that was created when the document had been created.
    doc4.RemovePageAt(2);

    // Insert page 3 from the first document to the second postion of the fourth document
    doc4.InsertPage(2, doc1.SelectActivePage(3), false);

    // Save the fourth XPS document
    doc4.Save(dataDir + "out.xps");

Pasos para agregar un clon de glifo dentro del paquete XPS C#.

  1. Establezca la ruta al directorio de documentos.
  2. Abra una transmisión del archivo XPS.
  3. Cree un archivo XPS utilizando XpsDocument Class.
  4. Agregue glifos al documento usando el método AddGlyphs() .
  5. Cree el segundo archivo XPS utilizando XpsDocument Class.
  6. Para clonar el glifo del primer archivo al segundo archivo, use Add() y Clone() Métodos.
  7. Guarde ambos documentos XPS mediante el método XPsDocument.Save().

Código C# para copiar un glyth dentro del paquete XPS

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument();

    // Add glyphs to the first document
    XpsGlyphs glyphs = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");

    // Fill glyphs in the first document with one color
    glyphs.Fill = doc1.CreateSolidColorBrush(Color.Green);

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument();

    // Add glyphs cloned from the one's from the first document
    glyphs = doc2.Add(glyphs.Clone());

    // Fill glyphs in the second document with another color
    ((XpsSolidColorBrush)glyphs.Fill).Color = doc2.CreateColor(Color.Red);

    // Save the first XPS document
    doc1.Save(dataDir + "out1.xps");

    // Save the second XPS document
    doc2.Save(dataDir + "out2.xps");

Pasos para agregar un Glyph C# lleno de imágenes.

  1. Establezca la ruta al directorio de documentos.
  2. Abra una transmisión del archivo XPS.
  3. Cree un archivo XPS utilizando XpsDocument Class.
  4. Agregue glifos al documento usando el método AddGlyphs().
  5. Para rellenar los glifos con un pincel de imagen, utilice el método CreateImageBrush() .
  6. Cree el segundo archivo XPS utilizando XpsDocument Class.
  7. Agregue glifos con la fuente del primer documento al segundo documento utilizando el método AddGlyphs().
  8. Cree un pincel de imagen a partir del relleno del primer documento y rellene los glifos en el segundo documento utilizando el método CreateImageBrush().
  9. Guarde ambos documentos XPS mediante el método XPsDocument.Save()

Código C# para crear un glifo lleno de imágenes dentro del paquete XPS

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCrossPackageOperations();

    // Create the first XPS Document
    XpsDocument doc1 = new XpsDocument();

    // Add glyphs to the first document
    XpsGlyphs glyphs1 = doc1.AddGlyphs("Times New Roman", 200, FontStyle.Bold, 50, 250, "Test");

    // Fill the glyphs with an image brush
    glyphs1.Fill = doc1.CreateImageBrush(dataDir + "R08SY_NN.tif", new RectangleF(0f, 0f, 128f, 192f),
        new RectangleF(0f, 0f, 64f, 96f));
    ((XpsImageBrush)glyphs1.Fill).TileMode = XpsTileMode.Tile;

    // Create the second XPS Document
    XpsDocument doc2 = new XpsDocument();

    // Add glyphs with the font from the first document to the second document
    XpsGlyphs glyphs2 = doc2.AddGlyphs(glyphs1.Font, 200, 50, 250, "Test");

    // Create an image brush from the fill of the the first document and fill glyphs in the second document
    glyphs2.Fill = doc2.CreateImageBrush(((XpsImageBrush)glyphs1.Fill).Image, new RectangleF(0f, 0f, 128f, 192f),
        new RectangleF(0f, 0f, 128f, 192f));
    ((XpsImageBrush)glyphs2.Fill).TileMode = XpsTileMode.Tile;

    // Save the first XPS document
    doc1.Save(dataDir + "out1.xps");

    // Save the second XPS document
    doc2.Save(dataDir + "out2.xps");



Preguntas más frecuentes

1. ¿Qué es el paquete XPS?

El paquete XPS es una biblioteca separada para administrar archivos XPS. Úselo para crear sus propios convertidores, lectores u otras aplicaciones para editar XPS.

2. ¿Cómo puedo obtener un paquete XPS?

El paquete XPS está incluido en la solución Aspose.Page .

3. ¿Qué operaciones entre paquetes están disponibles?

Con el paquete Aspose XPS puede transferir páginas de un documento a otro, clonar objetos como glifos, estilos o configuraciones.

4. ¿Cómo manipular páginas entre documentos XPS?

Para transferir archivos con este paquete XPS, utilice los métodos InsertPage(), AddPage(), RemovePage() y SelectActivePage() de la clase XpsDocument.

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.