Skip to main content
K.Daube
Community Expert
Community Expert
Aug 8, 2023 10:38 AM UTC
Question

oFile.execute not that simple for *.bat files

Some information is available only by extracting it from a source by means of command-line programs. I wanted to get meta information (number of pages, etc.) out of PDF files. This can be done with xpdfinfo.exe (http://www.xpdfreader.com/).

Assume you have all ingredients in one directory (unfortunately a ZIP can not be attached, even with name XMP - so see my website)

 

ExecuteBatFile.jsx
GetPDFinfo.jsx
GetScriptPath.jsx
Message.jsx
PDF-6pages-landscape.pdf
pdfinfo.exe

 

If in the central part of function GetPDFinfo.jsx files are references relatively:

 

REM Generated by function GetPDFinfo
pdfinfo.exe FMjsxLib_lib_DOM.pdf > pdfinfo.txt

 

... the required batch file is produced within the current directory, it is also executed (a flicker indicates open/close of the console window) - but you do not thet the output text file.

Since the bat file is still there, you can double click on it to produce the desired output - but this is not available within the function GetPDFinfo...

After tinkering around with various Command Line Programs I found that the execution environment can not be foreseen - it is visible in the Command window as prompt string...

The problem is solved by using absolute paths in the creation of the batch file (within GetPDFinfo) :

 

  sPath = KLD_Z.GetScriptPath () + "\\";  
  sBat = sPath + "pdfinfo.exe " + sPdf + " > " + sPath + sInfo;

 

This results in a batch file (my test directory is I:\!_Downloads\ExecuteBatFile):

 

REM Generated by function GetPDFinfo
I:\!_Downloads\ExecuteBatFile\pdfinfo.exe E:\_DDDprojects\FM-JsxLib\Docu\FMjsxLib_lib_DOM.pdf > I:\!_Downloads\ExecuteBatFile\pdfinfo.txt

 

... which properly creates the output pdfinfo.txt also into this directory where the function GetPDFinfo can pick it up:

 

Title:          Microsoft PowerPoint - Freu Dich!.ppt
Author:         Klaus
Creator:        PScript5.dll Version 5.2.2
Producer:       Acrobat Distiller 11.0 (Windows)
CreationDate:   Thu Dec 22 22:17:42 2016
ModDate:        Fri Aug  4 09:20:40 2023
Tagged:         no
Form:           none
Pages:          6
Encrypted:      no
Page size:      595.22 x 842 pts (A4) (rotated 90 degrees)
File size:      455972 bytes
Optimized:      no
PDF version:    1.6

 

 

 

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

frameexpert
Community Expert
Community Expert
Aug 8, 2023 12:08 PM UTC

Hi Klaus, Is your primary goal to get the number of pages in the PDF? Do you need other information as well? -Rick

Translate
www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Aug 8, 2023 1:16 PM UTC

Rick, to support the script presented by Yatani at this post with the number of pages (not needing to open it before and check) - I came to this.

Currently it is an esoteric question. But the script GetPDFinfo is now included in the latest version of FMjsxLib.

I just felt the mechanism required to execute a batch file might be of interest.

Translate