Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
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.
---o0O0o---
Our .NET Developer Tools | |
---|---|
Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
Our Delphi/C++Builder developer tools | |
---|---|
Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
Our Java developer tools | |
---|---|
Gnostice Document Studio JavaMulti-format document-processing component suite for Java developers. |
PDFOne (for Java)A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications. |
Our Platform-Agnostic Cloud and On-Premises APIs | |
---|---|
StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved. |