使用Aspose.Words將Word文件轉換為Tiff格式圖片檔案
用 Aspose元件的優點是操作 Word 文件不需要安裝 Office 就可以實現。
首先需要引用 Aspose.Words.dll,連結地址: 連結:https://pan.baidu.com/s/1rJvjp-kMsEterYf_oud28Q 提取碼:awiw
程式碼如下:
public bool WordToTif(string sourcePath,string targetPath)
{
try
{
Document doc = new Document(sourcePath);
ImageSaveOptions iso = new ImageSaveOptions(SaveFormat.Tiff);
iso.TiffCompression = TiffCompression.Ccitt4;//設定壓縮方式
iso.PageCount = 1;
iso.Resolution = 200;//設定精度
//iso.PrettyFormat = true;
//iso.UseAntiAliasing = true;
int count = doc.PageCount;
for (int i = 0; i < count; i++)
{
iso.PageIndex = i;
doc.Save(targetPath + "\\000" + i.ToString() + ".Tif", iso);
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
return true;
}