与此同时,.NET版和Java版Aspose.Page已更新至v20.3最新版,修复将图像添加到XPS文件时发生的异常,点击下方按钮下载试用。

                      

  • 用C ++创建一个新的XPS文档
  • 将页面或文档添加到C ++中的XPS文档中

用C ++创建XPS文档

以下是使用Aspose.Page for C ++创建包含文本和图像的XPS文档的简单步骤。

  • 创建XpsDocument类的对象。

  • 分别使用XpsGlyphs和XpsPath对象添加文本和图像。

  • 使用保存方法保存文档。

下面的代码示例演示如何使用C ++创建XPS文档。

// Create a new XpsDocument objectauto doc = System::MakeObject<XpsDocument>();// Add ImageSystem::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 Brushpath->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 footerSystem::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 &#xa9; 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 XPSdoc->Save(u"Create-XPS.xps");

输出结果

  • 创建XpsDocument类的对象,并使用XPS文档的路径对其进行初始化。

  • 使用XpsDocument对象访问文档的元素。

  • 使用保存方法保存更新的文档。

// Load XPS Documentauto doc = System::MakeObject(u"Created-XPS.xps");// Add empty page at end of pages listdoc->AddPage();// Insert an empty page at beginning of pages listdoc->InsertPage(1, true);// Save XPS filedoc->Save(u"Updated-XPS.xps");

在C ++中将页面和文档添加到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 activedoc->AddPage();// Add 2nd document with 1 page (3rd page in file)doc->AddDocument(false);// 1st document's 2nd page is still activeSystem::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 documentdoc->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 filedoc->Save(u"Create-XPS.xps");

还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月22日
下一篇 2020年1月22日

相关推荐

发表回复

登录后才能评论