【问题标题】:Get Path of PDF Opened in Acrobat DC Pro (Working in VB but not in C#)获取在 Acrobat DC Pro 中打开的 PDF 的路径(在 VB 中工作,但不在 C# 中)
【发布时间】:2018-03-23 09:07:59
【问题描述】:

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

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

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,那么我得到的文档路径就像,

Dim docPath As string
docPath = jsObj.path

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

【问题讨论】:

  • 如果你明确使用System.__ComObject 作为jsObj 的对象类型而不是object 会怎样?就投吧:
  • 不幸的是,在 Adob​​e SDK 中没有名为 JSObject 的类/接口,我可以在其中进行转换。

标签: c# vb.net pdf acrobat-sdk


【解决方案1】:

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

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

【讨论】:

  • 是的,我同意这行得通,但我需要在 c# 中建立相同的内容。有什么帮助吗?
猜你喜欢
  • 2020-05-26
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
相关资源
最近更新 更多