การดำเนินการข้ามแพ็คเกจภายในแพ็คเกจ XPS

จัดการหน้า สี และร่ายมนตร์ภายในแพ็คเกจ XPS ผ่าน C#

 

โซลูชัน Aspose.Page API สำหรับ .NET ในรูปแบบอื่นๆ รวมถึงแพ็คเกจ XPS เป็นไลบรารีแยกต่างหากเพื่อทำงานกับไฟล์ XPS ฟังก์ชันที่หลากหลายประกอบด้วยคุณสมบัติที่มีประโยชน์และเป็นที่นิยมมากมาย เช่น การรวมไฟล์ การแปลง การทำงานกับกราฟิก ฯลฯ

XPS สามารถเก็บไฟล์ได้หลายไฟล์ในเอกสารเดียว ดังนั้นแพ็คเกจ XPS ใด ๆ ควรมีฟังก์ชันในการจัดการไฟล์เหล่านั้นและหน้าเว็บภายในเอกสารและระหว่างเอกสาร XPS ต่างๆ การจัดการดังกล่าวเรียกว่าการดำเนินการข้ามแพ็คเกจ ควรอธิบายแยกกัน

คุณจะพบตัวอย่างการดำเนินการข้ามแพ็คเกจ เช่น การปรับแต่งหน้า การเพิ่มสัญลักษณ์และสี

ขั้นตอนในการจัดการเพจภายใน XPS Package 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");

ขั้นตอนในการเพิ่ม glyph clone ภายใน XPS Package C#

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. เปิดสตรีมของไฟล์ XPS
  3. สร้างไฟล์ XPS โดยใช้ XpsDocument Class
  4. เพิ่มร่ายมนตร์ลงในเอกสารโดยใช้วิธีการ AddGlyphs()
  5. สร้างไฟล์ XPS ไฟล์ที่สองโดยใช้ XpsDocument Class
  6. ในการโคลนสัญลักษณ์จากไฟล์แรกไปยังไฟล์ที่สอง ให้ใช้ Add() และ Clone() วิธีการ
  7. บันทึกเอกสาร XPS ทั้งสองโดยใช้เมธอด XPsDocument.Save()

รหัส C# เพื่อคัดลอก glyth ภายใน XPS Package

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

ขั้นตอนในการเพิ่ม Glyph C# ที่เต็มไปด้วยรูปภาพ

  1. กำหนดเส้นทางไปยังไดเร็กทอรีเอกสาร
  2. เปิดสตรีมของไฟล์ XPS
  3. สร้างไฟล์ XPS โดยใช้ XpsDocument Class
  4. เพิ่มร่ายมนตร์ให้กับเอกสารโดยใช้วิธีการ AddGlyphs()
  5. ในการเติมร่ายมนตร์ด้วยแปรงรูปภาพ ให้ใช้วิธีการ CreateImageBrush()
  6. สร้างไฟล์ XPS ไฟล์ที่สองโดยใช้ XpsDocument Class
  7. เพิ่มร่ายมนตร์ด้วยแบบอักษรจากเอกสารแรกไปยังเอกสารที่สองโดยใช้วิธีการ AddGlyphs()
  8. สร้างแปรงรูปภาพจากการเติมเอกสารแรกและเติมร่ายมนตร์ในเอกสารที่สองโดยใช้วิธีการ CreateImageBrush()
  9. บันทึกเอกสาร XPS ทั้งสองด้วยวิธีการ XPsDocument.Save() Method

รหัส 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 Package เป็นไลบรารีแยกต่างหากสำหรับจัดการไฟล์ XPS ใช้เพื่อสร้างตัวแปลง โปรแกรมอ่าน หรือแอปอื่นๆ ของคุณเองเพื่อแก้ไข XPS

2. ฉันจะรับแพ็คเกจ XPS ได้อย่างไร

แพ็คเกจ XPS รวมอยู่ในโซลูชัน Aspose.Page

3. มีการดำเนินการข้ามแพ็คเกจอะไรบ้าง?

การใช้ Aspose XPS Package ทำให้คุณสามารถถ่ายโอนหน้าจากเอกสารหนึ่งไปยังอีกเอกสารหนึ่ง โคลนออบเจ็กต์ เช่น สัญลักษณ์ สไตล์ หรือการตั้งค่า

4. วิธีจัดการหน้าระหว่างเอกสาร XPS

หากต้องการถ่ายโอนไฟล์ด้วยแพ็คเกจ XPS นี้ ให้ใช้เมธอด InsertPage(), AddPage(), RemovePage() และ SelectActivePage() ของคลาส XpsDocument

XPS XPS รูปแบบไฟล์คืออะไร

รูปแบบ XPS คล้ายกับรูปแบบ PDF ทั้งสองรูปแบบเป็นภาษาคำอธิบายหน้า (PDL) EPS อิงตาม HTML ไม่ใช่ภาษา PostScript ไฟล์ .eps สามารถใส่มาร์กอัปของโครงสร้างของเอกสารพร้อมกับข้อมูลเกี่ยวกับลักษณะของเอกสารได้ นอกจากนี้ยังมีคำแนะนำเพิ่มเติมเกี่ยวกับวิธีการพิมพ์และแสดงผลเอกสาร คุณสมบัติของรูปแบบคือ แก้ไขคำอธิบายของเอกสาร ซึ่งหมายความว่าจะมีลักษณะเหมือนกันไม่ว่าใครจะเปิดจากระบบปฏิบัติการใด