views:

2568

answers:

4

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

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.

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

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?

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.)

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

Thank you for any help.

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

A: 

IText# may help you out.

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

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.

Andy Webb
A: 

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

Greco
+1  A: 

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

jmein
A: 

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:

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);
}
Peter Samwel