You can read more at: Insert Text or Image in XPS File Programmatically using C++
Created
January 18, 2021 21:00
Insert Text or Image in XPS File Programmatically using C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create new XPS Document | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Add Image | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z")); | |
// Creating a matrix is optional, it 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(RunExamples::dataDir() + u"QL_logo_color.tif", System::Drawing::RectangleF(0.f, 0.f, 258.24f, 56.64f), System::Drawing::RectangleF(50.f, 20.f, 193.68f, 42.48f))); | |
// Save resultant XPS document | |
doc->Save(RunExamples::outDir() + u"AddImage_out.xps"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
//Create a brush | |
System::SharedPtr<XpsSolidColorBrush> textFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black()); | |
//Add glyph to the document | |
System::SharedPtr<XpsGlyphs> glyphs = doc->AddGlyphs(u"Arial", 12.0f, System::Drawing::FontStyle::Regular, 300.f, 450.f, u"Hello World!"); | |
glyphs->set_Fill(textFill); | |
// Save resultant XPS document | |
doc->Save(RunExamples::outDir() + u"AddText_out.xps"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Add Text | |
System::SharedPtr<XpsSolidColorBrush> textFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black()); | |
System::SharedPtr<XpsGlyphs> glyphs = doc->AddGlyphs(u"Arial", 20.0f, System::Drawing::FontStyle::Regular, 400.f, 200.f, u"++C. rof SPX.esopsA"); | |
glyphs->set_BidiLevel(1); | |
glyphs->set_Fill(textFill); | |
// Save resultant XPS document | |
doc->Save(RunExamples::outDir() + u"AddText_unicode.xps"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create new XPS Document | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Tile image | |
// ImageBrush filled rectangle in the right top bellow | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,160 L 228,160 228,305 10,305")); | |
path->set_Fill(doc->CreateImageBrush(RunExamples::dataDir() + u"R08LN_NN.jpg", System::Drawing::RectangleF(0.f, 0.f, 128.f, 96.f), System::Drawing::RectangleF(0.f, 0.f, 64.f, 48.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsImageBrush>(path->get_Fill()))->set_TileMode(Aspose::Page::Xps::XpsModel::XpsTileMode::Tile); | |
path->get_Fill()->set_Opacity(0.5f); | |
// Save resultant XPS document | |
doc->Save(RunExamples::outDir() + u"AddTiledImage_out.xps"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment