การทำงานข้ามแพ็คเกจภายในแพ็คเกจ XPS
จัดการหน้า สี และ glyph ภายในแพ็คเกจ XPS ผ่าน C++
Aspose.Page API สำหรับ C++ ขอเสนอไลบรารีแยกต่างหากสำหรับการทำงานกับไฟล์ XPS ซึ่งช่วยให้คุณสามารถปฏิบัติต่อไฟล์ XPS ในรูปแบบที่แตกต่างกันได้ ไลบรารีนี้มีฟีเจอร์ที่เป็นประโยชน์มากมาย เช่น การรวมเอกสาร XPS การแปลงเป็นรูปแบบอื่น และการจัดการกราฟิกภายในเอกสาร XPS
แง่มุมที่สำคัญประการหนึ่งของไฟล์ XPS คือความสามารถในการมีหลายไฟล์อยู่ภายในเอกสารเดียว ด้วยเหตุนี้ ไลบรารี Aspose.Page XPS จึงมีฟังก์ชันการทำงานสำหรับการจัดการไฟล์ภายในเหล่านี้และหน้าต่างๆ ของไฟล์เหล่านั้น การดำเนินการเหล่านี้หรือที่เรียกว่า "การทำงานข้ามแพ็คเกจ (cross-package operations)" เกี่ยวข้องกับการจัดการเนื้อหาในเอกสาร XPS ต่างๆ
หัวข้อนี้จะเจาะลึกตัวอย่างเฉพาะของการทำงานข้ามแพกเกจ เช่น การจัดการหน้าในเอกสาร XPS ไฟล์เดียวและการเพิ่มข้อความ (glyphs) ที่มีสีเฉพาะ
แต่หากต้องการทดลองใช้ฟังก์ชันการทำงาน คุณต้องได้รับโซลูชันก่อน:
เปิดโปรแกรมจัดการแพ็กเกจ NuGet แล้วค้นหา Aspose.Page แล้วติดตั้ง คุณอาจใช้คำสั่งต่อไปนี้ จาก Package Manager Console
ขั้นตอนในการจัดการหน้าต่างๆ ภายในแพ็คเกจ XPS ใน C++
- ระบุเส้นทางไปยังไดเรกทอรีเอกสาร
- สร้างไฟล์ XPS โดยใช้ XpsDocument Class
- หากต้องการแทรกหน้าที่ใช้งานอยู่จากเอกสารหนึ่งไปยังจุดเริ่มต้นของเอกสารอีกไฟล์หนึ่ง ให้ใช้วิธีการ InsertPage()
- หากต้องการแทรกหน้าที่ใช้งานอยู่จากเอกสารหนึ่งไปยังส่วนท้ายของเอกสารอีกไฟล์หนึ่ง ให้ใช้วิธีการ AddPage()
- หากต้องการนำหน้าว่างออก ให้ตั้งค่าเป็นใช้วิธีการ RemovePage()
- หากต้องการลบ (ย้าย) หน้าเอกสารจากเอกสารหนึ่งไปยังเอกสารอื่น ให้ใช้วิธีการ InsertPage() และ SelectActivePage()
- บันทึกเอกสาร XPS ที่เปลี่ยนแปลงโดยใช้เมธอด XPsDocument.Save
จัดการเพจ
// 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 ใน C++
- ระบุเส้นทางไปยังไดเรกทอรีเอกสาร
- เปิดสตรีมไฟล์ XPS
- สร้างไฟล์ XPS โดยใช้ XpsDocument Class
- เพิ่มภาพกลีฟส์ลงในเอกสารโดยใช้เมธอด AddGlyphs()
- สร้างไฟล์ XPS ที่สองโดยใช้ XpsDocument Class
- หากต้องการโคลนเส้นเชื่อมจากไฟล์แรกไปยังไฟล์ที่ 2 ให้ใช้วิธีการ Add() และ Clone()
- บันทึกเอกสาร XPS ทั้งสองแบบด้วยเมธอด XPsDocument.Save()
เพิ่มการโคลนของ Glyph และเปลี่ยนสี
// 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");
ขั้นตอนในการเพิ่มภาพรูปทรงที่เต็มเปี่ยมไปด้วยอักษร C++
- ระบุเส้นทางไปยังไดเรกทอรีเอกสาร
- เปิดสตรีมไฟล์ XPS
- สร้างไฟล์ XPS โดยใช้ XpsDocument Class
- เพิ่มรูปอักขระ (glyphs) ลงในเอกสารโดยใช้วิธี AddGlyphs()
- หากต้องการเติมกลีฟด้วยอิมเมจแปรง (image brush) ให้ใช้วิธีการ CreateImageBrush()
- สร้างไฟล์ XPS ที่สองโดยใช้ XpsDocument Class
- เพิ่มรูปอักขระด้วยฟอนต์จากเอกสารแรกไปยังเอกสารที่สองโดยใช้วิธี AddGlyphs()
- สร้างแปรงรูปภาพจากการเติมของเอกสารแรก และเติมกลีฟส์ในเอกสารที่สองโดยใช้วิธี CreateImageBrush()
- บันทึกเอกสาร XPS ทั้งสองฉบับด้วยเมธอด XPsDocument.Save()
เพิ่ม Glyph ที่เติมภาพและรูปภาพภายนอก
// 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 รูปแบบไฟล์คืออะไร
XPS (XML Paper Specification) เป็นรูปแบบทางเลือกของ Microsoft ต่อ PDF พื้นฐานบน XML/HTML รักษาเลย์เอาต์ข้ามแพลตฟอร์มและไม่ขึ้นกับระบบปฏิบัติการ