XPS Paketi içindeki paketler arası işlemler
C++ aracılığıyla XPS Paketi içindeki sayfaları, renkleri ve glifleri işleyin
C++ için Aspose.Page API, XPS dosyalarıyla çalışmak için ayrı bir kütüphane sunarak, onlara farklı bir format olarak davranmanıza olanak tanır. Bu kütüphane, XPS belgelerini birleştirme, diğer biçimlere dönüştürme ve içlerindeki grafikleri işleme dahil olmak üzere çeşitli faydalı özelliklere sahiptir.
XPS dosyalarının önemli bir yönü, tek bir belge içinde birden fazla dosya içerebilme yetenekleridir. Sonuç olarak Aspose.Page XPS kütüphanesi, bu dahili dosyaları ve sayfalarını yönetmeye yönelik işlevler sağlar. "Paketler arası işlemler (cross-package operations)" olarak bilinen bu işlemler, farklı XPS belgelerindeki içeriğin işlenmesini (manipüle edilmesini) içerir.
Bu bölüm, tek bir XPS belgesi içindeki sayfaları yönetmek ve belirli renklerde metin (glifler) eklemek gibi paketler arası işlemlerin belirli örneklerine değinecektir.
Ancak bu işlevi denemek için öncelikle çözümü edinmeniz gerekir:
NuGet paket yöneticisini (package manager) açın, Aspose.Page'i arayın ve yükleyin. Paket Yöneticisi Konsolundan (Package Manager Console) aşağıdaki komutu da kullanabilirsiniz.
XPS Package C++ içinde sayfaları değiştirme (manipüle etme) adımları.
- Belgeler dizininin yolunu ayarlayın.
- XpsDocument Sınıfını (XpsDocument Class) kullanarak bir XPS dosyası oluşturun.
- Bir belgeden aktif bir sayfayı başka bir belgenin başına eklemek için InsertPage() Metodunu kullanın.
- Bir belgeden aktif bir sayfayı başka bir belgenin sonuna eklemek için AddPage() Metodunu kullanın.
- Boş bir sayfayı kaldırmak için RemovePage() Metodunu kullanın.
- Bir sayfayı (taşımak için) bir belgeden başka bir belgeye kaldırmak için InsertPage() ve SelectActivePage() Metotlarını kullanın.
- Değiştirilen XPS belgelerini XPsDocument.Save Metodu ile kaydedin.
Sayfaları Değiştirme (Manipüle Etme)
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>(dataDir + u"input1.xps");
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>(dataDir + u"input2.xps");
// Create the third XPS Document
System::SharedPtr<XpsDocument> doc3 = System::MakeObject<XpsDocument>(dataDir + u"input3.xps");
// Create the fourth XPS Document
System::SharedPtr<XpsDocument> doc4 = System::MakeObject<XpsDocument>();
// Insert active page (1 in this case) from the second document to the beginning of the fourth document
doc4->InsertPage(1, doc2->get_Page(), false);
// Insert active page (1 in this case) from the third document to the end of the fourth document
doc4->AddPage(doc3->get_Page(), false);
// Remove page 2 from the fourth document. This is an empty page that was created when document has 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 + u"output/" + u"out.xps");
XPS Package C++ içine bir glif klonu eklemek için adımlar.
- Belgeler dizininin yolunu ayarlayın.
- XPS dosyasının bir akışını (stream) açın.
- XpsDocument Class kullanarak bir XPS dosyası oluşturun.
- AddGlyphs() Metodunu kullanarak belgeye glifler (glyphs) ekleyin.
- XpsDocument Class kullanarak ikinci XPS dosyasını oluşturun.
- Glifi ilk dosyadan ikinci dosyaya kopyalamak (klonlamak) için Add() ve Clone() Metotlarını kullanın.
- XPsDocument.Save() Metodu ile her iki XPS belgesini de kaydedin.
Glif Klonu Ekle ve Rengi Değiştir
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>();
// Add glyphs to the first document
System::SharedPtr<XpsGlyphs> glyphs = doc1->AddGlyphs(u"Times New Roman", 200.0f, System::Drawing::FontStyle::Bold, 50.0f, 250.0f, u"Test");
// Fill glyphs in the first document with one color
glyphs->set_Fill(doc1->CreateSolidColorBrush(System::Drawing::Color::get_Green()));
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>();
// Add glyphs cloned from the one's from the first document
glyphs = doc2->Add<System::SharedPtr<XpsGlyphs>>(glyphs->Clone());
// Fill glyphs in the second document with another color
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsSolidColorBrush>(glyphs->get_Fill()))->set_Color(doc2->CreateColor(System::Drawing::Color::get_Red()));
// Save the first XPS document
doc1->Save(dataDir + u"output/" + u"out1.xps");
// Save the second XPS document
doc2->Save(dataDir + u"output/" + u"out2.xps");
Görüntü dolgulu (Image-filled) Glif C++ ekleme adımları.
- Belgeler dizininin yolunu ayarlayın.
- XPS dosyasının bir akışını açın.
- XpsDocument Class kullanarak bir XPS dosyası oluşturun.
- AddGlyphs() Metodu ile belgeye glifler ekleyin.
- Glifleri bir görüntü fırçası (image brush) ile doldurmak için CreateImageBrush() Metodunu kullanın.
- XpsDocument Class kullanarak ikinci XPS dosyasını oluşturun.
- AddGlyphs() Metodu kullanılarak, ilk belgedeki yazı tipine sahip glifleri ikinci belgeye ekleyin.
- İlk belgenin dolgusundan (fill) bir resim fırçası oluşturun ve CreateImageBrush() Metodu ile ikinci belgedeki glifleri doldurun.
- XPsDocument.Save() Metodu ile her iki XPS belgesini de kaydedin.
Görüntü Dolgulu Glif ve Yabancı Görsel Ekleme
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithCrossPackageOperations();
// Create the first XPS Document
System::SharedPtr<XpsDocument> doc1 = System::MakeObject<XpsDocument>();
// Add glyphs to the first document
System::SharedPtr<XpsGlyphs> glyphs1 = doc1->AddGlyphs(u"Times New Roman", 200.0f, System::Drawing::FontStyle::Bold, 50.0f, 250.0f, u"Test");
// Fill the glyphs with an image brush
glyphs1->set_Fill(doc1->CreateImageBrush(dataDir + u"R08SY_NN.tif", System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f), System::Drawing::RectangleF(0.f, 0.f, 64.f, 96.f)));
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs1->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::Tile);
// Create the second XPS Document
System::SharedPtr<XpsDocument> doc2 = System::MakeObject<XpsDocument>();
// Add glyphs with the font from the first document to the second document
System::SharedPtr<XpsGlyphs> glyphs2 = doc2->AddGlyphs(glyphs1->get_Font(), 200.0f, 50.0f, 250.0f, u"Test");
// Create an image brush from the fill of the the first document and fill glyphs in the second document
glyphs2->set_Fill(doc2->CreateImageBrush((System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs1->get_Fill()))->get_Image(), System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f), System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f)));
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(glyphs2->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::Tile);
// Save the first XPS document
doc1->Save(dataDir + u"output/" + u"out1.xps");
// Save the second XPS document
doc2->Save(dataDir + u"output/" + u"out2.xps");XPS XPS Dosya Biçimi nedir
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.