文档半岛外围网上直营>>Aspose中文文档>>将 Word 文档转换为 PNG
将 Word 文档转换为 PNG
Aspose.Words是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
要将 Word 文档转换为 PNG,只需调用Save方法并指定扩展名为“.PNG”的文件名即可。
从DOC转换为PNG示例
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET
public static void ConvertDocumentToPNG()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
// Load a document
Document doc = new Document(dataDir + "SampleImages.doc");
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
PageRange pageRange = new PageRange(0, doc.PageCount - 1);
imageSaveOptions.PageSet = new PageSet(pageRange);
imageSaveOptions.PageSavingCallback = new HandlePageSavingCallback();
doc.Save(dataDir + "output.png", imageSaveOptions);
Console.WriteLine("\nDocument converted to PNG successfully.");
}
private class HandlePageSavingCallback : IPageSavingCallback
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
public void PageSaving(PageSavingArgs args)
{
args.PageFileName = string.Format(dataDir + "Page_{0}.png", args.PageIndex);
}
}
点击复制
代码示例
运行代码
如需下载产品Aspose.Words ,请点击产品名进入下载页面

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线