C# word 转图片 PDF 转图片
·
word转图片使用的Aspose组件,Aspose.word.dll
public bool Word2Png(string docFile, string pngDir, out int pngCount)
{
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.Resolution = 300;
options.PrettyFormat = true;
options.UseAntiAliasing = true;
pngCount = 0;
try
{
Aspose.Words.Document doc = new Aspose.Words.Document(docFile);
for (int i = 0; i < doc.PageCount; i++)
{
options.PageIndex = i;
doc.Save(pngDir + i + ".png", options);
pngCount++;
}
return true;
}
catch
{
return false;
}
}PDF 转图片使用的是Aspose.pdf.dll 组件
public bool PDF2PNG(string srcPdfPath, string desPicPath)
{
try
{
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(srcPdfPath);
for (int pageCount = 1; pageCount <= pdf.Pages.Count; pageCount++)
{
using (FileStream p_w_picpathStream = new FileStream(desPicPath + "\\" + pageCount + ".png", FileMode.Create))
{
//create Resolution object
Aspose.Pdf.Devices.Resolution resolution = new Aspose.Pdf.Devices.Resolution(300);
Aspose.Pdf.Devices.PngDevice pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution);
//convert a particular page and save the p_w_picpath to stream
pngDevice.Process(pdf.Pages[pageCount], p_w_picpathStream);
//close stream
p_w_picpathStream.Close();
}
}
return true;
}
catch (Exception e)
{
return false;
}
}转载于:https://blog.51cto.com/xiaoshuaigege/1889703
更多推荐


所有评论(0)