Last active
January 19, 2021 07:26
-
-
Save aspose-com-gists/1128d967b432793ca43e26bceca820d0 to your computer and use it in GitHub Desktop.
This file contains 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
This gist contains code snippets for Aspose.Page for C++ API. |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Radial gradient stroked ellipse in the lower left | |
auto stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>(); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 0, 255), 0.f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 0, 0), .25f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 255, 0), .5f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 255, 0), .75f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 0, 0), 1.f)); | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 20,250 A 100,50 0 1 1 220,250 100,50 0 1 1 20,250")); | |
path->set_Stroke(doc->CreateRadialGradientBrush(System::Drawing::PointF(575.f, 125.f), System::Drawing::PointF(575.f, 100.f), 75.f, 50.f)); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Stroke()))->set_SpreadMethod(Aspose::Page::Xps::XpsModel::XpsSpreadMethod::Reflect); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Stroke()))->get_GradientStops()->AddRange(stops); | |
stops->Clear(); | |
path->set_StrokeThickness(12.f); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddEllipse_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Geometry for magenta grid VisualBrush | |
System::SharedPtr<XpsPathGeometry> pathGeometry = doc->CreatePathGeometry(); | |
pathGeometry->AddSegment(doc->CreatePolyLineSegment(System::MakeArray<System::Drawing::PointF>({ System::Drawing::PointF(240.f, 5.f), System::Drawing::PointF(240.f, 310.f), System::Drawing::PointF(0.f, 310.f) }))); | |
pathGeometry->idx_get(0)->set_StartPoint(System::Drawing::PointF(0.f, 5.f)); | |
// Canvas for magenta grid VisualBrush | |
System::SharedPtr<XpsCanvas> visualCanvas = doc->CreateCanvas(); | |
System::SharedPtr<XpsPath> visualPath = visualCanvas->AddPath(doc->CreatePathGeometry(u"M 0,4 L 4,4 4,0 6,0 6,4 10,4 10,6 6,6 6,10 4,10 4,6 0,6 Z")); | |
visualPath->set_Fill(doc->CreateSolidColorBrush(doc->CreateColor(1.f, .61f, 0.1f, 0.61f))); | |
System::SharedPtr<XpsPath> gridPath = doc->CreatePath(pathGeometry); | |
//Create Visual Brush, it is specified by some XPS fragment (vector graphics and glyphs) | |
gridPath->set_Fill(doc->CreateVisualBrush(visualCanvas, System::Drawing::RectangleF(0.f, 0.f, 10.f, 10.f), System::Drawing::RectangleF(0.f, 0.f, 10.f, 10.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsVisualBrush>(gridPath->get_Fill()))->set_TileMode(Aspose::Page::Xps::XpsModel::XpsTileMode::Tile); | |
// New canvas | |
System::SharedPtr<XpsCanvas> canvas = doc->AddCanvas(); | |
canvas->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 268.f, 70.f)); | |
// Add grid | |
canvas->AddPath(gridPath); | |
// Red transparent rectangle in the middle top | |
System::SharedPtr<XpsPath> path = canvas->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z")); | |
path = canvas->AddPath(doc->CreatePathGeometry(u"M 10,10 L 228,10 228,100 10,100")); | |
path->set_Fill(doc->CreateSolidColorBrush(doc->CreateColor(1.0f, 0.0f, 0.0f))); | |
path->set_Opacity(0.7f); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddGrid_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Initialize List of XpsGradentStop | |
System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>> stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>(); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 244, 253, 225), 0.0673828f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 251, 240, 23), 0.314453f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 252, 209, 0), 0.482422f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 241, 254, 161), 0.634766f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 53, 253, 255), 0.915039f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 12, 91, 248), 1.f)); | |
// Create new path by defining geometery in abbreviation form | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,210 L 228,210 228,300 10,300")); | |
path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f)); | |
path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 0.f), System::Drawing::PointF(228.f, 0.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddHorizontalGradient_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// 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(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(outDir() + u"AddImage_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Initialize List of XpsGradentStop | |
System::SharedPtr<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>> stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>(); | |
// Add Colors to Gradient | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 142, 4), 0.f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 202, 0), 0.144531f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 250, 0), 0.264648f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(255, 0, 0), 0.414063f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(233, 0, 255), 0.544922f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(107, 27, 190), 0.694336f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(63, 0, 255), 0.844727f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(0, 199, 80), 1.f)); | |
// Create new path by defining geometery in abbreviation form | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,10 L 228,10 228,100 10,100")); | |
path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f)); | |
path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 10.f), System::Drawing::PointF(228.f, 100.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddLinearGradient_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(dataDir() + u"Sample1.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 resultant XPS document | |
doc->Save(outDir() + u"AddPages_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// CMYK (blue) solid color stroked rectangle in the lower left | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 20,10 L 220,10 220,100 20,100 Z")); | |
path->set_Stroke(doc->CreateSolidColorBrush(doc->CreateColor(dataDir() + u"uswebuncoated.icc", System::MakeArray<float>({ 1.0f, 1.000f, 0.000f, 0.000f, 0.000f })))); | |
path->set_StrokeThickness(12.f); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddRectangle_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// 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(outDir() + u"AddText_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// 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(outDir() + u"AddText_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// 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(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(outDir() + u"AddTiledImage_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Just to demonstrate transparency | |
doc->AddPath(doc->CreatePathGeometry(u"M120,0 H400 v1000 H120"))->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Gray())); | |
doc->AddPath(doc->CreatePathGeometry(u"M300,120 h600 V420 h-600"))->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Gray())); | |
// Create path with closed rectangle geometry | |
System::SharedPtr<XpsPath> path1 = doc->CreatePath(doc->CreatePathGeometry(u"M20,20 h200 v200 h-200 z")); | |
// Set blue solid brush to fill path1 | |
path1->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
// Add it to the current page | |
System::SharedPtr<XpsPath> path2 = doc->Add(path1); | |
// path1 and path2 are the same as soon as path1 hasn't been placed inside any other element | |
// (which means that path1 had no parent element). | |
// Because of that rectangle's color on the page effectively turns to green | |
path2->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Green())); | |
// Now add path2 once again. Now path2 has parent. So path3 won't be the same as path2. | |
// Thus a new rectangle is painted on the page ... | |
System::SharedPtr<XpsPath> path3 = doc->Add(path2); | |
// ... and we shift it 300 units lower ... | |
path3->set_RenderTransform(doc->CreateMatrix(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 300.0f)); | |
// ... and set red solid brush to fill it | |
path3->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Red())); | |
// Create new path4 with path2's geometry ... | |
System::SharedPtr<XpsPath> path4 = doc->AddPath(path2->get_Data()); | |
// ... shift it 300 units to the right ... | |
path4->set_RenderTransform(doc->CreateMatrix(1.0f, 0.0f, 0.0f, 1.0f, 300.0f, 0.0f)); | |
// ... and set blue solid fill | |
path4->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
// Add path4 once again. | |
System::SharedPtr<XpsPath> path5 = doc->Add(path4); | |
// path4 and path5 are not the same again ... | |
// (move path5 300 units lower) | |
path5->set_RenderTransform(path5->get_RenderTransform()->Clone()); | |
// to disconnect RenderTransform value from path4 (see next comment about Fill property) | |
path5->get_RenderTransform()->Translate(0.0f, 300.0f); | |
// ... but if we set the opacity of Fill property, it will take effect on both path5 and path4 | |
// because brush is a complex property value which remains the same for path5 and path4 | |
path5->get_Fill()->set_Opacity(0.8f); | |
// Create new path6 with path2's geometry ... | |
System::SharedPtr<XpsPath> path6 = doc->AddPath(path2->get_Data()); | |
// ... shift it 600 units to the right ... | |
path6->set_RenderTransform(doc->CreateMatrix(1.0f, 0.0f, 0.0f, 1.0f, 600.0f, 0.0f)); | |
// ... and set yellow solid fill | |
path6->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Yellow())); | |
// Now add path6's clone ... | |
System::SharedPtr<XpsPath> path7 = doc->Add(path6->Clone()); | |
// (move path5 300 units lower) | |
path7->set_RenderTransform(path7->get_RenderTransform()->Clone()); | |
path7->get_RenderTransform()->Translate(0.0f, 300.0f); | |
// ... and set opacity for path7 | |
path7->get_Fill()->set_Opacity(0.8f); | |
// Now opacity effects independantly as soon as property values are cloned along with the element | |
// The following code block is equivalent to the previous one. | |
// Add path6 itself. path6 and path7 are not the same. Although their Fill property values are the same | |
//XpsPath path7 = doc.Add(path6); | |
//path7.RenderTransform = path7.RenderTransform.Clone(); | |
//path7.RenderTransform.Translate(0, 300); | |
// To "disconnect" path7's Fill property from path6's Fill property reassign it to its clone (or path6's Fill clone) | |
//path7.Fill = ((XpsSolidColorBrush)path7.Fill).Clone(); | |
//path7.Fill.Opacity = 0.8f; | |
// Save resultant XPS document | |
doc->Save(outDir() + u"WorkingWithTransparency_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
auto doc = System::MakeObject<XpsDocument>(); | |
// Initialize List of XpsGradentStop | |
auto stops = System::MakeObject<System::Collections::Generic::List<System::SharedPtr<XpsGradientStop>>>(); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(253, 255, 12, 0), 0.f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 154, 0), 0.359375f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 56, 0), 0.424805f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(253, 255, 229, 0), 0.879883f)); | |
stops->Add(doc->CreateGradientStop(doc->CreateColor(252, 255, 255, 234), 1.f)); | |
// Create new path by defining geometery in abbreviation form | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 10,110 L 228,110 228,200 10,200")); | |
path->set_RenderTransform(doc->CreateMatrix(1.f, 0.f, 0.f, 1.f, 20.f, 70.f)); | |
path->set_Fill(doc->CreateLinearGradientBrush(System::Drawing::PointF(10.f, 110.f), System::Drawing::PointF(10.f, 200.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsGradientBrush>(path->get_Fill()))->get_GradientStops()->AddRange(stops); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"AddVerticalGradient_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
System::SharedPtr<License> license = System::MakeObject<License>(); | |
// This line attempts to set a license from several locations relative to the executable and Aspose.Page.dll. | |
// You can also use the additional overload to load a license from a stream, this is useful for instance when the | |
// license is stored as an embedded resource | |
try | |
{ | |
license->SetLicense(u"Aspose.Page.Cpp.lic"); | |
std::cout << "License set successfully." << std::endl; | |
} | |
catch (System::Exception& e) | |
{ | |
// We do not ship any license with this example, visit the Aspose site to obtain either a temporary or permanent license. | |
std::cout << "There was an error setting the license: " << e->get_Message().ToUtf8String() << std::endl; | |
} |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
System::SharedPtr<License> license = System::MakeObject<License>(); | |
try | |
{ | |
// Initializes a license from a stream | |
System::SharedPtr<System::IO::MemoryStream> stream = System::MakeObject<System::IO::MemoryStream>(System::IO::File::ReadAllBytes(u"Aspose.Words.Cpp.lic")); | |
license->SetLicense(stream); | |
std::cout << "License set successfully." << std::endl; | |
} | |
catch (System::Exception& e) | |
{ | |
// We do not ship any license with this example, visit the Aspose site to obtain either a temporary or permanent license. | |
std::cout << "There was an error setting the license: " << e->get_Message().ToUtf8String() << std::endl; | |
} | |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Initialize PDF output stream | |
System::SharedPtr<System::Drawing::Imaging::ImageFormat> imageFormat = System::Drawing::Imaging::ImageFormat::get_Png(); | |
// Initialize PostScript input stream | |
System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir() + u"inputForImage.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream); | |
// If you want to convert Postscript file despite of minor errors set this flag | |
bool suppressErrors = true; | |
//Initialize options object with necessary parameters. | |
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(suppressErrors); | |
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({ u"{FONT_FOLDER}" })); | |
// Default image format is PNG and it is not mandatory to set it in ImageDevice | |
// Default image size is 595x842 and it is not mandatory to set it in ImageDevice | |
System::SharedPtr<Aspose::Page::EPS::Device::ImageDevice> device = System::MakeObject<Aspose::Page::EPS::Device::ImageDevice>(); | |
// But if you need to specify size and image format use constructor with parameters | |
//ImageDevice device = new ImageDevice(new System.Drawing.Size(595, 842), System.Drawing.Imaging.ImageFormat.Jpeg); | |
{ | |
auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream]() | |
{ | |
psStream->Close(); | |
}); | |
try | |
{ | |
document->Save(device, options); | |
} | |
catch (...) | |
{ | |
throw; | |
} | |
} | |
System::ArrayPtr<System::ArrayPtr<uint8_t>> imagesBytes = device->get_ImagesBytes(); | |
int32_t i = 0; | |
{ | |
for (System::ArrayPtr<uint8_t> imageBytes : imagesBytes) | |
{ | |
System::String imagePath = System::IO::Path::GetFullPath(outDir() + System::String(u"out_image") + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(imageFormat).ToLower()); | |
{ | |
System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ fs }); | |
// ------------------------------------------ | |
try | |
{ | |
fs->Write(imageBytes, 0, imageBytes->get_Length()); | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} | |
i++; | |
} | |
} |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Initialize PDF output stream | |
System::SharedPtr<System::IO::FileStream> pdfStream = System::MakeObject<System::IO::FileStream>(outDir() + u"outputPDF_out.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Initialize PostScript input stream | |
System::SharedPtr<System::IO::FileStream> psStream = System::MakeObject<System::IO::FileStream>(dataDir() + u"input.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(psStream); | |
// If you want to convert Postscript file despite of minor errors set this flag | |
bool suppressErrors = true; | |
//Initialize options object with necessary parameters. | |
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors); | |
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({ u"{FONT_FOLDER}" })); | |
// Default page size is 595x842 and it is not mandatory to set it in PdfDevice | |
System::SharedPtr<Aspose::Page::EPS::Device::PdfDevice> device = System::MakeObject<Aspose::Page::EPS::Device::PdfDevice>(pdfStream); | |
// But if you need to specify size and image format use following line | |
//Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new System.Drawing.Size(595, 842)); | |
{ | |
auto __finally_guard_0 = ::System::MakeScopeGuard([&psStream, &pdfStream]() | |
{ | |
psStream->Close(); | |
pdfStream->Close(); | |
}); | |
try | |
{ | |
document->Save(device, options); | |
} | |
catch (...) | |
{ | |
throw; | |
} | |
} |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Create new XPS Document | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
//Add Canvas to XpsDocument instance | |
System::SharedPtr<XpsCanvas> canvas = doc->AddCanvas(); | |
// Rectangle with opacity masked by ImageBrush | |
System::SharedPtr<XpsPath> path = canvas->AddPath(doc->CreatePathGeometry(u"M 10,180 L 228,180 228,285 10,285")); | |
path->set_Fill(doc->CreateSolidColorBrush(doc->CreateColor(1.0f, 0.0f, 0.0f))); | |
path->set_OpacityMask(doc->CreateImageBrush(dataDir() + u"R08SY_NN.tif", System::Drawing::RectangleF(0.f, 0.f, 128.f, 192.f), System::Drawing::RectangleF(0.f, 0.f, 64.f, 96.f))); | |
(System::DynamicCast<Aspose::Page::Xps::XpsModel::XpsImageBrush>(path->get_OpacityMask()))->set_TileMode(Aspose::Page::Xps::XpsModel::XpsTileMode::Tile); | |
// Save resultant XPS document | |
doc->Save(outDir() + u"OpacityMask_out.xps"); |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Input file | |
System::String inputFileName = dataDir() + u"input.xps"; | |
//Outut file | |
System::String outputFileName = outDir() + u"XPStoImage_out.bmp"; | |
// Initialize XPS input stream | |
{ | |
System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(inputFileName, System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ xpsStream }); | |
// ------------------------------------------ | |
try | |
{ | |
// Load XPS document form the stream | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<BmpSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<BmpSaveOptions>(); tmp_0->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); tmp_0->set_Resolution(300); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }(); | |
// Create rendering device for PDF format | |
System::SharedPtr<ImageDevice> device = System::MakeObject<ImageDevice>(); | |
document->Save(device, options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int32_t i = 0; i < device->get_Result()->get_Length(); i++) | |
{ | |
for (int32_t j = 0; j < device->get_Result()[i]->get_Length(); j++) | |
{ | |
// Initialize image output stream | |
{ | |
System::String str = System::IO::Path::GetDirectoryName(outputFileName) + u"\\" + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName); | |
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(str, System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream }); | |
// ------------------------------------------ | |
try | |
{ | |
imageStream->Write(device->get_Result()[i][j], 0, device->get_Result()[i][j]->get_Length()); | |
} | |
catch (...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
} | |
} | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Input file | |
System::String inputFileName = dataDir() + u"input.xps"; | |
//Outut file | |
System::String outputFileName = outDir() + u"XPStoImage_out.jpeg"; | |
// Initialize XPS input stream | |
{ | |
System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(inputFileName, System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ xpsStream }); | |
// ------------------------------------------ | |
try | |
{ | |
// Load XPS document form the stream | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<JpegSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<JpegSaveOptions>(); tmp_0->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); tmp_0->set_Resolution(300); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }(); | |
// Create rendering device for PDF format | |
System::SharedPtr<ImageDevice> device = System::MakeObject<ImageDevice>(); | |
document->Save(device, options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int32_t i = 0; i < device->get_Result()->get_Length(); i++) | |
{ | |
for (int32_t j = 0; j < device->get_Result()[i]->get_Length(); j++) | |
{ | |
// Initialize image output stream | |
{ | |
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + u"\\" + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream }); | |
// ------------------------------------------ | |
try | |
{ | |
imageStream->Write(device->get_Result()[i][j], 0, device->get_Result()[i][j]->get_Length()); | |
} | |
catch (...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
} | |
} | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} |
This file contains 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
//For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Input file | |
System::SharedPtr<System::IO::Stream> pdfStream = System::IO::File::Open(RunExamples::outDir() + u"XPStoPDF.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ pdfStream }); | |
// ------------------------------------------ | |
try { | |
System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(RunExamples::dataDir() + u"input.xps", System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ xpsStream }); | |
// ------------------------------------------ | |
try | |
{ | |
// Load XPS document form the stream | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<Aspose::Page::Xps::Presentation::Pdf::PdfSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<Aspose::Page::Xps::Presentation::Pdf::PdfSaveOptions>(); tmp_0->set_JpegQualityLevel(100); tmp_0->set_ImageCompression(Aspose::Page::Xps::Presentation::Pdf::PdfImageCompression::Jpeg); tmp_0->set_TextCompression(Aspose::Page::Xps::Presentation::Pdf::PdfTextCompression::Flate); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }(); | |
// Create rendering device for PDF format | |
System::SharedPtr<Aspose::Page::Xps::Presentation::Pdf::PdfDevice> device = System::MakeObject<Aspose::Page::Xps::Presentation::Pdf::PdfDevice>(pdfStream); | |
document->Save(device, options); | |
} | |
catch (...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} |
This file contains 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
For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Input file | |
System::String inputFileName = dataDir() + u"input.xps"; | |
//Outut file | |
System::String outputFileName = outDir() + u"XPStoImage_out.png"; | |
// Initialize XPS input stream | |
{ | |
System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(inputFileName, System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ xpsStream }); | |
// ------------------------------------------ | |
try | |
{ | |
// Load XPS document form the stream | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<PngSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<PngSaveOptions>(); tmp_0->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); tmp_0->set_Resolution(300); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }(); | |
// Create rendering device for PDF format | |
System::SharedPtr<ImageDevice> device = System::MakeObject<ImageDevice>(); | |
document->Save(device, options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int32_t i = 0; i < device->get_Result()->get_Length(); i++) | |
{ | |
for (int32_t j = 0; j < device->get_Result()[i]->get_Length(); j++) | |
{ | |
// Initialize image output stream | |
{ | |
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + u"\\" + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream }); | |
// ------------------------------------------ | |
try | |
{ | |
imageStream->Write(device->get_Result()[i][j], 0, device->get_Result()[i][j]->get_Length()); | |
} | |
catch (...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
} | |
} | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} |
This file contains 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
//For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// Input file | |
System::String inputFileName = dataDir() + u"input.xps"; | |
//Outut file | |
System::String outputFileName = outDir() + u"XPStoImage_out.tif"; | |
// Initialize XPS input stream | |
{ | |
System::SharedPtr<System::IO::Stream> xpsStream = System::IO::File::Open(inputFileName, System::IO::FileMode::Open, System::IO::FileAccess::Read); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ xpsStream }); | |
// ------------------------------------------ | |
try | |
{ | |
// Load XPS document form the stream | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(xpsStream, System::MakeObject<XpsLoadOptions>()); | |
// or load XPS document directly from file. No xpsStream is needed then. | |
// XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); | |
// Initialize options object with necessary parameters. | |
System::SharedPtr<TiffSaveOptions> options = [&] { auto tmp_0 = System::MakeObject<TiffSaveOptions>(); tmp_0->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); tmp_0->set_Resolution(300); tmp_0->set_PageNumbers(System::MakeArray<int32_t>({ 1, 2, 6 })); return tmp_0; }(); | |
// Create rendering device for PDF format | |
System::SharedPtr<ImageDevice> device = System::MakeObject<ImageDevice>(); | |
document->Save(device, options); | |
// Iterate through document partitions (fixed documents, in XPS terms) | |
for (int32_t i = 0; i < device->get_Result()->get_Length(); i++) | |
{ | |
for (int32_t j = 0; j < device->get_Result()[i]->get_Length(); j++) | |
{ | |
// Initialize image output stream | |
{ | |
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + u"\\" + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream }); | |
// ------------------------------------------ | |
try | |
{ | |
imageStream->Write(device->get_Result()[i][j], 0, device->get_Result()[i][j]->get_Length()); | |
} | |
catch (...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
} | |
} | |
} | |
catch (...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment