获取在 Acrobat DC Pro 中打开的 PDF 路径(在 VB 中工作,但不在 C# 中工作) [英] Get Path of PDF Opened in Acrobat DC Pro (Working in VB but not in C#)

查看:49
本文介绍了获取在 Acrobat DC Pro 中打开的 PDF 路径(在 VB 中工作,但不在 C# 中工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想检索在 Acrobat DC Pro 中打开的 PDF 文档的路径,并在 C# 中将路径保存到我的数据库中,

I just wish to retrieve the path of PDF document opened in Acrobat DC Pro, and save paths to my database in c#,

我能够在 c# 中获取活动的 pdf 文档,但无法检索文档的路径,

I able to get active pdf document in c# but unable to retrieve path of the document,

Type PDFType = Type.GetTypeFromProgID("AcroExch.App");
CAcroApp AcroAppObj = Activator.CreateInstance(PDFType) as CAcroApp;  

CAcroAVDoc AvDocObj = AcroAppObj.GetActiveDoc() as CAcroAVDoc;  

CAcroPDDoc PdDocObj = AvDocObj.GetPDDoc() as CAcroPDDoc;

object jsObj = pdDocObj.GetJSObject();

现在在 jsObj 中,我得到 System.__ComObject,如果我使用的是 Vb.net,那么我得到的文件路径很简单,

Now in jsObj I get System.__ComObject, if I am using Vb.net, then I get path of document simply as,

Dim docPath As string
docPath = jsObj.path

但是,在 C# 中是不允许的,我该怎么办?

but, it is not allowed in C#, what should I do?

推荐答案

这里是另一种获取当前活动 Doc 路径的解决方案.它使用 Acrobat Form api 通过 js 获取路径.附上一个vbs例子.祝你好运,莱因哈德

Here another solution to get the path of the current active Doc. It uses Acrobat Form api to get the path via js. Attached a vbs example. Good luck, Reinhard

Path = "D:\Test.pdf"

Set App = CreateObject("Acroexch.app")
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI

If AVDoc.Open(Path,"") Then
    '// write some js code on a vbs variable
   js =  "var f = this.path;" &vblf _
        & "app.alert(f);"
     '//execute the js code
    AForm.Fields.ExecuteThisJavaScript js
end if

Set AForm = Nothing
Set AVDoc = Nothing
Set APP = Nothing

这篇关于获取在 Acrobat DC Pro 中打开的 PDF 路径(在 VB 中工作,但不在 C# 中工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆