没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-03-27 10:31:46.593|阅读 242 次
概述:Aspose.Page for C ++是一个本机C ++库,用于创建新的PostScript和XPS文件以及以编程方式修改和转换现有文件。本文演示了如何将PS / EPS或XPS文档转换为PDF或光栅图像格式,包括PNG,JPEG,TIFF和BMP。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
XPS是工作中常用的一种微软的文档保存和查看格式,针对XPS、EPS格式的管理控件Aspose.Page已经推出C++版,将能够在基于C ++的应用程序中以编程方式创建,读取,编辑,保存和转换XPS文档,该API还允许您处理XPS文档中的页面和元素,例如画布和字形。此外,它支持将文档转换为PDF和光栅图像。。你可以点击下方按钮下载测试体验。
与此同时,.NET版和Java版Aspose.Page已更新至v20.3最新版,修复将图像添加到XPS文件时发生的异常,点击下方按钮下载试用。
下载最新版Aspose.Page for .NET 下载最新版Aspose.Page for java
在本文中,将演示如何将PS / EPS或XPS文档转换为PDF或光栅图像格式,包括PNG,JPEG,TIFF和BMP。本文的内容包括:
以下是将PostScript PS / EPS文档转换为PDF的步骤:
为输出PDF文件创建FileStream对象。
将输入的PostScript文档加载到FileStream对象中。
使用输入流创建并初始化PsDocument对象。
使用输出流创建并初始化PdfDevice对象。
使用PsDocument-> Save方法处理文档并将其另存为PDF文件。
以下代码示例显示了如何在C ++中将PostScript PS文档转换为PDF。
// Initialize PDF output stream
System::SharedPtrpdfStream = System::MakeObject(value + u"PStoPDF.pdf", System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Initialize PostScript input stream
System::SharedPtrpsStream = System::MakeObject(value + u"input.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
System::SharedPtrdocument = System::MakeObject(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::SharedPtroptions = System::MakeObject(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({ u"{FONT_FOLDER}" }));
// Default page size is 595x842 and it is not mandatory to set it in PdfDevice
System::SharedPtrdevice = System::MakeObject(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;
}
}
// Review errors
if (suppressErrors)
{
//auto ex_enumerator = (System::DynamicCastEnumerableTo(options->get_Exceptions()))->GetEnumerator();
auto ex_enumerator = (options->get_Exceptions())->GetEnumerator();
decltype(ex_enumerator->get_Current()) ex;
while (ex_enumerator->MoveNext() && (ex = ex_enumerator->get_Current(), true))
{
System::Console::WriteLine(ex->get_Message());
}
}
以下是将PS / EPS转换为图像格式的步骤。
创建ImageFormat对象以设置输出图像的格式,即PNG。
将输入的PostScript文档加载到FileStream对象中。
使用输入流创建并初始化PsDocument对象。
创建一个ImageDevice对象。
使用PsDocument-> Save方法处理文档并将其另存为图像。
下面的代码示例演示如何将PostScript PS / EPS转换为C ++中的图像。
// Initialize PDF output stream
System::SharedPtrimageFormat = System::Drawing::Imaging::ImageFormat::get_Png();
// Initialize PostScript input stream
System::SharedPtrpsStream = System::MakeObject(value + u"inputForImage.ps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
System::SharedPtrdocument = System::MakeObject(psStream);
// If you want to convert PostScript file despite of minor errors the set this flag
bool suppressErrors = true;
// Initialize options object with necessary parameters.
System::SharedPtroptions = System::MakeObject(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({ 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::SharedPtrdevice = System::MakeObject();
// 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::ArrayPtrimagesBytes = device->get_ImagesBytes();
int32_t i = 0;
{
for (System::ArrayPtrimageBytes : imagesBytes)
{
System::String imagePath = System::IO::Path::GetFullPath(value + System::String(u"out_image") + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(imageFormat).ToLower());
{
System::SharedPtrfs = System::MakeObject(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard__dispose_guard_1({ fs });
try
{
fs->Write(imageBytes, 0, imageBytes->get_Length());
}
catch (...)
{
__dispose_guard_1.SetCurrentException(std::current_exception());
}
}
i++;
}
}
// Review errors
if (suppressErrors)
{
//auto ex_enumerator = (System::DynamicCastEnumerableTo(options->get_Exceptions()))->GetEnumerator();
//decltype(ex_enumerator->get_Current()) ex;
//while (ex_enumerator->MoveNext() && (ex = ex_enumerator->get_Current(), true))
//{
// System::Console::WriteLine(ex->get_Message());
//}
}
以下是将XPS文档转换为光栅图像格式的步骤:
将输入的XPS文档加载到FileStream对象中。
创建XpsDocument对象,并使用输入流对象对其进行初始化。
通过创建PngSaveOptions类的对象来设置保存选项。
使用XpsDocument-> Save方法将XPS转换为图像。
以下代码示例显示了如何在C ++中将XPS转换为PNG图像。
// Input file
System::String inputFileName = u"input.xps";
// Output file
System::String outputFileName = u"XPStoImage_out.png";
// Initialize XPS input stream
{
System::SharedPtrxpsStream = System::IO::File::Open(inputFileName, System::IO::FileMode::Open, System::IO::FileAccess::Read);
// Clearing resources under 'using' statement
System::Details::DisposeGuard__dispose_guard_1({ xpsStream });
try
{
// Load XPS document form the stream
System::SharedPtrdocument = System::MakeObject(xpsStream, System::MakeObject());
// 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::SharedPtroptions = [&] { auto tmp_0 = System::MakeObject(); tmp_0->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality); tmp_0->set_Resolution(300); tmp_0->set_PageNumbers(System::MakeArray({ 1, 2, 6 })); return tmp_0; }();
// Create rendering device for PDF format
System::SharedPtrdevice = System::MakeObject();
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::SharedPtrimageStream = 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__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());
}
}
还想要更多吗?您可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),我们很高兴为您提供查询和咨询。 本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn




在使用Parasoft C/C++test执行BugDetective数据流分析时,可能会遇到用户自定义的资源API,那在这种情况下,若要判断是否存在资源问题,如资源泄露等,则需要手动配置测试配置。
大型SaaS系统的自动化测试常常受制于界面变化快、结构复杂、加载机制多变等因素。从元素识别到脚本管理,SmartBear TestComplete帮助Salesforce建了可靠的自动化测试体系。
BarTender 标签管理系统,正是帮助企业轻松实现 GS1 标准化标签设计、编码生成与信息联动的强大工具。
Parasoft C/C++test 是一款功能强大的 C/C++ 软件测试工具,集成了静态代码分析、单元测试、集成测试和覆盖率分析等功能,单元测试作为其关键功能之一,为了适配多样化的目标部署环境,C/C++test 设计了灵活的测试结果收集机制。通过Socket通讯方式来收集单元测试结果,从而扩展其测试覆盖范围与应用场景。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营