翻譯|使用教程|編輯:李顯亮|2020-03-25 10:03:06.853|閱讀 464 次
概述:spose.Page for C ++是一個本機C ++庫,用于創建新的PostScript和XPS文件以及以編程方式修改和轉換現有文件。本文演示了如何使用Aspose.Page for C ++執行與PostScript和XPS文檔有關的以下操作。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
XPS是工作中常用的一種微軟的文檔保存和查看格式,針對XPS、EPS格式的管理控件Aspose.Page已經推出C++版,將能夠在基于C ++的應用程序中以編程方式創建,讀取,編輯,保存和轉換XPS文檔,該API還允許您處理XPS文檔中的頁面和元素,例如畫布和字形。此外,它支持將文檔轉換為PDF和光柵圖像。。你可以點擊下方按鈕下載測試體驗。
與此同時,.NET版和Java版Aspose.Page已更新至v20.3最新版,修復將圖像添加到XPS文件時發生的異常,點擊下方按鈕下載試用。
下載最新版Aspose.Page for .NET 下載最新版Aspose.Page for java
本文演示了如何使用Aspose.Page for C ++執行與PostScript和XPS文檔有關的以下操作。
以下是使用Aspose.Page for C ++創建包含文本和圖像的XPS文檔的簡單步驟。
創建XpsDocument類的對象。
分別使用XpsGlyphs和XpsPath對象添加文本和圖像。
使用保存方法保存文檔。
下面的代碼示例演示如何使用C ++創建XPS文檔。
// Create a new XpsDocument object auto doc = System::MakeObject<XpsDocument>(); // Add Image System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 30,20 l 450.24,0 0,150.64 -350.24,0 Z")); // Create a matrix that can be used for proper positioning. path->set_RenderTransform(doc->CreateMatrix(0.7f, 0.f, 0.f, 0.7f, 0.f, 20.f)); // Create Image Brush path->set_Fill(doc->CreateImageBrush(u"QL_logo_color.tif", System::Drawing::RectangleF(0.f, 0.f, 450.24f, 150.64f), System::Drawing::RectangleF(50.f, 20.f, 450.68f, 150.48f))); // Text as footer System::SharedPtr<XpsSolidColorBrush> textFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black()); System::SharedPtr<XpsGlyphs> glyphs = doc->AddGlyphs(u"Arial", 18.0f, System::Drawing::FontStyle::Regular, 40.f, 1015.f, u"Copyright © 2006 QualityLogic, Inc."); glyphs->set_Fill(textFill); glyphs = doc->AddGlyphs(u"Arial", 15.0f, System::Drawing::FontStyle::Regular, 475.f, 1003.f, u"For information on QualityLogic XPS test products,"); glyphs->set_Fill(textFill); // Save as XPS doc->Save(u"Create-XPS.xps");
輸出結果
以下是編輯現有XPS文檔的步驟:
創建XpsDocument類的對象,并使用XPS文檔的路徑對其進行初始化。
使用XpsDocument對象訪問文檔的元素。
使用保存方法保存更新的文檔。
下面的代碼示例演示如何使用C ++編輯現有的XPS文檔。
// Load XPS Document auto doc = System::MakeObject(u"Created-XPS.xps"); // Add empty page at end of pages list doc->AddPage(); // Insert an empty page at beginning of pages list doc->InsertPage(1, true); // Save XPS file doc->Save(u"Updated-XPS.xps");
Aspose.Page for C ++還允許您在XPS文檔中添加頁面以及多個文檔。以下是創建新XPS文檔并添加其他頁面和文檔的步驟。
創建XpsDocument類的對象。
使用AddPage和AddDocument方法分別添加頁面和文檔。
使用SelectActiveDocument方法選擇要處理的活動文檔。
在文檔中添加文本或圖像。
保存文檔。
下面的代碼示例演示如何使用C ++將其他頁面和文檔添加到XPS。
// New document (1 fixed document with 1 default size page) auto doc = System::MakeObject(); // Add 2nd page on 1st document and set active doc->AddPage(); // Add 2nd document with 1 page (3rd page in file) doc->AddDocument(false); // 1st document's 2nd page is still active System::SharedPtrtextFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black()); System::SharedPtrglyphs = doc->AddGlyphs(u"Arial", 12.0f, System::Drawing::FontStyle::Regular, 200.f, 500.f, u"Text on Page 2 (Document 1),"); glyphs->set_Fill(textFill); // Activate 2nd document doc->SelectActiveDocument(2); glyphs = doc->AddGlyphs(u"Arial", 12.0f, System::Drawing::FontStyle::Regular, 200.f, 500.f, u"Text on Document 2 (Page #3 in file),"); glyphs->set_Fill(textFill); // Save XPS file doc->Save(u"Create-XPS.xps");還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn