ReNamer:Scripts:Xpdf

From den4b Wiki
Revision as of 02:04, 3 August 2009 by Den4b (talk | contribs) (→‎Code: source tag)
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.