ReNamer:Scripts:Xpdf

From den4b Wiki
Revision as of 16:57, 23 June 2009 by Den4b (talk | contribs) (Created page with 'Script integrates [http://www.foolabs.com/xpdf/ Xpdf] command line tool in order to extract PDF tags. == Requirements == * ReNamer 5.10 Beta * [http://www.foolabs.com/xpdf/downl...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Requirements

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.

{ Extract PDF tag }

const
  PDF_INFO = 'pdfinfo.exe';
  PDF_TAG = 'Title';

function ExtractTagPDF(const Info, Tag: string): string;
var
  Lines: TStringsArray;
  I, Delim: Integer;
begin
  Result := '';
  Lines := WideSplitString(Info, #13#10);
  for I := 0 to Length(Lines)-1 do
  if WideSameText(Tag, Copy(Lines[i], 1, Length(Tag))) then
  begin
    Delim := WidePos(':', Lines[i]);
    if Delim > 0 then
    begin
      Result := WideCopy(Lines[i], Delim+1, WideLength(Lines[i]));
      Result := Trim(Result);
    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.