Các thao tác chéo gói trong XPS Package
Thao tác các trang, màu sắc và glyph trong XPS Package thông qua C#
Giải pháp Aspose.Page API cho .NET cùng với các định dạng khác bao gồm XPS Package như một thư viện riêng biệt để làm việc với các tệp XPS. Các chức năng phong phú của nó chứa nhiều tính năng hữu ích và phổ biến như hợp nhất tệp, chuyển đổi, làm việc với đồ họa, v.v.
XPS có thể chứa nhiều tệp trong một tài liệu. Vì vậy, bất kỳ XPS Package nào cũng phải có chức năng thao tác các tệp đó và các trang của chúng bên trong tài liệu và giữa các tài liệu XPS khác nhau. Những thao tác như vậy được gọi là thao tác chéo gói. Chúng nên được giải thích riêng biệt.
Tại đây bạn sẽ tìm thấy các ví dụ về các thao tác chéo gói như thao tác trang, thêm glyph và màu sắc.
Các bước thao tác trang trong XPS Package bằng C#.
- Thiết lập đường dẫn đến thư mục tài liệu.
- Tạo tệp XPS bằng Lớp XpsDocument .
- Để chèn một trang đang hoạt động từ tài liệu này vào đầu tài liệu khác, hãy sử dụng Phương thức InsertPage() .
- Để chèn một trang đang hoạt động từ tài liệu này vào cuối tài liệu khác, hãy sử dụng Phương thức AddPage() .
- Để xóa một trang trống, hãy sử dụng Phương thức RemovePage() .
- Để di chuyển một trang từ tài liệu này sang tài liệu khác, hãy sử dụng các Phương thức InsertPage() và SelectActivePage() .
- Lưu các tài liệu XPS đã thay đổi bằng cách sử dụng XPsDocument.Save .
Mã C# cho các thao tác chéo gói với trang
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");Các bước thêm bản sao glyph trong XPS Package bằng C#.
- Thiết lập đường dẫn đến thư mục tài liệu.
- Mở một luồng của tệp XPS.
- Tạo tệp XPS bằng Lớp XpsDocument.
- Thêm glyph vào tài liệu bằng Phương thức AddGlyphs() .
- Tạo tệp XPS thứ hai bằng Lớp XpsDocument.
- Để sao chép glyph từ tệp đầu tiên sang tệp thứ hai, hãy sử dụng các Phương thức Add() và Clone() .
- Lưu cả hai tài liệu XPS bằng Phương thức XPsDocument.Save().
Mã C# để sao chép một glyph trong 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");Các bước thêm Glyph được lấp đầy bằng hình ảnh bằng C#.
- Thiết lập đường dẫn đến thư mục tài liệu.
- Mở một luồng của tệp XPS.
- Tạo tệp XPS bằng Lớp XpsDocument.
- Thêm glyph vào tài liệu bằng Phương thức AddGlyphs().
- Để lấp đầy các glyph bằng một brush hình ảnh, hãy sử dụng Phương thức CreateImageBrush() .
- Tạo tệp XPS thứ hai bằng Lớp XpsDocument.
- Thêm glyph với phông chữ từ tài liệu đầu tiên vào tài liệu thứ hai bằng Phương thức AddGlyphs().
- Tạo một brush hình ảnh từ phần lấp đầy của tài liệu đầu tiên và lấp đầy glyph trong tài liệu thứ hai bằng Phương thức CreateImageBrush().
- Lưu cả hai tài liệu XPS bằng Phương thức XPsDocument.Save()
Mã C# để tạo Glyph được lấp đầy bằng hình ảnh trong 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 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");Câu hỏi thường gặp
1. Gói XPS là gì?
Gói XPS là một thư viện riêng để quản lý các tệp XPS. Sử dụng nó để tạo trình chuyển đổi, trình đọc hoặc ứng dụng khác của riêng bạn để chỉnh sửa XPS.
2. Làm cách nào tôi có thể nhận được Gói XPS?
Gói XPS được bao gồm trong Giải pháp Aspose.Page .
3. Những hoạt động gói chéo nào có sẵn?
Sử dụng Gói Aspose XPS, bạn có thể chuyển các trang từ tài liệu này sang tài liệu khác, sao chép các đối tượng như glyphs, kiểu hoặc cài đặt.
4. Làm cách nào để thao tác các trang giữa các tài liệu XPS?
Để truyền tệp bằng Gói XPS này, hãy sử dụng các phương thức InsertPage(), AddPage(), RemovePage() và SelectActivePage() của Lớp XpsDocument.
XPS Những gì là XPS Tập Tin Định Dạng
XPS (XML Paper Specification) là định dạng thay thế PDF của Microsoft, dựa trên XML/HTML, giữ nguyên bố cục trên mọi nền tảng và không phụ thuộc vào hệ điều hành.