需要的环境:Adobe Acrobat 7.0 Professional  和   Quite Imposing Plus 1.5d Acrobat plugin  (qi160.exe)

程序界面:

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, RzTray, Vcl.ExtCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
edtDownNum: TEdit;
Label3: TLabel;
Label4: TLabel;
BalloonHint1: TBalloonHint;
TrayIcon1: TTrayIcon;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses shellapi;
{$R *.dfm}

function Matchstrings(Source, pattern: String): Boolean;
var
pSource: array[0..255] of Char;
pPattern: array[0..255] of Char;
function MatchPattern(element, pattern: PChar): Boolean;
function IsPatternWild(pattern: PChar): Boolean;
begin
Result := StrScan(pattern, '*') <> nil;
if not Result then
Result := StrScan(pattern, '?') <> nil;
end;
begin
if 0 = StrComp(pattern, '*') then
Result := True
else if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
Result := False
else if element^ = Chr(0) then
Result := True
else
begin
case pattern^ of
'*':
if MatchPattern(element, @pattern[1]) then
Result := True
else
Result := MatchPattern(@element[1], pattern);
'?':
Result := MatchPattern(@element[1], @pattern[1]);
else
if element^ = pattern^ then
Result := MatchPattern(@element[1], @pattern[1])
else
Result := False;
end;
end;
end;
begin
StrPCopy(pSource, Source);
StrPCopy(pPattern, pattern);
Result := MatchPattern(pSource, pPattern);
end; {匹配字符串函数}

{从磁盘中搜索指定类型的所有文件}
procedure FindFiles(ASourceDir, SearchFileType: String; var List: TStrings);
var
FileRec: TSearchrec;
Sour: String;
begin
Sour := ASourceDir;
if Sour[length(Sour)] <> '\' then
Sour := Sour + '\';
if FindFirst(Sour + '*.*', faAnyfile, FileRec) = 0 then
{循环}
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if (FileRec.Name <> '.') and (FileRec.Name <> '..') then //找到目录
begin
FindFiles(Sour + FileRec.Name, SearchFileType, List);
end;
end
else //找到文件
begin
if Matchstrings(AnsiLowerCase(FileRec.Name), SearchFileType) then
begin
List.Add(Sour + FileRec.Name);
end; {拷贝所有类型的文件}
end;
until FindNext(FileRec) <> 0;
FindClose(FileRec);
end; {从磁盘中搜索指定类型的所有文件}

function ForceForegroundWindow(hwnd: HWND): Boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID: DWORD;
timeout: DWORD;
begin
if IsIconic(hwnd) then
ShowWindow(hwnd, SW_RESTORE);
// if not IsWindowVisible(hwnd) then
// ShowWindow(hwnd, SW_SHOWNOACTIVATE);

if GetForegroundWindow = hwnd then
Result := True
else
begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)))) then
begin
Result := False;
ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
ThisThreadID := GetWindowThreadPRocessId(hwnd, nil);
if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
begin
BringWindowToTop(hwnd);
SetForegroundWindow(hwnd);
AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
Result := (GetForegroundWindow = hwnd);
end;
if not Result then
begin
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(0), SPIF_SENDCHANGE);
BringWindowToTop(hWnd);
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(timeout), SPIF_SENDCHANGE);
end;
end
else
begin
BringWindowToTop(hWnd);
SetForegroundWindow(hwnd);
end;

Result := (GetForegroundWindow = hwnd);
end;
end;

procedure pressButtonDown(btn:Thandle);
begin
postMessage(btn,WM_LBUTTONDOWN,VK_LBUTTON,0); // MK_LBUTTON 0231028E $1f0028
postMessage(btn,WM_LBUTTONUP,0,0);
postMessage(btn,WM_LBUTTONDOWN,VK_LBUTTON,0); // MK_LBUTTON 0231028E $1f0028
postMessage(btn,WM_LBUTTONUP,0,0);
end;

function closeAboutWindow():boolean;
var
rundemo,btnHandle: Cardinal;
begin
result:=false;
rundemo:= findwindow('#32770','About Quite Imposing 1.6 (EN)');
if rundemo<>0 then
begin
SetForegroundWindow(rundemo);
btnHandle:= findwindowex(rundemo,0,'Button','Run &demo');
if btnHandle<>0 then
begin
pressButtonDown(btnHandle);
result:=true;
end;
end;
end;

function PDFisOpen():boolean;
var readerHandle,mdiHandle,mdiHandle2:Cardinal;
Title: array[0..255] of Char;
begin
readerHandle:= findwindowEx(0,0,'AdobeAcrobat',nil);
result:=false;
if readerHandle<>0 then
begin

mdiHandle:= findwindowex(readerHandle,0,'MDIClient',nil);
if mdiHandle<>0 then
begin
mdiHandle2:= findwindowex(mdiHandle,0,'AcrobatMDIChildWnd',nil);
GetWindowText(mdiHandle2, Title, SizeOf(Title));
// showmessage('AcrobatMDIChildWnd='+string(Title));
if pos('.pdf',ansilowercase(string(Title)))>0 then
result:=true;

end;
end;
end;

function kuoBianAction():boolean;
var readerHandle:Cardinal;
mdiHandle: Cardinal;
mdiHandle2: Cardinal;

trimHandle: Cardinal;
ImpositionHandle: Cardinal;
DownNum: Integer;
NextBtn: Cardinal;
begin
readerHandle:= findwindowEx(0,0,'AdobeAcrobat',nil);

result:=false;
DownNum:=0;

if readerHandle<>0 then
begin
SetForegroundWindow(readerHandle);
// ForceForegroundWindow(readerHandle);
// form1.Memo1.Lines.Add('find AdobeAcrobat');

//Alt+P
keybd_event(18, MapVirtualKey(18, 0), 0, 0);
keybd_event(80, MapVirtualKey(80, 0), 0, 0);
keybd_event(80, MapVirtualKey(80, 0), KEYEVENTF_KEYUP, 0);
keybd_event(18, MapVirtualKey(18, 0), KEYEVENTF_KEYUP, 0);

DownNum:=strtointdef(form1.edtDownNum.Text,1); //工具菜单光标首次下移多少次

while DownNum>0 do
begin

sleep(100);
//方向键down (1次)
keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), 0, 0);
keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), KEYEVENTF_KEYUP, 0);

dec(DownNum);
end;

sleep(200);

//方向键 right(1次)
keybd_event(VK_RIGHT, MapVirtualKey(VK_RIGHT, 0), 0, 0);
keybd_event(VK_RIGHT, MapVirtualKey(VK_RIGHT, 0), KEYEVENTF_KEYUP, 0);

sleep(200);

//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);

sleep(200);

//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);

sleep(200);

//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);

sleep(100);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);

while not closeAboutWindow() do
begin
sleep(200);
closeAboutWindow();
break;
end;

sleep(500);
trimHandle:=findwindowex(0,0,'#32770','Trim and shift 1 - page selection');

while trimHandle=0 do
begin
application.ProcessMessages ;
trimHandle:=findwindowex(0,0,'#32770','Trim and shift 1 - page selection');
end;

if trimHandle<>0 then
begin
// SetForegroundWindow(trimHandle);
ForceForegroundWindow(trimHandle);
// form1.Memo1.Lines.Add('find Trim and shift 1 - page selection');

sleep(1000);

NextBtn:= findwindowex(trimHandle,0,'Button','&Next');

while NextBtn=0 do
begin
application.ProcessMessages ;
NextBtn:= findwindowex(trimHandle,0,'Button','&Next');
end;

if NextBtn<>0 then
begin
pressButtonDown(NextBtn);
end
else
begin
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
end;

NextBtn:=0;

sleep(1000);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);

sleep(1000);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);

// sleep(300);

while True do
begin
application.ProcessMessages ;
// sleep(100);
ImpositionHandle:=findwindow(nil,'Imposition');
if ImpositionHandle>0 then
begin
break;
end;
end;

while True do
begin

application.ProcessMessages ;
ImpositionHandle:=findwindow(nil,'Imposition');
if ImpositionHandle=0 then
begin
// showmessage('find Imposition window');
//form1.Memo1.Lines.Add('本次扩边完毕!');

//Ctrl+S 保存
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(83, MapVirtualKey(83, 0), 0, 0);
keybd_event(83, MapVirtualKey(83, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);

sleep(3000);

//Ctrl+W 关闭
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(87, MapVirtualKey(87, 0), 0, 0);
keybd_event(87, MapVirtualKey(87, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);

break;

end;
end;

result:=true;
end;

end;

end;

procedure TForm1.Button2Click(Sender: TObject);
var
pdflist,configFile: TStrings;
i: integer;
label ok;
begin
//开始扩边
// Memo1.Clear ;
pdflist:=tstringlist.Create ;
configFile:=tstringlist.Create ;

configFile.Add('pdfpath='+edit1.Text); //PDF所在路径
configFile.Add('acrobat7='+edit2.Text); //Acrobat7完整路径
configFile.Add('DownNum='+trim(edtDownNum.Text));

configFile.SaveToFile(extractfilepath(application.ExeName)+'setinfo.txt');

findfiles(edit1.Text,'*.pdf',pdflist);

try
for i := 0 to pdflist.Count-1 do
begin
application.ProcessMessages ;
shellexecute(handle,'open',pchar(edit2.Text),pchar(pdflist[i]),nil,1);

while True do
begin
application.ProcessMessages ;
if PDFisOpen() then //文件已经打开
begin
ok:
application.ProcessMessages ;

if kuoBianAction() then //扩边
begin
if i=pdflist.Count-1 then
begin
TrayIcon1.BalloonTimeout:=30000;
TrayIcon1.BalloonTitle:='全部扩边完毕';
end;
TrayIcon1.BalloonTitle:='共有 '+inttostr(pdflist.Count)+' 个PDF ';
TrayIcon1.BalloonHint:='已处理:'+inttostr(i+1)+' 个PDF!';
TrayIcon1.ShowBalloonHint;
break;
end
else
goto ok;

end;

end;
self.Caption:='已处理('+inttostr(i+1)+')';
end;

finally
freeandnil(configFile);
freeandnil(pdflist);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var loadCfg:Tstrings;
begin
self.KeyPreview:=false;
edit1.Clear ;
edit2.Clear ;
//edit1.Text:='E:\tools\data';
//edit2.Text:='F:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe';
loadCfg:=tstringlist.Create ;
try
if fileExists(extractfilepath(application.ExeName)+'setinfo.txt') then
begin
loadCfg.LoadFromFile(extractfilepath(application.ExeName)+'setinfo.txt');
edit1.Text:=loadCfg.Values['pdfpath'];
edit2.Text:=loadCfg.Values['acrobat7'];
edtDownNum.Text:=loadCfg.Values['DownNum'];
end;
finally
freeandnil(loadCfg);
end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
var other:Thandle;
begin
{ other:=findwindow('#32770','Trim and shift - advanced options');
if other<>0 then
begin
postmessage(other,wm_close,0,0);
end;
}
end;

end.

delphi模拟按键精灵自动控制PDF页面自动扩边的源代码的更多相关文章

  1. 【按键精灵篇】如何做一个自动打开APP进入注册页面自动输入自己手机号

    按键精灵,虽然很早听过,但是一直没有真正使用过,所以最近有点时间也简单试一下,通过脚本自动清理APP缓存,打开百家号并自动进入注册页面输入自己的手机号. 软件清单 1. 雷电手机模拟器:https:/ ...

  2. 转:Android随笔之——使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)

    本文转载自CSDN的jzj1993,原文连接:http://blog.csdn.net/jzj1993/article/details/39158865 有时我们需要使用安卓实现在后台模拟系统按键,比 ...

  3. delphi 向其他程序发送模拟按键

    向其他程序发送模拟按键: 1.用keybd_event: varh : THandle;beginh := FindWindow('TFitForm', '1stOpt - [Untitled1]') ...

  4. 【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】

    通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵! 主要代码如下: library KeyBoardHook; { Important note about DLL memory ...

  5. 将HTML页面自动保存为PDF文件并上传的两种方式(一)-前端(react)方式

    一.业务场景 公司的样本检测报告以React页面的形式生成,已调整为A4大小的样式并已实现分页,业务上需要将这个网页生成PDF文件,并上传到服务器,后续会将这个文件发送给客户(这里不考虑). 二.原来 ...

  6. 安卓使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)

    继续在网上搜索安卓按键模拟(其实那时都不知道用什么关键字好了,能想到的关键字都用遍了,但是搜索出来的结果,都是之前提到的那几个依赖源码环境和系统权限的方案).发现有很多介绍ADB调试,向手机发送按键事 ...

  7. GitHub Java项目推荐|不需要 ROOT权限的类似按键精灵的自动操作

    不需要 ROOT 权限的类似按键精灵的自动操作软件,可以实现自动点击.滑动.输入文字.打开应用等.Auto.js 的大部分用户用它来点赞.签到.刷游戏 项目分析 仓库名称:Auto.js 标星(sta ...

  8. Delphi驱动方式WINIO模拟按键 可用

    http://www.delphitop.com/html/yingjian/152.html Delphi驱动方式WINIO模拟按键 作者:admin 来源:未知 日期:2010/2/1 1:14: ...

  9. 按键精灵如何调用Excel及按键精灵写入Excel数据的方法教程---入门自动操作表格

    首先来建立一个新的Excel文档,在桌面上点击右键,选择[新建]-[Excel工作表],命名为[新手学员]. 现在这个新Excel文档是空白的,我们接下来会通过按键精灵的脚本来打开并写入一些数据.打开 ...

随机推荐

  1. day15_集合第一天

    1.集合体系 红色为今天所学 Collection                          (接口)|--List                       (接口) 元素有序,可以重复 ...

  2. poj 3463 最短路与次短路的方案数求解

    Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8968   Accepted: 3139 Descr ...

  3. 通过SSH远程使用ipython notebook

    本文讲述如何在本地用浏览器运行远程服务器上的iPython notebook服务. 在远程机器上,启动IPython notebooks服务: remote_user@remote_host$ ipy ...

  4. 创建Windows截图工具的快捷方式

    日常生活中我们会用到好多截图,一般截图我们用QQ自带截图较多,但许多人都忽视了电脑自带截图功能.在我的电脑-->附件-->截图工具   按照上述方式找截图工具比较繁琐,今天我们可以通过快捷 ...

  5. JPush极光推送Java服务器端API

    // 对android和ios设备发送 JPushClient jpush = new JPushClient(masterSecret, appKey);   // 对android和ios设备发送 ...

  6. mm/swap

    /* *  linux/mm/swap.c * *  Copyright (C) 1991, 1992  Linus Torvalds */ /* * This file should contain ...

  7. 旅行家的预算 1999年NOIP全国联赛普及组NOIP全国联赛提高组

     时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 一个旅行家想驾驶汽车以最少的费用从一个城市到另一个城市(假设出发时油箱是空的).给定两个城市之间的距离D1.汽车 ...

  8. H20的题——[noip2003]银河英雄传(并查集)

    公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰山压顶集团派宇 ...

  9. uva 10622

    http://vjudge.net/contest/140673#problem/H 求某个数字(最大到10^9,可为负值)写成完全p次方数的指数p是多少 分析: 先进行唯一分解,之后p整除各个素因子 ...

  10. Android Studio debug使用release的签名

    当我们在做微信微博sdk分享的时候调试非常麻烦,因为要使用对应的签名版本才能调用sdk成功. 当我们使用AndroidStudio的Gradle之后会很简单的解决这个问题. 1.我们把签名文件放到工程 ...