是否可以使用 Acrobat.dll 在 ac# 应用程序中打开 PDF?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/429449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 03:01:22  来源:igfitidea点击:

Is it possible to open a PDF inside a c# application with Acrobat.dll?

c#acrobat

提问by johnny

I know that I can display a PDF file in my c# executable (not web app) with:

我知道我可以在我的 c# 可执行文件(不是网络应用程序)中显示一个 PDF 文件:

private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
axAcroPDF1.LoadFile(@"somefile.pdf");
axAcroPDF1.Show();

But that is the regular pdf viewer like in the browser. I don't want that. I want full Adobe Standard or Professional functionality in my C# application using the Adobe controls. For example, if I use the code above, it loads in the C# app and I can see the adobe toolbar (print, save, etc.) But it is useless to me because I need things like save which cannot be done with the activex viewer above. Specifically, you cannot save, just as you cannot within the broswer.

但那是浏览器中的常规 pdf 查看器。我不想要那个。我希望使用 Adob​​e 控件在我的 C# 应用程序中使用完整的 Adob​​e Standard 或 Professional 功能。例如,如果我使用上面的代码,它会加载到 C# 应用程序中,我可以看到 adobe 工具栏(打印、保存等)但它对我来说没用,因为我需要诸如保存之类的东西,而这些东西不能用 activex 来完成上面的查看器。具体来说,您无法保存,就像您无法在浏览器中保存一样。

So, I referenced the acrobat.dll and am trying to use:

所以,我引用了 acrobat.dll 并尝试使用:

Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
Acrobat.AcroPDDoc _pdDoc = null;
_acroDoc.Open(myPath, "test");
pdDoc = (Acrobat.AcroPDDoc)(_acroDoc.GetPDDoc());
_acroDoc.SetViewMode(2);
_myAdobe.Show();

It opens adobe acrobat but it opens it outside of my c# application. I need it to open in my c# application like the activex library does. Can it be done with these libraries?

它会打开 adobe acrobat,但会在我的 c# 应用程序之外打开它。我需要它像 activex 库一样在我的 c# 应用程序中打开。可以用这些库来完成吗?

If I cannot open it in my c# application I would like to be able to "hold" my c# app tied to it so the c# app knows when I close the adobe app. At least that way I'd have some measure of control. This means I would hit open, the adobe app opens. I close the adobe app, my C# app is aware of this and loads the newly changed doc with the activex library (because I don't need change ability anymore, just displaying.)

如果我无法在我的 c# 应用程序中打开它,我希望能够“保持”绑定到它的 c# 应用程序,以便 c# 应用程序知道我何时关闭 adobe 应用程序。至少那样我会有一些控制措施。这意味着我会打开,adobe 应用程序打开。我关闭了 adobe 应用程序,我的 C# 应用程序知道这一点,并使用 activex 库加载新更改的文档(因为我不再需要更改功能,只需显示。)

I have the full versions of adobe acrobat installed on my computer. It is not the reader.

我的计算机上安装了完整版本的 adobe acrobat。它不是读者。

Thank you for any help.

感谢您的任何帮助。

edit: There is an example in vb in the adobe acrobat sdk. I believe it is called activeview.

编辑:adobe acrobat sdk 中的 vb 中有一个示例。我相信它被称为activeview。

回答by Andy Webb

IText#may help you out.

IText#可以帮到你。

You can create PDF's and I believe you can use it to read and modify them.

您可以创建 PDF,我相信您可以使用它来阅读和修改它们。

As for displaying in the app..... I am not sure how to display them with iText or if it is possible (have not tried this yet), sorry. iText does let you convert to RTF which may be one approach.

至于在应用程序中显示..... 我不知道如何用 iText 显示它们,或者是否可能(还没有尝试过),抱歉。iText 确实可以让您转换为 RTF,这可能是一种方法。

回答by Dimi Takis

Using a webbrowser control would be an option to display the content.

使用 webbrowser 控件将是显示内容的一个选项。

回答by Josh Mein

you can check out ABCpdf. I dont know if it has this capability but we have used it for several of our apps

您可以查看ABCpdf。我不知道它是否有这个功能,但我们已经将它用于我们的几个应用程序

回答by psamwel

Best option is to write a listener which tells your calling code when Adobe.exe is no longer running. Something like the following (with tweaks for your uses) should work:

最好的选择是编写一个侦听器,当 Adob​​e.exe 不再运行时,它会告诉您的调用代码。类似于以下内容(针对您的用途进行调整)应该可以工作:

public void Open(string myPath)
{
    Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
    Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
    Acrobat.AcroPDDoc _pdDoc = null;
    _acroDoc.Open(myPath, "test");
    _pdDoc = (Acrobat.AcroPDDoc) (_acroDoc.GetPDDoc());
    _acroDoc.SetViewMode(2);
    _myAdobe.Show();
    NotifyAdobeClosed += new EventHandler(Monitor_NotifyAdobeClosed);
    MonitorAdobe();
}
private void Monitor_NotifyAdobeClosed(object sender, EventArgs e)
{
    NotifyAdobeClosed -= Monitor_NotifyAdobeClosed;
    //Do whatever it is you want to do when adobe is closed.
}

private void MonitorAdobe()
{
    while(true)
    {
        var adcount = (from p in Process.GetProcesses()
                       where p.ProcessName.ToLower() == "acrobat"
                       select p).Count();
        if (adcount == 0)
        {
            OnNotifyAdobeClosed();
            break;
        }
    }
}

public event EventHandler NotifyAdobeClosed;
public void OnNotifyAdobeClosed()
{
    if (NotifyAdobeClosed != null)
        NotifyAdobeClosed(this, null);
}