#11 2016-04-28 14:27

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 2,813

Offline

#12 2016-05-01 19:17

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

Re: PDF tags (pdfinfo.exe)

Thanks for the resources Dennis.  Are there any examples of how to insert the content (the PDF tag, in this case) as a 'prefix' rather than a suffix?  I thought maybe the "move_to" command from here http://www.den4b.com/wiki/ReNamer:Scrip … me_portion, but I don't know...  This also makes me think of a feature idea, but I'll put that on a separate thread...

Offline

#13 2016-05-02 19:17

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: PDF tags (pdfinfo.exe)

FileName := WideExtractBaseName(FileName) + ' ' + Matches[0] + WideExtractFileExt(FileName);
    ↓                 ↓                      ↓          ↓                    ↓
new filename    base part of old filename   space    metatag      extension (last part) of old filename

This is just simple logic and common sense. All you need to do is move the metatag and space before the filename if you want to prepend rather than append it.

Of course if you're writing WideExtractBaseName(FileName) + WideExtractFileExt(FileName), then you might as well shorten it to simply FileName.

Offline

#14 2016-05-03 13:55

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

Re: PDF tags (pdfinfo.exe)

Hmm.. Yes, I guess that was a no-brainer!  Thanks Andrew smile

EDIT:
Just an extra note here, in case anyone else finds this thread via search, as I did.
My whole purpose was to rename a large number of ebooks that are in pdf format and give them a consistent naming structure.  It turns out that most of the pdfs are mission the metadata needed.  sad   
Also, the metadata tag is likely to have "invalid characters" that will get added to the file name.
I looked up which common characters are invalid for file/folder names in Windows.  Here they are as a list that you can paste (and save) as a custom Transliteration in list that changes them all to hyphens:

#=-
%=-
&=-
{=-
}=-
\=-
<=-
>=-
*=-
?=-
/=-
$=-
!=-
'=-
"=-
:=-
+=-
`=-
==-

It's interesting to note that the @ symbol and the space character " " were on the list.  I use both of those in file and folder names though, so I left them off of this list.

EDIT AGAIN: Actually I'm going to post this list as a separate thread...  It just occurred to me that maybe tilde "~" should be there...

Last edited by kunkel321 (2016-05-04 20:49)

Offline

#15 2019-09-06 02:59

jeffli
Member
From: den4b.com
Registered: 2019-01-22
Posts: 14
Website

Re: PDF tags (pdfinfo.exe)

Hi,
pdfinfo.exe default encoding is Latin1, which doesn't support Chinese characters. If Meta-data contains Chinese words, it will not display.
It should display:

ReNamer_Pro_7.1>pdfinfo.exe 3.pdf
Title:          标题abc1
Subject:        主题abc
Keywords:       关键字abc2

But it actually display:

ReNamer_Pro_7.1>pdfinfo.exe 3.pdf
Title:          abc1
Subject:        abc
Keywords:       abc2

Try running this, it works well:

pdfinfo.exe -enc UTF-8 1.pdf

If you want to support Chinese characters, Pascal script should be modified to:

const
  EXE = 'pdfinfo.exe -enc UTF-8';
  TAG = 'Title\s*\:\s*(.*?)[\r\n]';

var
  Command, Output: String;
  Matches: TWideStringArray;

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.    

Last edited by jeffli (2019-09-07 02:30)


Jeff

Offline

#16 2019-09-07 20:47

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 2,813

Re: PDF tags (pdfinfo.exe)

jeffli wrote:

Try running this, it works well:

pdfinfo.exe -enc UTF-8 1.pdf

Thanks for pointing this out. The script on the wiki has been updated accordingly.

http://www.den4b.com/wiki/ReNamer:Scripts:Xpdf

Offline

#17 2019-09-08 00:18

jeffli
Member
From: den4b.com
Registered: 2019-01-22
Posts: 14
Website

Re: PDF tags (pdfinfo.exe)

den4b wrote:
jeffli wrote:

Try running this, it works well:

pdfinfo.exe -enc UTF-8 1.pdf

Thanks for pointing this out. The script on the wiki has been updated accordingly.

http://www.den4b.com/wiki/ReNamer:Scripts:Xpdf

Hi,
You help us a lot, I'd really appreciate it and give positive feedback.


Jeff

Offline

Board footer

Powered by FluxBB