Last active
October 4, 2024 15: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->AddPath(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
// ExStart:UsingImageUtils | |
// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithImages(); | |
// Create new XPS Document | |
{ | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ doc}); | |
// ------------------------------------------ | |
try | |
{ | |
// Set first page's size. | |
doc->get_Page()->set_Width(540.f); | |
doc->get_Page()->set_Height(220.f); | |
// Draw the image box. | |
System::Drawing::RectangleF imageBox(10.f, 10.f, 200.f, 200.f); | |
System::SharedPtr<XpsPath> path = doc->AddPath(doc->get_Utils()->CreateRectangle(imageBox)); | |
path->set_Stroke(doc->CreateSolidColorBrush(System::Drawing::Color::get_Black())); | |
// Add an image to fit width. | |
path = doc->get_Utils()->CreateImage(dataDir + u"R08LN_NN.jpg", imageBox, Aspose::Page::XPS::ImageMode::FitToWidth); | |
// Prevent tiling. | |
(System::ExplicitCast<Aspose::Page::XPS::XpsModel::XpsImageBrush>(path->get_Fill()))->set_TileMode(Aspose::Page::XPS::XpsModel::XpsTileMode::None); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Add an image to fit width. | |
doc->Add<System::SharedPtr<XpsPath>>(doc->get_Utils()->CreateImage(dataDir + u"R08LN_NN.jpg", System::Drawing::RectangleF(220.f, 10.f, 200.f, 100.f), Aspose::Page::XPS::ImageMode::FitToHeight)); | |
// Add an image to fit width. | |
doc->Add<System::SharedPtr<XpsPath>>(doc->get_Utils()->CreateImage(dataDir + u"R08LN_NN.jpg", System::Drawing::RectangleF(430.f, 10.f, 100.f, 200.f), Aspose::Page::XPS::ImageMode::FitToBox)); | |
// Save resultant XPS document | |
doc->Save(dataDir + u"UseImageUtilsXPS_out.xps"); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:UsingImageUtils |
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
// ExStart:ModifyingXpsPageOnConversion | |
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithPages(); | |
// Open an XPS document | |
{ | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(dataDir + u"Sample3.xps"); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_1({ doc}); | |
// ------------------------------------------ | |
try{ | |
System::SharedPtr<System::IO::Stream> fontStream = System::IO::File::OpenRead(dataDir + u"arialbd.ttf"); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ fontStream}); | |
// ------------------------------------------ | |
try | |
{ | |
// Create options for conversion to PDF | |
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(); | |
// Set the filter for the pages that need conversion | |
options->set_PageNumbers(System::MakeArray<int32_t>({2, 6, 7, 13})); | |
// Add the event handler that will execute right before the conversion of each page | |
options->get_BeforePageSavingEventHandlers()->Add(System::MakeObject<ModifyXpsPageOnConversion::NavigationInjector>(doc->CreateFont(fontStream), options->get_PageNumbers())); | |
// Save resultant XPS document | |
doc->SaveAsPdf(dataDir + u"ModifyPageOnConversion_out.pdf", options); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
catch(...) | |
{ | |
__dispose_guard_1.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:ModifyingXpsPageOnConversion |
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
ModifyXpsPageOnConversion::NavigationInjector::NavigationInjector(System::SharedPtr<Aspose::Page::XPS::XpsModel::XpsFont> font, System::ArrayPtr<int32_t> pageNumbers) | |
{ | |
_font = font; | |
if (pageNumbers == nullptr) | |
{ | |
return; | |
} | |
// Turn the page number array into a sorted collection of unique values. | |
_pageNumbers = System::MakeObject<System::Collections::Generic::SortedList<int32_t, int32_t>>(); | |
for (int32_t pn : pageNumbers) | |
{ | |
_pageNumbers->idx_set(pn, 0); | |
} | |
} | |
void ModifyXpsPageOnConversion::NavigationInjector::Handle(System::SharedPtr<Aspose::Page::XPS::Features::EventBasedModifications::BeforeSavingEventArgs<System::SharedPtr<Aspose::Page::XPS::Features::EventBasedModifications::PageAPI>>> args) | |
{ | |
System::SharedPtr<PageAPI> api = args->get_ElementAPI(); | |
System::SharedPtr<XpsGlyphs> glyphs; | |
// For all pages in the output PDF except the first one... | |
if (args->get_OutputPageNumber() > 1) | |
{ | |
// ...insert a hyperlink to the first page... | |
glyphs = api->CreateGlyphs(_font, 15.f, 5.f, api->get_Height() - 10.f, u"[First]"); | |
glyphs->set_Fill(api->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
glyphs->set_HyperlinkTarget(System::MakeObject<XpsPageLinkTarget>(_pageNumbers == nullptr ? 1 : _pageNumbers->get_Keys()->idx_get(0))); | |
api->Add<System::SharedPtr<XpsGlyphs>>(glyphs); | |
// ...and to the previous page. | |
glyphs = api->CreateGlyphs(_font, 15.f, 60.f, api->get_Height() - 10.f, u"[Prev]"); | |
glyphs->set_Fill(api->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
glyphs->set_HyperlinkTarget(System::MakeObject<XpsPageLinkTarget>(_pageNumbers == nullptr ? args->get_AbsolutePageNumber() - 1 : _pageNumbers->get_Keys()->idx_get(args->get_OutputPageNumber() - 2))); | |
api->Add<System::SharedPtr<XpsGlyphs>>(glyphs); | |
} | |
// For all pages in the output PDF except the last one... | |
if ((_pageNumbers != nullptr && args->get_OutputPageNumber() < _pageNumbers->get_Count()) || (_pageNumbers == nullptr && args->get_OutputPageNumber() < api->get_TotalPageCount())) | |
{ | |
// ...insert a hyperlink to the next page... | |
glyphs = api->CreateGlyphs(_font, 15.f, 110.f, api->get_Height() - 10.f, u"[Next]"); | |
glyphs->set_Fill(api->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
glyphs->set_HyperlinkTarget(System::MakeObject<XpsPageLinkTarget>(_pageNumbers == nullptr ? args->get_AbsolutePageNumber() + 1 : _pageNumbers->get_Keys()->idx_get(args->get_OutputPageNumber()))); | |
api->Add<System::SharedPtr<XpsGlyphs>>(glyphs); | |
// ...and to the last page. | |
glyphs = api->CreateGlyphs(_font, 15.f, 160.f, api->get_Height() - 10.f, u"[Last]"); | |
glyphs->set_Fill(api->CreateSolidColorBrush(System::Drawing::Color::get_Blue())); | |
glyphs->set_HyperlinkTarget(System::MakeObject<XpsPageLinkTarget>(_pageNumbers == nullptr ? api->get_TotalPageCount() : _pageNumbers->get_Keys()->idx_get(_pageNumbers->get_Keys()->get_Count() - 1))); | |
api->Add<System::SharedPtr<XpsGlyphs>>(glyphs); | |
} | |
// Insert a page number in the bottom-right corner. | |
glyphs = api->CreateGlyphs(_font, 15.f, api->get_Width() - 20.f, api->get_Height() - 10.f, System::Convert::ToString(args->get_OutputPageNumber())); | |
glyphs->set_Fill(api->CreateSolidColorBrush(System::Drawing::Color::get_Black())); | |
api->Add<System::SharedPtr<XpsGlyphs>>(glyphs); | |
// Add an outline entry to display the links to the converted pages in the navigation pane of a PDF viewer. | |
api->AddOutlineEntry(System::String::Format(u"Page {0}", args->get_OutputPageNumber()), 1, args->get_AbsolutePageNumber()); | |
} |
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
/// <summary> | |
/// The class to handle the before-page event while converting an XPS document. | |
/// </summary> | |
class NavigationInjector : public Aspose::Page::XPS::Features::EventBasedModifications::BeforePageSavingEventHandler | |
{ | |
typedef NavigationInjector ThisType; | |
typedef Aspose::Page::XPS::Features::EventBasedModifications::BeforePageSavingEventHandler BaseType; | |
typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo; | |
RTTI_INFO_DECL(); | |
public: | |
NavigationInjector(System::SharedPtr<Aspose::Page::XPS::XpsModel::XpsFont> font, System::ArrayPtr<int32_t> pageNumbers); | |
/// <summary> | |
/// The action itself to be triggered on a before-page event. | |
/// </summary> | |
/// <param name="args">The event arguments.</param> | |
void Handle(System::SharedPtr<Aspose::Page::XPS::Features::EventBasedModifications::BeforeSavingEventArgs<System::SharedPtr<Aspose::Page::XPS::Features::EventBasedModifications::PageAPI>>> args) override; | |
private: | |
System::SharedPtr<Aspose::Page::XPS::XpsModel::XpsFont> _font; | |
System::SharedPtr<System::Collections::Generic::SortedList<int32_t, int32_t>> _pageNumbers; | |
}; |
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
// ExStart:UsingShapeUtils | |
// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C | |
// The path to the documents directory. | |
System::String dataDir = RunExamples::GetDataDir_WorkingWithShapes(); | |
// Create new XPS Document | |
{ | |
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>(); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ doc}); | |
// ------------------------------------------ | |
try | |
{ | |
// Set first page's size. | |
doc->get_Page()->set_Width(650.f); | |
doc->get_Page()->set_Height(240.f); | |
// Draw a circle with center (120, 120) and radius 100. | |
System::SharedPtr<XpsPath> path = doc->CreatePath(doc->get_Utils()->CreateCircle(System::Drawing::PointF(120.f, 120.f), 100.f)); | |
path->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Green())); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Inscribe a regular pentagon in the circle. | |
path = doc->CreatePath(doc->get_Utils()->CreateRegularInscribedNGon(5, System::Drawing::PointF(120.f, 120.f), 100.f)); | |
path->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Red())); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Circumscribe a regular hexagon around the circle. | |
path = doc->CreatePath(doc->get_Utils()->CreateRegularCircumscribedNGon(6, System::Drawing::PointF(120.f, 120.f), 100.f)); | |
path->set_Stroke(doc->CreateSolidColorBrush(System::Drawing::Color::get_Magenta())); | |
path->set_StrokeThickness(3.f); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Draw a sector of the circle centered at (340, 120), starting at -45 degrees and ending at +45 degrees. | |
path = doc->CreatePath(doc->get_Utils()->CreatePieSlice(System::Drawing::PointF(340.f, 120.f), 100.f, -45.f, 45.f)); | |
path->set_Stroke(doc->CreateSolidColorBrush(System::Drawing::Color::get_Red())); | |
path->set_StrokeThickness(5.f); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Draw a segment of the circle centered at (340, 120), starting at -45 degrees and ending at +45 degrees. | |
path = doc->CreatePath(doc->get_Utils()->CreateCircularSegment(System::Drawing::PointF(340.f, 120.f), 100.f, -45.f, 45.f)); | |
path->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Black())); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Draw a rectangle with the top left vertex (530, 20), width 100 units and height 200 units. | |
path = doc->CreatePath(doc->get_Utils()->CreateRectangle(System::Drawing::RectangleF(530.f, 20.f, 100.f, 200.f))); | |
path->set_Stroke(doc->CreateSolidColorBrush(System::Drawing::Color::get_Red())); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
// Draw an ellipse with center (580, 120) and radii 50 and 100. | |
path = doc->CreatePath(doc->get_Utils()->CreateEllipse(System::Drawing::PointF(580.f, 120.f), 50.f, 100.f)); | |
path->set_Fill(doc->CreateSolidColorBrush(System::Drawing::Color::get_Yellow())); | |
doc->Add<System::SharedPtr<XpsPath>>(path); | |
doc->Save(dataDir + u"UseShapeUtilsXPS_out.xps"); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:UsingShapeUtils |
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()); | |
} | |
} |
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
// ExStart:CreateCustomPrintTicket | |
// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET | |
// The path to the documents directory. | |
System::String dir = RunExamples::GetDataDir_WorkingWithPrintTickets(); | |
// Create new XPS document | |
{ | |
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(); | |
// Clearing resources under 'using' statement | |
System::Details::DisposeGuard<1> __dispose_guard_0({ document}); | |
// ------------------------------------------ | |
try | |
{ | |
// Set a custom job-level print ticket | |
document->set_JobPrintTicket(System::MakeObject<JobPrintTicket>( | |
System::MakeArray<System::SharedPtr<IJobPrintTicketItem>>({ | |
// Specify input bin. | |
System::MakeObject<JobInputBin>(System::MakeArray<System::SharedPtr<InputBin::IInputBinItem>>({InputBin::InputBinOption::Manual->Clone()->Add(System::MakeArray<System::SharedPtr<InputBin::IInputBinOptionItem>>( | |
{InputBin::FeedFace::FaceDown, InputBin::FeedDirection::LongEdgeFirst, System::MakeObject<InputBin::MediaSheetCapacity>(100)}))})), | |
// Specify output bin. | |
System::MakeObject<JobOutputBin>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinItem>>({ | |
System::MakeObject<OutputBin::OutputBinOption>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinOptionItem>>( | |
{OutputBin::BinType::Sorter})), | |
System::MakeObject<OutputBin::OutputBinOption>(System::MakeArray<System::SharedPtr<OutputBin::IOutputBinOptionItem>>( | |
{OutputBin::BinType::Stacker, System::MakeObject<OutputBin::MediaSheetCapacity>(100)}))})), | |
// Specify page orientation. | |
System::MakeObject<PageOrientation>(System::MakeArray<System::SharedPtr<PageOrientation::PageOrientationOption>>( | |
{PageOrientation::PageOrientationOption::Landscape})), | |
// Specify duplex mode for the output. | |
System::MakeObject<JobDuplexAllDocumentsContiguously>(System::MakeArray<System::SharedPtr<Duplex::DuplexOption>>( | |
{Duplex::DuplexOption::TwoSidedLongEdge(Duplex::DuplexMode::Automatic)})), | |
// Specify the color settings for the output. | |
System::MakeObject<PageOutputColor>(System::MakeArray<System::SharedPtr<PageOutputColor::IPageOutputColorItem>>( | |
{PageOutputColor::PageOutputColorOption::Grayscale(0, 8)}))}))); | |
// Save the document with the custom job-level print ticket. | |
document->Save(dir + u"output1.xps"); | |
} | |
catch(...) | |
{ | |
__dispose_guard_0.SetCurrentException(std::current_exception()); | |
} | |
} | |
// ExEnd:CreateCustomPrintTicket |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment