Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1164
  • Last Modified:

Acrobat Issue

I'm trying to automate opening Acrobat Reader and printing a pdf file using the Acrobat ActiveX control.  I create the PDF control just fine, but for one reason or another the LoadFile fails.  I think I'm missing something, because Acrobat Reader is not showing up in the task manager.  I'm using Acrobat 6.0 and MS Visual C++ .NET 2003 (7.1).  Does anyone know what I'm doing wrong?  Any help would be greatly appreciated.  

#include <iostream>
#include <string>

#import "C:\PROGRA~1\Adobe\ACROBA~1.0\Reader\ActiveX\pdf.tlb"

using namespace std;

int main()
{
  CoInitialize(NULL);
  try
  {
    PdfLib::_DPdfPtr pdf;
    HRESULT hr = pdf.CreateInstance("PDF.PdfCtrl.5"); // Returns S_OK
    hr = pdf->LoadFile("c:\\vpd.pdf"); // Throws error
    hr = pdf->Print();
  }
  catch(_com_error &ce)
  {
    string error = ce.ErrorMessage(); // Error says "Catastrophic failure"
  }

  CoUninitialize();
}
0
mnashadka
Asked:
mnashadka
1 Solution
 
AmitAgarwalCommented:
I guess you have to take the memership of the Adobe to get the SDK.
Because there might be lot of internal flags which you are not aware of may be set before you call LoadFile

amit
0
 
AndyAinscowCommented:
Does the file exist and is it a pdf file?
0
 
mnashadkaAuthor Commented:
Yes, the file exists and is a pdf file.  I even moved it to the root of the C: drive so that I could avoid any issues with spaces in the file name or whatever.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
AndyAinscowCommented:
Does the LoadFile function require any other options setting?  
0
 
mnashadkaAuthor Commented:
That's what I'm asking.  There is very little in the imported tlh file as far as member functions, and nothing that looked obvious.
0
 
clockwatcherCommented:
Per the Acrobat SDK docs, Acrobat Reader doesn't support OLE automation.  Supposedly you'd have to use DDE.  The full blown Acrobat does support automation.  Here's a sample that prints a page.

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

#import "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\acrobat.tlb"

int _tmain(int argc, _TCHAR* argv[])
{

  CoInitialize(NULL);
  try
  {
        Acrobat::CAcroAVDocPtr pAVdoc("AcroExch.AVDoc");
        pAVdoc->Open("c:\\testsign.pdf", "");
        pAVdoc->PrintPagesSilent(0, 0, 1, 0, 1);
        pAVdoc->Close(1);
  }
  catch(_com_error &ce)
  {
    string error = ce.ErrorMessage(); // Error says "Catastrophic failure"
  }

  CoUninitialize();
}

The PDF.tlb you're referencing deals with the PDF.ocx control and I'm pretty sure that has to be hosted within a container for you to get it to work.
0
 
mnashadkaAuthor Commented:
Thanks clockwatcher, that's exactly what I needed.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now