unit Pdf_vers_Text_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, OleCtrls, AcroPDFLib_TLB, StdCtrls, ComObj, ActiveX;
type
TForm1 = class(TForm)
ToolBar1: TToolBar;
LectureDocument: TToolButton;
StatusBar1: TStatusBar;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
AcroPDF1: TAcroPDF;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
procedure FormActivate(Sender: TObject);
procedure LectureDocumentClick(Sender: TObject);
procedure LectureDocumentMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Procedure SimuClavierCtrl_(var C : Char);
procedure Souris_ClickGauche( );
Procedure SimuClavierCtrl_s(Const s : String);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
function IsOLEObjectInstalled(Name: String): Boolean;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Dйclarations privйes }
public
{ Dйclarations publiques }
end;
var
Form1: TForm1;
on_ : wordbool = true;
Handle1 : integer ;
filename : string;
App, doc: OleVariant;
pagesCount: Integer;
PDDoc,AVDoc,AVPageView:variant;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
AVDoc := App.GetActiveDoc() ;
AVPageView := AVDoc.GetAVPageView();
pagesCount := AVPageView.GetPageNum;
ShowMessageFmt('pages count = %d', [pagesCount]);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
//
PageControl1.TabIndex := 0;
IF ParamCount < 1 then
edit1.Text := ExtractFilePath( application.ExeName )+'*.pdf';
IF ParamCount >0 THEN
caption :='NB DE PARAMETRES / '+ paramstr(1)+' - '+inttostr(ParamCount);
if trim(paramstr(1)) <>'' then
begin
if pos('.pdf', paramstr(1)) > 0 then
edit1.Text := paramstr(1) ;
end ;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
Ref : Integer;
begin
Ref := AcroPDF1.ControlInterface._AddRef;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
filename:='D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf';
end;
procedure TForm1.LectureDocumentClick(Sender: TObject);
begin
{ if IsOLEObjectInstalled('AcroExch.PDDoc') then
begin
doc := CreateOleObject('AcroExch.PDDoc');
if doc.Open('D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf') then
begin
pagesCount := doc.GetNumPages;
ShowMessageFmt('pages count = %d', [pagesCount]);
end
else
begin
ShowMessage('файл не открыт');
end;
end
else
begin
ShowMessage('установи adobe acrobat');
end;
}
//AcroPDF1.src := 'D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf';
if not FileExists('D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf') then EXIT ;
PageControl1.TabIndex := 0;
sleep(100);
statusbar1.Panels[1].Text := 'nl : ' ;
TRY
AcroPDF1.LoadFile('D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf' ) ;
AcroPDF1.SetFocus;
AcroPDF1.setShowToolbar(on_);
AcroPDF1.gotoFirstPage;
Except
showmessage('ошибка открытия pdf'#10 + edit1.Text ); exit;
end;
end;
function TForm1.IsOLEObjectInstalled(Name: String): Boolean;
var
ClassID: TCLSID;
Rez: HRESULT;
begin
Rez := CLSIDFromProgID(PWideChar(WideString(Name)), ClassID);
Result := (Rez = S_OK);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if IsOLEObjectInstalled('AcroExch.PDDoc') then
begin
doc := CreateOleObject('AcroExch.PDDoc');
if doc.Open('D:\моя работа\Программирование\НВТП 11 класс\пдф\pdf\1.pdf') then
begin
pagesCount := doc.GetNumPages;
ShowMessageFmt('pages count = %d', [pagesCount]);
end
else
begin
ShowMessage('не открыт');
end;
end
else
begin
ShowMessage('установи adobe acrobat');
end;
end;
procedure TForm1.LectureDocumentMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if x > (LectureDocument.Width div 2) then LectureDocument.Tag := 1
else LectureDocument.Tag :=-1;
statusbar1.Panels[0].Text := inttostr(x)+ ' '+ inttostr(LectureDocument.Tag) ;
end;
procedure TForm1.Souris_ClickGauche( );
begin
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0) ; //
SLEEP(50);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0) ;
SLEEP(50);
END;
Procedure TForm1.SimuClavierCtrl_s(Const s : String);
var c_ : Char;
begin
c_ := Char(s[1]) ;
SimuClavierCtrl_(C_);
end;
Procedure TForm1.SimuClavierCtrl_(var C : Char);
begin
keybd_event(VK_LCONTROL,0,0,0);
sleep(50);
keybd_event(Ord(C),0,0,0);
sleep(50);
keybd_event(Ord(C),0,KEYEVENTF_KEYUP,0);
sleep(50);
keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0);
sleep(50);
application.ProcessMessages;
//
end;
end.