今天跟大家分享一个实现PDF另存为的效果,是调用Acrobat SDK的JavaScript实现的。
复制代码 代码如下:
/// <summary>
/// PDF另存为效果
/// </summary>
/// <param name="fileName">PDF文件名</param>
/// <param name="saveFileName">另存结果文件名</param>
public static void PDFSaveAs(String fileName, string saveFileName)
{
Acrobat.CAcroPDDoc pdfDoc = null;
pdfDoc = (Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", "");
if (!pdfDoc.Open(fileName)) { string.Format("源文件{0}不存在!", fileName); }
Object jsObj = pdfDoc.GetJSObject();
Type T = jsObj.GetType();
object[] saveAsParam = { saveFileName, "com.adobe.acrobat.tiff" }; //com.adobe.acrobat.tiff 表示TIFF文件
T.InvokeMember(
"saveAs",
BindingFlags.InvokeMethod |
BindingFlags.Public |
BindingFlags.Instance,
null, jsObj, saveAsParam);
pdfDoc.Close();
}