public sealed class AcrobatUtil
{
public string ConvertToExecl(string inputFileName, string outputFileName)
{
//判断文件是否存在
if (!File.Exists(inputFileName))
{
return "File Is Missing";
}
try
{
//判断是否已经安装Acrobat
string acrobatPath = GetAppPath();
if (acrobatPath == null)
{
return "Adobe Acrobat not installed.";
}
var aVDoc = new AcroAVDoc();
aVDoc.Open(inputFileName, "");
CAcroPDDoc PDDoc = (CAcroPDDoc)aVDoc.GetPDDoc();
object jsObj = PDDoc.GetJSObject();
var jsObjType = jsObj.GetType();
//另存为
jsObjType.InvokeMember(
"saveAs",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, jsObj, new object[] { outputFileName, "com.adobe.acrobat.xlsx" });
/*
另存为更多格式
html htm com.adobe.acrobat.html
jpeg jpg com.adobe.acrobat.jpeg
docx com.adobe.acrobat.docx
doc com.adobe.acrobat.doc
png com.adobe.acrobat.png
ps com.adobe.acrobat.ps
rft com.adobe.acrobat.rft
xlsx com.adobe.acrobat.xlsx
xls com.adobe.acrobat.spreadsheet
txt com.adobe.acrobat.accesstext
tiff tif com.adobe.acrobat.tiff
xml com.adobe.acrobat.xml-1-00
*/
//关闭文档
aVDoc.Close(1);
}
catch (Exception ex)
{
return "Error:" + ex.Message;
}
return null;
}
//获取Acrobat安装路径
private string GetAppPath()
{
string acrobatPath = null;
using (RegistryKey acrobatRegistryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Adobe\Adobe Acrobat"))
{
if (acrobatRegistryKey == null)
{
return acrobatPath;
}
string acrobatVersion = acrobatRegistryKey.GetValue("TrackName").ToString();
using (RegistryKey acrobatInstallPathRegistryKey = acrobatRegistryKey.OpenSubKey(acrobatVersion + @"\InstallPath"))
{
if (acrobatInstallPathRegistryKey == null)
{
return acrobatPath;
}
acrobatPath = acrobatInstallPathRegistryKey.GetValue("").ToString() + @"\Acrobat.exe";
}
}
return acrobatPath;
}
}
liqiinhit (2023/10/13 10:43:27)
在网上找了另一个,不好用!! 你这个非常好用,谢谢!!