提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-03-27 10:31:46.593|阅读 248 次
概述:Aspose.Page for C ++是一个本机C ++库,用于创建新的PostScript和XPS文件以及以编程方式修改和转换现有文件。本文演示了如何将PS / EPS或XPS文档转换为PDF或光栅图像格式,包括PNG,JPEG,TIFF和BMP。
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
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@hmdbvip.cn




在现代软件开发过程中,自动化单元测试是确保代码质量与可靠性的关键环节。尤其对于特定框架(如MFC)的代码,测试复杂度显著增加,常因依赖外部资源或交互操作而难以在静默环境中顺利执行。Parasoft C/C++test作为专业的软件测试工具,致力于帮助开发团队高效实施自动化测试,通过其强大的桩函数功能,能够有效模拟依赖组件的行为,从而实现对复杂逻辑的隔离测试。
本文将为大家介绍如何在MyEclipse中使用XDoclet开发EJB 2 Session Bean,欢迎下载最新版体验!
如果能将 CSV 自动转换为 PDF ,就能快速生成清晰、美观的报表,既节省手动排版时间,又能保持数据的专业呈现。本文将介绍如何使用 Spire.XLS for Java 实现这一过程——从加载 CSV 到输出高质量 PDF,仅需数行代码即可完成。
Parasoft C/C++test是一款专为C/C++代码设计的自动化测试工具,通过静态代码分析、单元测试和运行时错误检测等功能,帮助开发团队在早期发现并修复缺陷,提升代码质量和开发效率 。在实际使用中,尤其是在VC6此类旧版开发环境中执行单元测试时,可能会因环境兼容性问题触发链接错误。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@hmdbvip.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
永利最大(官方)网站