Difference between revisions of "ReNamer:Scripts:Xpdf"

From den4b Wiki
Jump to navigation Jump to search
(→‎Code: source tag)
(Updated script for ReNamer 5.70 and Xpdf 3.03)
Line 2: Line 2:
  
 
== Requirements ==
 
== Requirements ==
* ReNamer 5.10 Beta
+
* ReNamer 5.70
* [http://www.foolabs.com/xpdf/download.html pdfinfo.exe] 3.02 in ReNamer's folder
+
* [http://www.foolabs.com/xpdf/download.html pdfinfo.exe] 3.03 in ReNamer's folder
  
 
== Code ==
 
== Code ==
  
Author: Denis Kozlov. Date: 10 Oct 2007. Modify the PDF_TAG constant to specify which tag you want to extract. For the list of available tags consult Xpdf web site or pdfinfo.exe command line tool.
+
Author: Denis Kozlov. Date: 2013-04-01. Modify the <code>TAG</code> constant to specify which tag you want to extract. For the list of available tags consult [http://www.foolabs.com/xpdf/ Xpdf] web site or <code>pdfinfo.exe</code> command line tool.
  
 
<source>
 
<source>
{ Extract PDF tag }
+
{ Extract PDF tags using Xpdf }
 
+
 
const
 
const
   PDF_INFO = 'pdfinfo.exe';
+
   EXE = 'pdfinfo.exe';
   PDF_TAG = 'Title';
+
   TAG = 'Title\s*\:\s*(.*?)[\r\n]';
 
+
function ExtractTagPDF(const Info, Tag: string): string;
 
 
var
 
var
   Lines: TStringsArray;
+
   Command, Output: String;
   I, Delim: Integer;
+
   Matches: TStringsArray;
 +
 
begin
 
begin
   Result := '';
+
   Command := '"'+EXE+'" "'+FilePath+'"';
   Lines := WideSplitString(Info, #13#10);
+
   if ExecConsoleApp(Command, Output) = 0 then
  for I := 0 to Length(Lines)-1 do
 
  if WideSameText(Tag, Copy(Lines[i], 1, Length(Tag))) then
 
 
   begin
 
   begin
     Delim := WidePos(':', Lines[i]);
+
     Matches := SubMatchesRegEx(Output, TAG, False);
     if Delim > 0 then
+
     if Length(Matches) > 0 then
    begin
+
       FileName := Matches[0] + WideExtractFileExt(FileName);
       Result := WideCopy(Lines[i], Delim+1, WideLength(Lines[i]));
 
      Result := Trim(Result);
 
    end;
 
 
   end;
 
   end;
end;
 
 
var
 
  Command, Output: string;
 
  TagValue: string;
 
 
begin
 
  Command := '"'+PDF_INFO+'" "'+FilePath+'"';
 
  ExecConsoleApp(Command, Output);
 
  TagValue := ExtractTagPDF(Output, PDF_TAG);
 
  FileName := TagValue + WideExtractFileExt(FileName);
 
 
end.
 
end.
 
</source>
 
</source>

Revision as of 13:22, 1 April 2013

Script integrates Xpdf command line tool in order to extract PDF tags.

Requirements

Code

Author: Denis Kozlov. Date: 2013-04-01. Modify the TAG constant to specify which tag you want to extract. For the list of available tags consult Xpdf web site or pdfinfo.exe command line tool.

{ Extract PDF tags using Xpdf }
 
const
  EXE = 'pdfinfo.exe';
  TAG = 'Title\s*\:\s*(.*?)[\r\n]';
 
var
  Command, Output: String;
  Matches: TStringsArray;  
 
begin
  Command := '"'+EXE+'" "'+FilePath+'"';
  if ExecConsoleApp(Command, Output) = 0 then
  begin
    Matches := SubMatchesRegEx(Output, TAG, False);
    if Length(Matches) > 0 then
      FileName := Matches[0] + WideExtractFileExt(FileName);
  end;
end.