Operaciones entre paquetes dentro de un paquete XPS

Manipular páginas, colores y glifos dentro de un paquete XPS mediante C#

 

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

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

Aquí encontrará ejemplos de tales operaciones entre paquetes, como manipulaciones de páginas y la adición de glifos y colores.

Pasos para manipular páginas dentro de un paquete XPS con C#.

  1. Establezca la ruta al directorio de documentos.
  2. Cree un archivo XPS utilizando la clase XpsDocument .
  3. To insert an active page from one document to the beginning of another document use the InsertPage() Method.
  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, utilice el método RemovePage() .
  6. Para mover una página de un documento a otro documento, utilice los métodos InsertPage() y SelectActivePage() .
  7. Guarde los documentos XPS modificados utilizando XPsDocument.Save .

Código C# para manipulaciones de páginas entre paquetes

    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 de un paquete XPS con C#.

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

Código C# para copiar un glifo dentro de un 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 glifo relleno de imagen con C#.

  1. Establezca la ruta al directorio de documentos.
  2. Abra un flujo del archivo XPS.
  3. Cree un archivo XPS utilizando la clase XpsDocument.
  4. Agregue glifos al documento utilizando 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 la clase XpsDocument.
  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 relleno de imagen dentro de un 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 What is XPS File Format

XPS (XML Paper Specification) es el equivalente de Microsoft a PDF. Se basa en XML/HTML, mantiene el diseño en distintas plataformas y es independiente del sistema operativo.