XPS是工作中常用的一种微软的文档保存和查看格式,
本文演示了如何使用Aspose.Page for C ++执行与PostScript和XPS文档有关的以下操作。
用C ++创建一个新的XPS文档在C ++中编辑现有的XPS文档将页面或文档添加到C ++中的XPS文档中用C ++创建XPS文档
以下是使用Aspose.Page for C ++创建包含文本和图像的XPS文档的简单步骤。
创建XpsDocument类的对象。分别使用XpsGlyphs和XpsPath对象添加文本和图像。使用保存方法保存文档。下面的代码示例演示如何使用C ++创建XPS文档。
<code>// 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");/<xpsglyphs>/<xpssolidcolorbrush>/<xpspath>/<xpsdocument>/<code>
输出结果
下面的代码示例演示如何使用C ++编辑现有的XPS文档。
<code>// 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");/<code>
在C ++中将页面和文档添加到XPS
Aspose.Page for C ++还允许您在XPS文档中添加页面以及多个文档。以下是创建新XPS文档并添加其他页面和文档的步骤。
下面的代码示例演示如何使用C ++将其他页面和文档添加到XPS。
<code>// 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");/<code>
如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),我们很高兴为您提供查询和咨询。