Solved

Read File Title (from the Properties) - In Windows

Posted on 2003-11-11
6
4,362 Views
Last Modified: 2012-05-04
How can I read the Title and the other properties (all the properties under the Summary tab of the file properties)  of a PDF file? All this is running in Windows 2000.
0
Comment
Question by:Éric Moreau
  • 4
6 Comments
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9723232
Can't be done in java, I'm afraid.  it's a purely platform-dependent trick of Windows, and as a result, Sun has no interest in supporting it, as it wouldn't be platform independent.

Why do you need it?  Is it already in the file and you need to only read it, or were you planning on setting it yourself?
0
 
LVL 69

Author Comment

by:Éric Moreau
ID: 9723930
We need a dynamic of retrieving these info from the files properties to display somewhere. The lowest maintenance would have been to use these properties.
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9723963
Well, in that case it can't be done, at least in java directly.  The only possible option is going to be to try to hack it by using a windows command line, and calling it from the java.  I'm looking around through the windows documentation to see if this is possible, and I'll get back on this if I find anything.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9724527
Alright.  Good news and bad news:

Bad news:  The only 'officially' sanctioned way to access the Summary Information properties of a file is to use the C++ functions exposed by the windows API.  Also, these properties are only available in NTFS file systems.  If you have anything in FAT32 you're going to lose those properties when they get copied over to them.

Good news:  There are unofficial kludges available.  For example, there's a command line application that can be used to read these properties located at:

http://peccatte.karefil.com/Software/SumInfos/SumInfosEN.htm

You can then just call it from the command line using the command:

Runtime.getRuntime().exec(" etc..." );

Here's the tricky bit, though:  I don't think it's possible to capture the output of the program, so you're going to have to cobble together a .bat file which runs the program, and then dumps the results into a file.  From there you can read the file using java to get the appropriate properties.

This is really not the best way to handle this problem, but it's about as good as it's going to get if you want to stick to java.  Fact is, Sun really has no interest in tackling these sort of issues because they are windows-specific.  They'd rather deal with cross-platform features and performance enhancements, and I agree with that approach.  If you have no interest in any other platform but Windows w/ NTFS, (2000 and XP,) and you want to get into bed with Microsoft over an issue like this, you might need to look into Visual Studio.
0
 
LVL 2

Accepted Solution

by:
SuperKarateMonkey earned 125 total points
ID: 9724953
There's another way to handle grabbing the output of an executable, aside from dumping it into a file within a windows .bat file.  You could get it's output from an InputStream object.  The code would look like this:

try
{
      Process proc = Runtime.getRuntime().exec( "SomeExecutable.exe" );
      BufferedInputStream in = new BufferedInputStream( proc.getInputStream() );
      int i;
      while( ( i = in.read() ) != -1 )
      {
            System.out.print( (char)i );
      }
}
catch( IOException e )
{
      System.err.println( "Error:" + e.getMessage() );
      e.printStackTrace();
      System.exit(1);
}


Now, all this code does is dump the output to the System.out, but you could instead read it into a String to parse it, or any of a dozen different things.  You should beware, however, that the Runtime.createProcess() method creates a native process that runs asynchronously from the application, so you need to programatically buffer that inputstream IMMEDIATELY.  Don't do anything else, lest you lose output.  That's why you create a BufferedInputStream, by the way:  It will create a buffer for the InputStream to dump it's output into, so that you don't need to worry about whether you're catching all the output, or if you miss something.
0
 

Expert Comment

by:softexperience
ID: 9981941
You may also test our MetaDataMiner Catalogue Pro software at www.metadataminer.com

Listing folders and documents summary information, extraction of file properties and metadata, creation of HTML file catalogs including hypertext links and building XML reports.
"Software for extended listings of folders contents in interactive mode and in command line. File cataloging utility that enables quick creation of HTML pages listing files and associated metadata, managing and updating document properties associated with such files as: Microsoft Office, retrieve information from OpenOffice.org, StarOffice, Visio documents, PDF documents , export metadata from photos JPEG, Tiff images (IPTC fields).

Metadata Miner Catalogue PRO also enables Adobe XMP file information (eXtensible Metadata Platform) metadata extraction from documents produced by recent Adobe applications and XSL transformation on metadata extracted listings converting to Dublin Core RDF, CSV, SVG and other custom presentations for common uses or in a Content Management System Architecture

Allows companies to quickly gather summary information from MS Office, Adobe documents and other source documents, and easily move that meta data into XML or post it on shared drives as an HTML documentation catalog index with hypertext links to access files.

Helps in mass update of standard and custom file properties in a folder and sub-folders to easily change a set of documents and include metadata in Word and other Office files. This Professional version lets you call it from command-line to extract metadata for batch processing and optionally run a XSL transformation delivered with the program or your own XSL "
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now