العمل مع اللوحات

قص وتحويل اللوحات القماشية لملفات XPS

 

تعد إدارة Canvas في المستندات إحدى الميزات التي يوفرها Aspose.Page لـ .NET. هذا حل للعمل مع لغات وصف الصفحة المختلفة ، XPS XPS على وجه التحديد. في المثال أدناه سوف تتعرف على كيفية:

  • قم بإنشاء لوحة قماشية في ملف XPS.

  • قم بعمل تعويضات أعلى وأيسر في اللوحة الرئيسية.

  • أضف لوحة قماشية جديدة بتحويل مترجم إلى اللوحة الرئيسية.

  • أضف لوحة قماشية جديدة مع دوران حول نقطة تحول إلى اللوحة الرئيسية.

  • مقطع قماش. والعديد من المعالجات باستخدام اللوحات القماشية في ملفات XPS.

لتحويل اللوحات القماشية لملف XPS ، اتبع الدليل التالي:

  1. أنشئ ملف XPS باستخدام XpsDocument Class .
  2. قم بإنشاء اللوحة الرئيسية ، المشتركة لجميع عناصر الصفحة باستخدام طريقة AddCanvas() .
  3. قم بعمل إزاحات يسرى وأعلى في اللوحة الرئيسية باستخدام طريقة CreateMatrix() .
  4. أنشئ هندسة مسار مستطيل باستخدام طريقة CreatePathGeometry() .
  5. قم بإنشاء تعبئة للمستطيلات عن طريق فئة XpsBrush .
  6. لإنشاء مستطيل في لوحة الرسم 2 وتعبئته ، استخدم فئة XpsPath .
  7. لترجمة لوحة الرسم 3 لوضع مستطيل جديد أسفل المستطيل السابق ، استخدم طريقة CreateMatrix() .
  8. لترجمة لوحة الرسم هذه إلى الجانب الأيمن من الصفحة ، استخدم طريقة Translate() .
  9. لتوسيع نطاق اللوحة 4 ، استدع الأسلوب Scale() .
  10. لتدوير قماش الرسم 5 حول نقطة 45 درجة ، يتم تنفيذ طريقة RotateAround() في متناول اليد.
  11. احفظ مستند XPS الذي تم تغييره باستخدام طريقة XPsDocument.Save() .

ملف XPS Canvas Transformation C# code

    using Aspose.Page.Xps;
    using Aspose.Page.Xps.XpsModel;
    using System.Drawing;
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 200,0 200,100 0,100 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add new canvas without any transformations to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();
    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with translate transformation to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas3.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 200);
    // Translate this canvas to the right side of the page
    canvas3.RenderTransform.Translate(500, 0);
    // Create the rectangle in this canvas and fill it
    rect = canvas3.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with the double scale transformation to the main canvas
    XpsCanvas canvas4 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas4.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 400);
    // Scale this canvas
    canvas4.RenderTransform.Scale(2, 2);
    // Create a rectangle in this canvas and fill it
    rect = canvas4.AddPath(rectGeom);
    rect.Fill = fill;

    // Add new canvas with rotation around a point transformation to the main canvas
    XpsCanvas canvas5 = canvas1.AddCanvas();
    // Translate this canvas to position new rectangle below the previous rectnagle
    canvas5.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 0, 800);
    // Rotate this canvas aroud a point on 45 degrees
    canvas5.RenderTransform.RotateAround(45, new PointF(100, 50));
    rect = canvas5.AddPath(rectGeom);
    rect.Fill = fill;
            
    // Save the resultant XPS document
    doc.Save(dataDir + "output1.xps");
يوضح مقتطف الكود التالي كيفية قص اللوحات القماشية لملفات XPS داخل Aspose.Page لـ .NET Api Solution.

لقص اللوحات القماشية لملف XPS ، اتبع الدليل التالي:

  1. قم بإنشاء أو فتح ملف XPS باستخدام XpsDocument Class.
  2. قم بإنشاء اللوحة الرئيسية ، المشتركة لجميع عناصر الصفحة باستخدام طريقة AddCanvas() .
  3. قم بعمل إزاحات يسرى وأعلى في اللوحة الرئيسية باستخدام طريقة CreateMatrix() .
  4. أنشئ هندسة مسار مستطيل باستخدام طريقة CreatePathGeometry() .
  5. قم بإنشاء تعبئة للمستطيلات عن طريق فئة XpsBrush .
  6. لإضافة لوحة قماشية أخرى بمقطع إلى اللوحة الرئيسية ، قم باستدعاء طريقة AddCanvas() مرة أخرى.
  7. أنشئ هندسة دائرية للمقطع باستخدام فئة XpsPathGeometry .
  8. لإنشاء مستطيل في لوحة الرسم هذه وتعبئته ، استخدم فئة XpsPath .
  9. أضف لوحة قماشية أخرى باستخدام طريقة AddCanvas() ثم أنشئ مستطيلًا في لوحة الرسم هذه وقم بضربها باستخدام فئة XpsPathGeometry.
  10. احفظ مستند XPS الذي تم تغييره باستخدام طريقة XPsDocument.Save().

XPS قماشية لقص كود C#

    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_WorkingWithCanvas();
            
    // Create a new XPS Document
    XpsDocument doc = new XpsDocument();

    // Create main canvas, common for all page elemnts
    XpsCanvas canvas1 = doc.AddCanvas();

    // Make left and top offsets in the main canvas
    canvas1.RenderTransform = doc.CreateMatrix(1, 0, 0, 1, 20, 10);

    // Create the rectangle path geometry
    XpsPathGeometry rectGeom = doc.CreatePathGeometry("M 0,0 L 500,0 500,300 0,300 Z");

    // Create a fill for rectangles
    XpsBrush fill = doc.CreateSolidColorBrush(doc.CreateColor(12, 15, 159));
            
    // Add another canvas with the clip to the main canvas
    XpsCanvas canvas2 = canvas1.AddCanvas();

    // Create circle geometry for the clip
    XpsPathGeometry clipGeom = doc.CreatePathGeometry("M250,250 A100,100 0 1 1 250,50 100,100 0 1 1 250,250");
    canvas2.Clip = clipGeom;

    // Create rectangle in this canvas and fill it
    XpsPath rect = canvas2.AddPath(rectGeom);
    rect.Fill = fill;

    // Add the second canvas with stroked rectangle to the main canvas
    XpsCanvas canvas3 = canvas1.AddCanvas();

    // Create rectangle in this canvas and stroke it
    rect = canvas3.AddPath(rectGeom);
    rect.Stroke = fill;
    rect.StrokeThickness = 2;

    // Save resultant XPS document
    doc.Save(dataDir + "output2.xps");



التعليمات

1. كيف يمكنني إضافة لوحة قماشية إلى ملف XPS؟

قم بتعيين المسار إلى دليل المستندات. لإضافة لوحات قماشية، استخدم طريقة AddCanvas().

2. كيفية التعامل مع إزاحات اللوحة القماشية في ملف XPS؟

قم بتعيين المسار إلى دليل المستندات وأضف اللوحات. استخدم طريقة CreateMatrix() لإجراء الإزاحات.

3. ما هي العمليات التي يتم دعمها باستخدام اللوحات القماشية في ملف XPS؟

يمكنك إنشاء لوحة قماشية وقصها وإضافتها بالإضافة إلى معالجة إزاحاتها.

XPS ما هو XPS تنسيق الملف

تنسيق XPS مشابه لتنسيق PDF. كلاهما عبارة عن تنسيقات لغة وصف الصفحة (PDL). يعتمد EPS على HTML وليس على لغة PostScript. يمكن أن يحتوي ملف .eps على ترميز لهيكل المستند بالإضافة إلى معلومات حول الشكل الذي سيبدو عليه المستند. هناك أيضًا إرشادات مضافة حول كيفية طباعة المستند وتقديمه. تتمثل ميزة التنسيق في أنه يعمل على إصلاح وصف المستند مما يعني أنه سيبدو كما هو بغض النظر عن من ومن أي نظام تشغيل يفتحه.