Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||||||
Document information properties are a very useful subset of a document's metadata. PDF metadata can be useful applications such as file indexing services, search engine spiders, and PDF viewers and printers. Document properties can also be valuable for human users.
In this article, you will to read and write document information properties such as title, author, subject, and keywords.
The TgtPDFDocument.DocInfo property exposes the document information properties of a loaded PDF document. This property is represented by an instance of TgtPDFInfo class. The properties of the TgtPDFInfo instance represents various document information properties of a document.
Here is some example code for reading document information properties.
{ This code example illustrates how to extract PDF document information properties. } program Examples_GetDocInfo; {$APPTYPE CONSOLE} uses SysUtils, gtPDFDoc; var gtPDFDocument1: TgtPDFDocument; begin // Create a document object gtPDFDocument1 := TgtPDFDocument.Create(Nil); try // Load input document gtPDFDocument1.LoadFromFile('input_doc.pdf'); // Check if document has loaded successfully if gtPDFDocument1.IsLoaded then begin // Display document information properties Writeln('Title: ' + gtPDFDocument1.DocInfo.Title); Writeln('Author: ' + gtPDFDocument1.DocInfo.Author); Writeln('Subject ' + gtPDFDocument1.DocInfo.Subject); Writeln('Keywords: ' + gtPDFDocument1.DocInfo.Keywords); Writeln('Creator: ' + gtPDFDocument1.DocInfo.Creator); Writeln('Producer: ' + gtPDFDocument1.DocInfo.Producer); Writeln('Created On: ' + gtPDFDocument1.DocInfo.CreationDate); Writeln('Modified On: ' + gtPDFDocument1.DocInfo.ModDate); end else begin // Output error message Writeln('Sorry, I could not load input_doc.pdf.'); end; except on Err:Exception do begin Writeln('Sorry, an exception was raised. '); Writeln(Err.Classname + ':' + Err.Message); end; end; // Free resources gtPDFDocument1.Reset; // Destroy PDF document object FreeAndNil(gtPDFDocument1); Writeln('Press Enter to exit.'); Readln; end.
Just as you can read the properties, you can also set their values, as shown below.
{ This code example illustrates how to specify PDF document information properties. } program Examples_SetDocInfo; {$APPTYPE CONSOLE} uses SysUtils, gtPDFDoc; var gtPDFDocument1: TgtPDFDocument; begin // Create a document object gtPDFDocument1 := TgtPDFDocument.Create(Nil); try // Load input document gtPDFDocument1.LoadFromFile('input_doc.pdf'); // Check if document has loaded successfully if gtPDFDocument1.IsLoaded then begin // Set new document information properties gtPDFDocument1.DocInfo.Title := 'To Be Or Not To Be'; gtPDFDocument1.DocInfo.Author := 'V. Subhash'; gtPDFDocument1.DocInfo.Subject := 'Hamlet''s Immortal Dilemma'; gtPDFDocument1.DocInfo.Keywords := 'hamlet, shakespeare, dilemma, english, drama, play'; gtPDFDocument1.DocInfo.Creator := 'Gnostice PDFtoolkit Newsletter Article Demo'; // Save the modified document to a file gtPDFDocument1.SaveToFile('output_doc.pdf'); Writeln('Output document written sucessfully.'); end else begin // Output error message Writeln('Sorry, I could not load input_doc.pdf.'); end; except on Err:Exception do begin Writeln('Sorry, an exception was raised. '); Writeln(Err.Classname + ':' + Err.Message); end; end; // Free resources gtPDFDocument1.Reset; // Destroy PDF document object FreeAndNil(gtPDFDocument1); Writeln('Press Enter to exit.'); Readln; end.
Please note that the Producer property is read-only. It will always be set to the Gnostice PDF processor used by PDFtoolkit.
| Privacy | Legal | Feedback | Newsletter | © 2002-2010 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.