XPS Paketi içindeki paketler arası işlemler

C# aracılığıyla XPS Paketi içindeki sayfaları, renkleri ve glifleri manipüle edin

 

.NET için Aspose.Page API Çözümü, diğer formatların yanı sıra XPS dosyalarıyla çalışmak için ayrı bir kütüphane olarak XPS Paketi'ni içerir. Zengin işlevselliği; dosyaları birleştirme, dönüştürme, grafiklerle çalışma vb. gibi birçok yararlı ve popüler özelliği içerir.

XPS, tek bir belgede birden fazla dosya tutabilir. Bu nedenle, herhangi bir XPS Paketi, bu dosyaları ve sayfalarını belge içinde ve farklı XPS belgeleri arasında manipüle etme işlevselliğine sahip olmalıdır. Bu tür manipülasyonlara paketler arası işlemler (cross-package operations) denir. Bunlar ayrı ayrı açıklanmalıdır.

Burada sayfa manipülasyonları, glif ve renk ekleme gibi paketler arası işlem örneklerini bulacaksınız.

C# ile XPS Paketi içindeki sayfaları manipüle etme adımları.

  1. Belge dizinine giden yolu ayarlayın.
  2. XpsDocument Sınıfı kullanarak bir XPS dosyası oluşturun.
  3. Bir belgedeki aktif bir sayfayı başka bir belgenin başına eklemek için InsertPage() yöntemini kullanın.
  4. Bir belgedeki aktif bir sayfayı başka bir belgenin sonuna eklemek için AddPage() yöntemini kullanın.
  5. Boş bir sayfayı kaldırmak için RemovePage() yöntemini kullanın.
  6. Bir sayfayı bir belgeden diğerine taşımak için InsertPage() ve SelectActivePage() yöntemlerini kullanın.
  7. Değiştirilen XPS belgelerini XPsDocument.Save kullanarak kaydedin.

Sayfalarla paketler arası manipülasyonlar için C# Kodu

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

C# ile XPS Paketi içinde bir glif klonu ekleme adımları.

  1. Belge dizinine giden yolu ayarlayın.
  2. XPS dosyasının bir akışını açın.
  3. XpsDocument Sınıfı kullanarak bir XPS dosyası oluşturun.
  4. AddGlyphs() yöntemini kullanarak belgeye glifler ekleyin.
  5. XpsDocument Sınıfı kullanarak ikinci XPS dosyasını oluşturun.
  6. Glifi ilk dosyadan ikinci dosyaya kopyalamak için Add() ve Clone() yöntemlerini kullanın.
  7. Her iki XPS belgesini XPsDocument.Save() yöntemiyle kaydedin.

XPS Paketi içinde bir glifi kopyalamak için C# Kodu

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

C# ile resimle doldurulmuş bir Glif ekleme adımları.

  1. Belge dizinine giden yolu ayarlayın.
  2. XPS dosyasının bir akışını açın.
  3. XpsDocument Sınıfı kullanarak bir XPS dosyası oluşturun.
  4. AddGlyphs() yöntemini kullanarak belgeye glifler ekleyin.
  5. Glifleri bir resim fırçasıyla doldurmak için CreateImageBrush() yöntemini kullanın.
  6. XpsDocument Sınıfı kullanarak ikinci XPS dosyasını oluşturun.
  7. İlk belgedeki yazı tipini kullanarak ikinci belgeye glifler eklemek için AddGlyphs() yöntemini kullanın.
  8. İlk belgenin dolgusundan bir resim fırçası oluşturun ve CreateImageBrush() yöntemini kullanarak ikinci belgedeki glifleri doldurun.
  9. Her iki XPS belgesini XPsDocument.Save() yöntemiyle kaydedin.

XPS Paketi içinde resimle doldurulmuş bir Glif oluşturmak için C# Kodu

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



SSS

1. XPS Paketi Nedir?

XPS Paketi, XPS dosyalarını yönetmek için ayrı bir kitaplıktır. XPS’yi düzenlemek için kendi dönüştürücülerinizi, okuyucularınızı veya diğer uygulamalarınızı oluşturmak için bunu kullanın.

2. XPS Paketini nasıl alabilirim?

XPS Paketi, Aspose.Page Çözümüne dahildir.

3. Hangi çapraz paket işlemleri mevcut?

Aspose XPS Paketini kullanarak sayfaları bir belgeden diğerine aktarabilir, glifler, stiller veya ayarlar gibi nesneleri kopyalayabilirsiniz.

4. XPS belgeleri arasındaki sayfalar nasıl değiştirilir?

Bu XPS Paketi ile dosya aktarmak için XpsDocument Sınıfının InsertPage(), AddPage(), RemovePage() ve SelectActivePage() Yöntemlerini kullanın.

XPS What is XPS File Format

XPS (XML Paper Specification), Microsoft’un PDF alternatifi olan bir formattır. XML/HTML temelli olup, farklı platformlarda aynı görünümü korur ve işletim sisteminden bağımsızdır.