العمليات عبر الحزم داخل حزمة XPS

معالجة الصفحات والألوان والصور الرمزية (النقوش) داخل حزمة XPS عبر C++

 

تُقدّم واجهة برمجة تطبيقات Aspose.Page لـ C++ مكتبة منفصلة للعمل مع ملفات XPS، مما يُتيح لك التعامل معها كتنسيق مميز. تفتخر هذه المكتبة بمجموعة متنوعة من الميزات المفيدة، بما في ذلك دمج مستندات XPS، وتحويلها إلى تنسيقات أخرى، ومعالجة الرسومات بداخلها.

أحد الجوانب الرئيسية لملفات XPS هو قدرتها على احتواء ملفات متعددة داخل مستند واحد. ونتيجة لذلك، توفر مكتبة Aspose.Page XPS وظائف لإدارة هذه الملفات الداخلية وصفحاتها. هذه العمليات، المعروفة باسم "العمليات عبر الحزم (cross-package operations)"، تتضمن معالجة المحتوى عبر مستندات XPS المختلفة.

سيتعمق هذا القسم في أمثلة محددة للعمليات عبر الحزم، مثل إدارة الصفحات داخل مستند XPS واحد وإضافة نص (صور رمزية - glyphs) بألوان محددة.

ولكن لتجربة الوظيفة، تحتاج أولاً إلى الحصول على الحل:

  • افتح مدير حزم NuGet، وابحث عن Aspose.Page وقم بتثبيته. يمكنك أيضاً استخدام الأمر التالي من وحدة تحكم مدير الحزم.

خطوات معالجة الصفحات داخل حزمة XPS C++.

  1. قم بتعيين المسار إلى دليل المستندات.
  2. قم بإنشاء ملف XPS باستخدام فئة XpsDocument .
  3. لإدراج صفحة نشطة من مستند إلى بداية مستند آخر، استخدم طريقة InsertPage() .
  4. لإدراج صفحة نشطة من مستند إلى نهاية مستند آخر، استخدم طريقة AddPage() .
  5. لإزالة صفحة فارغة، استخدم طريقة RemovePage() .
  6. لإزالة صفحة من مستند إلى مستند آخر، استخدم طريقتي InsertPage() و SelectActivePage() .
  7. احفظ مستندات 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++.

  1. قم بتعيين المسار إلى دليل المستندات.
  2. افتح تدفقاً لملف XPS.
  3. قم بإنشاء ملف XPS باستخدام فئة XpsDocument.
  4. أضف الصور الرمزية (glyphs) إلى المستند باستخدام طريقة AddGlyphs() .
  5. قم بإنشاء ملف XPS الثاني باستخدام فئة XpsDocument.
  6. لاستنساخ (استنساخ) الصورة الرمزية من الملف الأول إلى الملف الثاني، استخدم طريقتي Add() و Clone() .
  7. احفظ كلا مستندي 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>();
    
    // 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++.

  1. قم بتعيين المسار إلى دليل المستندات.
  2. افتح تدفقاً لملف XPS.
  3. قم بإنشاء ملف XPS باستخدام فئة XpsDocument.
  4. أضف صوراً رمزية إلى المستند باستخدام طريقة AddGlyphs().
  5. لتعبئة الصور الرمزية بفرشاة صورة، استخدم طريقة CreateImageBrush() .
  6. قم بإنشاء ملف XPS الثاني باستخدام فئة XpsDocument.
  7. أضف صوراً رمزية بالخط من المستند الأول إلى المستند الثاني باستخدام طريقة AddGlyphs().
  8. قم بإنشاء فرشاة صورة من تعبئة المستند الأول وقم بتعبئة الصور الرمزية في المستند الثاني باستخدام طريقة CreateImageBrush().
  9. احفظ كلا مستندي 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>();
    
    // 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) يشبه PDF من حيث كونه تنسيقاً مستقلاً عن النظام. يُنشأ باستخدام HTML وXML، ويُحافظ على مظهر المستند عبر مختلف الأنظمة.