Acrobat 转换pdf到png的另一种方法

此方法效率较低,大概2秒转3页pdf成png图片,但是可以保证图片质量很高,分辨率很高。有优化的地方,但没时间研究。先放代码吧。

前提是安装 acrobat 11(即acrobat xi)

  CAcroApp mApp = new AcroApp();
mApp.Hide();
String szPdfPathConst = AppDomain.CurrentDomain.BaseDirectory + @"深入浅出WPF.pdf";
AcroAVDoc g_AVDoc = new AcroAVDoc();
//open the PDF
if (g_AVDoc.Open(szPdfPathConst, ""))
{
int currentIndex = 0;
bool formDataExists = true; Object newDoc = null; if (g_AVDoc.IsValid())
{ CAcroPDDoc pdDoc = (CAcroPDDoc)g_AVDoc.GetPDDoc();
int iNum = pdDoc.GetNumPages();
Object jsObj = pdDoc.GetJSObject();
if (formDataExists)
{
Type T = jsObj.GetType(); object[] extractPagesParam = { currentIndex,iNum-1 };
newDoc = T.InvokeMember(
"extractPages",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, jsObj, extractPagesParam); String newFileName = AppDomain.CurrentDomain.BaseDirectory + "data\\" + currentIndex + ".png";
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "data"); object[] saveAsParam = { newFileName, "com.adobe.acrobat.png" };
T.InvokeMember(
"saveAs",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, newDoc, saveAsParam);
formDataExists = currentIndex != iNum - 1; object[] closeDocParam = { true };
T.InvokeMember(
"closeDoc",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, newDoc, closeDocParam); currentIndex++;
}
}
}
mApp.CloseAllDocs();
mApp.Exit();

  感谢阅读的人,希望可以帮到你。

上一篇:WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!


下一篇:机房收费系统(VB.NET)——存储过程实战