Operasi lintas-paket dalam Paket XPS

Memanipulasi halaman, warna, dan mesin terbang dalam Paket XPS melalui C#

 

Aspose.Page API Solusi untuk .NET di antara format lainnya termasuk Paket XPS sebagai pustaka terpisah untuk bekerja dengan file XPS. Fungsionalitasnya yang kaya berisi banyak fitur berguna dan populer seperti menggabungkan file, konversi, bekerja dengan grafik, dll.

XPS dapat menyimpan dalam satu dokumen beberapa file. Jadi Paket XPS apa pun harus memiliki fungsi untuk memanipulasi file-file itu dan halamannya di dalam dokumen dan di antara dokumen XPS yang berbeda. Manipulasi semacam itu disebut operasi lintas paket. Mereka harus dijelaskan secara terpisah.

Di sini Anda akan menemukan contoh operasi lintas-paket seperti manipulasi halaman, dan menambahkan mesin terbang dan warna.

Langkah-langkah untuk memanipulasi halaman dalam Paket XPS C#.

  1. Atur jalur ke direktori dokumen.
  2. Buat file XPS menggunakan XpsDocument Class .
  3. Untuk menyisipkan halaman aktif dari satu dokumen ke awal dokumen lain, gunakan InsertPage() Metode.
  4. Untuk menyisipkan halaman aktif dari satu dokumen ke akhir dokumen lain, gunakan Metode AddPage() .
  5. Untuk menghapus halaman kosong gunakan Metode RemovePage() .
  6. Untuk menghapus halaman dari satu dokumen ke dokumen lain gunakan InsertPage() dan SelectActivePage() Metode.
  7. Simpan dokumen XPS yang diubah menggunakan XPsDocument.Save .

C# Kode untuk manipulasi lintas-paket dengan halaman

    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");

Langkah-langkah untuk menambahkan klon mesin terbang dalam Paket XPS C#.

  1. Atur jalur ke direktori dokumen.
  2. Buka aliran file XPS.
  3. Buat file XPS menggunakan XpsDocument Class.
  4. Tambahkan mesin terbang ke dokumen menggunakan Metode AddGlyphs() .
  5. Buat file XPS kedua menggunakan XpsDocument Class.
  6. Untuk mengkloning mesin terbang dari file pertama ke file kedua, gunakan Add() dan Clone() Metode.
  7. Simpan kedua dokumen XPS melalui Metode XPsDocument.Save().

Kode C# untuk menyalin glyth dalam Paket 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");

Langkah-langkah untuk menambahkan Glyph C# yang dipenuhi gambar.

  1. Atur jalur ke direktori dokumen.
  2. Buka aliran file XPS.
  3. Buat file XPS menggunakan XpsDocument Class.
  4. Tambahkan mesin terbang ke dokumen menggunakan AddGlyphs() Metode.
  5. Untuk mengisi mesin terbang dengan kuas gambar, gunakan Metode CreateImageBrush() .
  6. Buat file XPS kedua menggunakan XpsDocument Class.
  7. Tambahkan glyphs dengan font dari dokumen pertama ke dokumen kedua menggunakan AddGlyphs() Metode.
  8. Buat kuas gambar dari isi dokumen pertama dan isi mesin terbang di dokumen kedua menggunakan Metode CreateImageBrush().
  9. Simpan kedua dokumen XPS melalui Metode XPsDocument.Save()

Kode C# untuk membuat Glyph berisi gambar dalam Paket 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");



Pertanyaan Umum

1. Apa itu Paket XPS?

Paket XPS adalah perpustakaan terpisah untuk mengelola file XPS. Gunakan untuk membuat konverter Anda sendiri, pembaca atau aplikasi lain untuk mengedit XPS.

2. Bagaimana saya bisa mendapatkan Paket XPS?

Paket XPS disertakan dalam Solusi Aspose.Page .

3. Operasi lintas paket apa saja yang tersedia?

Dengan menggunakan Paket Aspose XPS Anda dapat mentransfer halaman dari satu dokumen ke dokumen lainnya, mengkloning objek seperti mesin terbang, gaya, atau pengaturan.

4. Bagaimana cara memanipulasi halaman antar dokumen XPS?

Untuk mentransfer file dengan Paket XPS ini gunakan Metode InsertPage(), AddPage(), RemovePage(), dan SelectActivePage() dari Kelas XpsDocument.

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.