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

التعامل مع الصفحات والألوان والرموز (Glyphs) داخل حزمة XPS عبر C#

 

يتضمن حل Aspose.Page API لـ .NET من بين تنسيقات أخرى حزمة XPS كمكتبة منفصلة للعمل مع ملفات XPS. تحتوي وظائفها الغنية على العديد من الميزات المفيدة والشائعة مثل دمج الملفات، والتحويل، والعمل مع الرسومات، وما إلى ذلك.

يمكن أن يحتوي مستند XPS واحد على عدة ملفات. لذا يجب أن تتمتع أي حزمة XPS بالقدرة على التعامل مع تلك الملفات وصفحاتها داخل المستند وبين مستندات XPS المختلفة. تسمى هذه التلاعبات بالعمليات المشتركة بين الحزم. وينبغي شرحها بشكل منفصل.

ستجد هنا أمثلة على مثل هذه العمليات المشتركة بين الحزم مثل التلاعب بالصفحات، وإضافة الرموز والألوان.

خطوات التعامل مع الصفحات داخل حزمة XPS باستخدام C#.

  1. حدد المسار إلى دليل المستندات.
  2. أنشئ ملف XPS باستخدام XpsDocument Class .
  3. لإدراج صفحة نشطة من مستند إلى بداية مستند آخر، استخدم طريقة InsertPage() .
  4. لإدراج صفحة نشطة من مستند إلى نهاية مستند آخر، استخدم طريقة AddPage() .
  5. لحذف صفحة فارغة، استخدم طريقة RemovePage() .
  6. لنقل صفحة من مستند إلى مستند آخر، استخدم طريقتي InsertPage() و SelectActivePage() .
  7. احفظ مستندات XPS المعدلة باستخدام XPsDocument.Save .

كود C# للتلاعب بالصفحات عبر الحزم

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

خطوات إضافة نسخة مطابقة من الرمز داخل حزمة XPS باستخدام C#.

  1. حدد المسار إلى دليل المستندات.
  2. افتح تياراً لملف XPS.
  3. أنشئ ملف XPS باستخدام XpsDocument Class.
  4. أضف رموزاً إلى المستند باستخدام طريقة AddGlyphs() .
  5. أنشئ ملف XPS الثاني باستخدام XpsDocument Class.
  6. لنسخ الرمز من الملف الأول إلى الملف الثاني، استخدم طريقتي Add() و Clone() .
  7. احفظ كلا مستندي XPS بواسطة طريقة XPsDocument.Save().

كود C# لنسخ رمز داخل حزمة 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");

خطوات إضافة رمز مملوء بصورة باستخدام C#.

  1. حدد المسار إلى دليل المستندات.
  2. افتح تياراً لملف XPS.
  3. أنشئ ملف XPS باستخدام XpsDocument Class.
  4. أضف رموزاً إلى المستند باستخدام طريقة AddGlyphs().
  5. لتعبئة الرموز بفرشاة صور، استخدم طريقة CreateImageBrush() .
  6. أنشئ ملف XPS الثاني باستخدام XpsDocument Class.
  7. أضف رموزاً بالخط من المستند الأول إلى المستند الثاني باستخدام طريقة AddGlyphs().
  8. أنشئ فرشاة صور من تعبئة المستند الأول وقم بتعبئة الرموز في المستند الثاني باستخدام طريقة CreateImageBrush().
  9. احفظ كلا مستندي XPS بواسطة طريقة XPsDocument.Save()

كود C# لإنشاء رمز مملوء بصورة داخل حزمة 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");



التعليمات

1. ما هي باقة XPS؟

تعد حزمة XPS مكتبة منفصلة لإدارة ملفات XPS. استخدمه لإنشاء المحولات أو القراء أو التطبيقات الأخرى الخاصة بك لتحرير XPS.

2. كيف يمكنني الحصول على باقة XPS؟

تم تضمين حزمة XPS في حل Aspose.Page .

3. ما هي العمليات المتاحة عبر الحزمة؟

باستخدام Aspose XPS Package، يمكنك نقل الصفحات من مستند إلى آخر، واستنساخ الكائنات مثل الحروف الرسومية، أو الأنماط، أو الإعدادات.

4. كيفية التعامل مع الصفحات بين مستندات XPS؟

لنقل الملفات باستخدام حزمة XPS هذه، استخدم أساليب InsertPage() وAddPage() وRemovePage() وSelectActivePage() الخاصة بفئة XpsDocument.

XPS What is XPS File Format

تنسيق XPS (XML Paper Specification) يشبه PDF من حيث كونه تنسيقاً مستقلاً عن النظام. يُنشأ باستخدام HTML وXML، ويُحافظ على مظهر المستند عبر مختلف الأنظمة.