Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

c# - Enabling annotation in Adobe AxAcroPDFLib

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...