#1 2007-10-10 10:29

Cld
Member
Registered: 2006-12-10
Posts: 7

PDF tags (pdfinfo.exe)

Hello Denis,
I should have to rename a lot of pdf’s according to the title of the document, as Adobe shows when you display the document properties.
I have searched thru the various available meta tags, but I haven’t found anything about pdf.
Are there may be any royalty issues to insert them, or are there any other problems?

Thank you for your attention,
Claudio.

Offline

#2 2007-10-10 12:12

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: PDF tags (pdfinfo.exe)

Hi Claudio,

The problem is that extracting tags from PDF is no easy task, you'll nearly need to write an entire PDF parser to get that information. This is too big of a task, and there are no open source libraries for Delphi to parse PDFs. Anyway, there is possibility of using a 3-rd party executable tool to extract the tags from PDF, and then with a help of PascalScript, use them within ReNamer. This way had already been used to read exif date from RAW images.

The package that we need is called Xpdf (www.foolabs.com/xpdf). It has a command line tool pdfinfo.exe which we will use to extract the PDF tags. Extract that tool and place it into ReNamer's folder. Then use the script below. You can change the tag name which you want to use by changing the PDF_TAG constant at the top of the script.

Note1: This has been done with ReNamer 5.10 beta, and pdfinfo.exe 3.02. As both tools update, this script may require minor changes.

Note2: I've put together a PDF Ready version of ReNamer, which is available from downloads section.

{ 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.

Offline

#3 2007-10-10 13:49

Cld
Member
Registered: 2006-12-10
Posts: 7

Re: PDF tags (pdfinfo.exe)

Denis,
I’m absolutely impressed about your efficiency… it works like a charm.
I have just a little problem about some character that could exist in the title, but they aren’t accepted as filename, like the slash “/”. I’ll create another rule to change these characters with something of different, a sort of “filename cleaner”, according to filename rules.

It’s time to do another little donation… smile

Best regards,
Claudio.

Offline

#4 2016-04-26 21:42

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Re: PDF tags (pdfinfo.exe)

den4b wrote:

Note2: I've put together a PDF Ready version of ReNamer, which is available from downloads section.

Hi folks.  I just found this thread by doing a forum search.  Metadata from pdfs is exactly what I need to use...  Is the above referenced download still available?  I see the "additional downloads," but they appear to just be prior versions of ReNamer.
Thanks.

Offline

#5 2016-04-27 10:23

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: PDF tags (pdfinfo.exe)

kunkel321 wrote:

Is the above referenced download still available?

No, that bundle is not available anymore, but you can easily make it yourself.

Here are the instructions and an updated script:
http://www.den4b.com/wiki/ReNamer:Scripts:Xpdf

P.S. Wow, this thread is nearly 10 years old!

Offline

#6 2016-04-27 16:06

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Re: PDF tags (pdfinfo.exe)

Thanks for the fast reply Dennis!  Okay more questions now...
I downloaded the code here   http://www.den4b.com/wiki/ReNamer:Scripts:Xpdf  and saved it in/as C:\Program Files (x86)\ReNamer\Scripts\XPDFscript.pas.  I also downloaded the xpdf zip, opened it, and put it here:  C:\Program Files (x86)\ReNamer\xpdfbin-win-3.04.  Iv'e never tried to do a script in ReNamer, but I'm guessing I add a "PascalScript" item.  Doing this seems to work.  I see "XPDFscript" when I click the little lightning bolt.  The script seems to compile too.  However when the preview is attempted, I get an error about jpeg8.dll missing.  I located a copy of the dll on line and put it here: C:\Program Files (x86)\ReNamer\xpdfbin-win-3.04\Jpeg8.dll.  Then I tried to recompile the script, but I'm getting the same error...  Any ideas? 
-Firstly, does my overall use of the code/script seem correct?
-Also, should the dll go in another location?  Maybe in C:\Windows, or some program data folder?? 
Thanks.  -steve
EDIT:  I should also point out that I'm not even trying to do anything with Jpegs (at least I don't think I am!)  It's the "Authors" and "Title" that I want to extract.
Later Edit:  I actually did put that in C:\Windows\SysWOW64.  I'm not getting a different error:
---------------------------
pdfinfo.exe - Application Error
---------------------------
The application was unable to start correctly (0xc0000043). Click OK to close the application.
---------------------------
OK   
---------------------------
I'll Google this and see if I can learn anything....

Last edited by kunkel321 (2016-04-27 22:30)

Offline

#7 2016-04-27 22:55

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: PDF tags (pdfinfo.exe)

The steps should be as follows:

1) Download xpdfbin-win-3.04.zip
2) Extract only pdfinfo.exe (32-bit version) and place in the same folder as ReNamer.exe.
3) Start ReNamer and add PascalScript rule, paste the code from the article.

There should be no need for any jpeg8.dll, so test it again using the instructions above.

Offline

#8 2016-04-28 02:20

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Re: PDF tags (pdfinfo.exe)

Thanks Dennis!  That does, indeed, work.
Is it possible to have the script append the metadata tag to the new file name, rather than replacing it?  It appears that no matter what rename steps are ahead of the PascalScript, they get over-written.

Offline

#9 2016-04-28 11:14

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: PDF tags (pdfinfo.exe)

kunkel321 wrote:

It appears that no matter what rename steps are ahead of the PascalScript, they get over-written.

The example script just replaces the current name, leaving only the original extension untouched.

To append the meta tag to the end of the file name, find the following line:

FileName := Matches[0] + WideExtractFileExt(FileName);

And replace it with:

FileName := WideExtractBaseName(FileName) + ' ' + Matches[0] + WideExtractFileExt(FileName);

Offline

#10 2016-04-28 13:58

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 38

Re: PDF tags (pdfinfo.exe)

It's a beautiful thing!   Of course now I'll need more that 5 rules...  That's okay though.  I've been meaning to upgrade to some time now.   I'm only a "hobbyist" but I've used ReNamer dozens (hundreds?) of times over the years.  Thanks again Dennis.  I've got a couple more tweaks to make to the script, but I'll do some homework before posting anymore questions.  smile

Offline

Board footer

Powered by FluxBB