Solved

Acrobat Issue

Posted on 2003-11-06
7
1,157 Views
Last Modified: 2007-12-19
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
Comment
Question by:mnashadka
7 Comments
 
LVL 4

Expert Comment

by:AmitAgarwal
ID: 9697452
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9701979
Does the file exist and is it a pdf file?
0
 
LVL 8

Author Comment

by:mnashadka
ID: 9701994
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9702005
Does the LoadFile function require any other options setting?  
0
 
LVL 8

Author Comment

by:mnashadka
ID: 9702016
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
 
LVL 25

Accepted Solution

by:
clockwatcher earned 250 total points
ID: 9708187
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
 
LVL 8

Author Comment

by:mnashadka
ID: 9715397
Thanks clockwatcher, that's exactly what I needed.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question