Enabling annotation in Adobe AxAcroPDFLib

我与影子孤独终老i 提交于 2019-11-28 02:57:47

问题


I embedded a PDF viewer in a C# Winform using AxAcroPDFLib. However, the annotation buttons in the toolbar (comments...) are disabled. I searched and found that they are disabled by default, but some reported enabling them using Javascript:

Collab.showAnnotToolsWhenNoCollab = True

Is there a way to do this here?

Edit: Is it possible to use the browser plugin in a WebBrowser Control? If so, how can this be done?


回答1:


Update - The first section is relevant only to Acrobat Reader. For information on when using full versions of Acrobat, see the second section.

Acrobat Reader

I'll preface all of this by stating this is probably not the answer you're looking for, but I felt this warranted more of an explanation than just a comment.

A similar, self-answered question was asked on SO (here), where the OP came to the conclusion that this behavior is by design and nothing cannot be done about it, which I agree with, almost.

While I'm sure you've seen that Reader itself can add annotations, the only straightforward means of accomplishing this using the Reader Plugin (AcroPDFLib) is for the document being loaded to be "Reader Enabled," at which point annotations become available just as they are in Reader. If you have control of the documents you wish the plugin to load, this may be a solution for you.

To your question about possibly setting Collab.showAnnotToolsWhenNoCollab = True as a workaround, my searches only showed this being a viable workaround for those using a full version of Acrobat, not Reader. More specifically, on an Adobe forum (here), an Adobe staff commented on the use of this property directly:

No, it is not [about allowing commenting in Adobe Reader]. It is about enabling commenting in a browser for Acrobat Standard or Professional. If you wish to enable commenting in Reader, then you need to "Reader Enable" the PDFs themselves using Acrobat professional or Adobe Livecycle Reader Extension Server.

Granted, this comment was in reference to Acrobat 9, it appears to still be valid for Acrobat XI.

One last bit. I don't know the scope of your application, so this may be completely irrelevant, but if this is a commercial application, even if do you find a functional workaround, I'd be hesitant to use it, as it might violation the Adobe Reader license agreement (here); specifically section 4.3.3, Disabled Features. The short version is, as with most companies, they don't want you circumventing their protections.

Full versions of Acrobat

The following code will create a PDF viewer (using the Form's window for drawing), open a PDF, then set collab.showAnnotToolsWhenNoCollab = true to allow annotations on the open PDF. This requires a reference to the Acrobat type library.

void CreatePdfViewerAndOpenFile(string pdfFile)
{
    short AV_DOC_VIEW = 2;
    short PDUseBookmarks = 3;
    short AVZoomFitWidth = 2;

    Type AcroExch_AVDoc = Type.GetTypeFromProgID("AcroExch.AVDoc");
    _acroExchAVDoc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcroExch_AVDoc);
    bool ok = _acroExchAVDoc.OpenInWindowEx(pdfFile, this.Handle.ToInt32(), AV_DOC_VIEW, -1, 0, PDUseBookmarks, AVZoomFitWidth, 0, 0, 0);

    if (ok)
    {
        CAcroPDDoc pdDoc = (CAcroPDDoc)_acroExchAVDoc.GetPDDoc();
        object jsObj = pdDoc.GetJSObject();
        Type jsObjType = jsObj.GetType();
        object collab = jsObjType.InvokeMember("collab",
            BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
            null, jsObj, null);

        jsObjType.InvokeMember("showAnnotToolsWhenNoCollab",
            BindingFlags.SetProperty | BindingFlags.Public | BindingFlags.Instance,
            null, collab, new object[] { true });
    }
}

Call this method from wherever you want to display the PDF. When finished, be sure to call the Close method or the PDF file will remain open in the Acrobat process in the background.

_acroExchAVDoc.Close(-1);

Bear in mind that a lot of "normal" functionality is left out of this example, like form resize handling, etc., but it should get you started. Because resizing isn't handled by this example, you'll probably want to maximize the form before invoking the method, so the viewer is big enough to be useful. For more information on how to use the viewer in this fashion, download the Acrobat SDK (here) and look at the ActiveViewVB sample project, which is what I used to build some of this example. For reference, I used the Acrobat XI SDK.



来源:https://stackoverflow.com/questions/30019736/enabling-annotation-in-adobe-axacropdflib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!