1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <utilcls.h> // <---- ne pas oublier
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Variant vAcrobatApp, vAcrobatPDDoc, PDDocument;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// executer l'application
vAcrobatApp = CreateOleObject("AcroExch.App");
// executer le document
// vAcrobatPDDoc = CreateOleObject("AcroExch.PDDoc");
vAcrobatPDDoc = CreateOleObject("AcroExch.AVDoc");
// ouvrir acrobat vide
vAcrobatApp.OleFunction("Show");
// deux facon d'ouvrir un fichier
vAcrobatPDDoc.OleFunction("Open", "C:\\essaipdf.pdf", true);
// vAcrobatPDDoc.OleFunction("OpenAVDoc", "C:\\essaipdf.pdf");
// rendre acrobat invisible
// vAcrobatApp.OleFunction("Hide");
// PDDocument = vAcrobatPDDoc.OleFunction("GetActiveDoc"); // GetPDDoc
// int NumPages = (vAcrobatPDDoc.OleFunction("GetNumPages") - 1);
long retVal = vAcrobatPDDoc.OleFunction("PrintPagesSilent",
0, // First page
-1, // Last page (-1 is all pages)
1, // Postscript level
0, // Binary ok
1 // Shrink to fit
);
// if (retVal != 0)
// AfxMessageBox(_T("The Print was a success"));
// iNumPages = PDDoc.GetNumPages
//AVDoc.printPagesSilent 0, iNumPages - 1, 2, True, true
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
vAcrobatPDDoc.OleFunction("Close");
vAcrobatApp.OleFunction("CloseAllDocs");
vAcrobatApp.OleFunction("Exit");
vAcrobatPDDoc = Unassigned;
vAcrobatApp = Unassigned;
}
//--------------------------------------------------------------------------- |
Partager