//-----------------------------------------------------------------
//目的: 得到PRN文件信息
//参数: sFileName:文件名称
// psCaption:文档名称(传指针)
// psSize:文档尺寸(传指针)
//返回值:布尔
//programed by Star Song 2002-09-16
//-----------------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
var
F: TextFile;
sTextLine: String;
sText,s1,s: String;
sSubCaption:String;
sSubSize: String;
iPosbegin
: Integer;
iPosEnd: Integer;
i,PCount: Integer;
CopyCount: Integer;
PageSize,sFileName: String;
begin
try
sSubCaption:= '';
sSubSize:= '';
//读文件
AssignFile(F,sFileName);
Reset(F);
sText:= '';
while not eof(f)do
begin
ReadLn(F,sTextLine);
sText:= sText+ sTextLine;
end;
CloseFile(F);
//判断是否PCL6即PCL XL
//判断标志:PJL ENTER LANGUAGE=PCLXL;
{ if pos('PJL ENTER LANGUAGE=PCLXL',sText)>0 then
begin
msgbox('打印文件:' + sFileName + ' 不符合兼容要求,' + #13 + '请重新安装PCL 5版本的激光打印机驱动程序!'+ #13 + '此文件将不能打印!','打印管理',MB_OK);
i:= slFileNameRemove.IndexOf('sFileName');
if i<0 then
slFileNameRemove.Add(sFileName);
end;
}
//得到图纸名称
if Filename.Text<> '' then
begin
//取出文件的标题
if Pos('@PJL JOB NAME',sText)>0 then
begin
iPosbegin
:= Pos('@PJL JOB NAME',sText);
iPosEnd:= Pos('@PJL COMMENT',sText);
iPosbegin
:= iPosbegin
+ 13;
iPosEnd:= iPosEnd-2;
for i:=iPosbegin
To iPosEnddo
begin
sSubCaption:= sSubCaption + sText;
end;
//去掉图纸名称多余部分
// fucTrimDrawName(@sSubCaption);
end
else
begin
sSubCaption:= '';
end;
//psCaption^:= sSubCaption;
edit2.Text:= sSubCaption;
end;
// cbDrawSize.ReadOnly:= False;
//取出纸张的长度
// if psSize<> Nil then
// begin
if Pos('@PJL SET PAPER=',sText)>0 then
iPosbegin
:= Pos('@PJL SET PAPER=',sText)
// else
begin
//prn文件或某些plt文件不包含pjl头信息,原退出现改为:
//Result:= False;
//Exit;
//开始处理pcl数据
sTextLine := sText;
//计算页数
s1:= char(27)+char(42)+'b0M';
//页标记,HPLJ5000 PCL5
PCount:= 0;
if Pos(s1,sText)>0 then
begin
sText:= Copy(sText,Pos(s1,sText)+5,length(sText)-Pos(s1,sText)-5);
PCount:= 1;
// s:= Copy(sText,1,5);
while length(sText)>0do
begin
iPosbegin
:= Pos(s1,sText);
if iPosbegin
>0 then
begin
sText:= Copy(sText,Pos(s1,sText)+5,length(sText)-Pos(s1,sText)-5);
PCount:= PCount+1;
end
else
sText:='';
end;
end;
if PCount=0 then
PCount:= 1;
//查询打印份数
//Number of Copies of Copies (1 - 99)
//Ec&l#X (x)
//027 038 108 #...# 088 (120)
//1B 26 6C #. # 58 (78)
sText:= sTextLine;
s1:= char(27)+char(38)+char(108);
i:= 0;
CopyCount:= 0;
while Pos(s1,sText)>0do
begin
s:= Copy(sText,Pos(s1,sText)+3,3);
if (Pos('x',s)>0) or (Pos('X',s)>0) then
begin
if Pos('x',s)>0 then
i:= Pos('x',s);
if Pos('X',s)>0 then
i:= Pos('X',s);
s:= Copy(s,1,i-1);
CopyCount:= strtoint(s);
sText:= '';
end;
sText:= Copy(sText,Pos(s1,sText)+3,length(sText)-Pos(s1,sText)-3);
end;
if (CopyCount=0) and (PCount>0) then
CopyCount:=1;
//万一没有份数则为1
psCount^:= floattostr(CopyCount*PCount);
//查询纸张尺寸
//Page Size A4
//Ec&l26A (a)
//027 038 108 050 054 065 (097)
//1B 26 6C 32 36 41 (61)
PageSize:= '';
sText:= sTextLine;
s1:= char(27)+char(38)+char(108);
while Pos(s1,sText)>0do
begin
s:= Copy(sText,Pos(s1,sText)+3,3);
if (Pos('a',s)>0) or (Pos('A',s)>0) then
begin
if Pos('a',s)>0 then
i:= Pos('a',s);
if Pos('A',s)>0 then
i:= Pos('A',s);
s:= Copy(s,1,i-1);
if s='4' then
PageSize:= 'A5';
if s='26' then
PageSize:= 'A4';
if s='27' then
PageSize:= 'A3';
if s='100' then
PageSize:= 'B5';
sText:= '';
end;
sText:= Copy(sText,Pos(s1,sText)+3,length(sText)-Pos(s1,sText)-3);
end;
if (PageSize='') and (PCount>0) then
PageSize:='A4';
//万一没有则为A4
end;
iPosEnd:= Pos('@PJL SET TRAY1TEMP',sText);
iPosbegin
:= iPosbegin
+ 15;
iPosEnd:= iPosEnd-1;
for i:=iPosbegin
to iPosEnddo
begin
sSubSize:= sSubSize + sText;
end;
if PageSize='' then
begin
cbDrawSize.ReadOnly:= True;
psSize^:= sSubSize;
end
else
psSize^:= PageSize;
end;
//设置返回值
Result:= True;
except
Result:= False;
end;
end;
end.