Skip to content
Guides

Document Information

This example shows how to get document information:

swift
let url = URL(fileURLWithPath: "File Path")
let document = CPDFDocument(url: url)

if let documentAttributes = document?.documentAttributes() {
    let title = documentAttributes[.titleAttribute] as? String // Document title.
    let author = documentAttributes[.authorAttribute] as? String // Document author.
    let subject = documentAttributes[.subjectAttribute] as? String // Document subject
    let creator = documentAttributes[.creatorAttribute] as? String // Application name that created the document
    let keywords = documentAttributes[.keywordsAttribute] as? String // Document keywords.
    let creationDate = documentAttributes[.creationDateAttribute] as? String // Document creation date
    let modificationDate = documentAttributes[.modificationDateAttribute] as? String // Document last modified date
}
objective-c
NSURL *url = [NSURL fileURLWithPath:@"File Path"];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
NSDictionary *documentAttributes = [document documentAttributes];
NSString *title = documentAttributes[CPDFDocumentTitleAttribute];          // Document title.
NSString *author = documentAttributes[CPDFDocumentAuthorAttribute];        // Document author.
NSString *subject = documentAttributes[CPDFDocumentSubjectAttribute];      // Document subject
NSString *creator = documentAttributes[CPDFDocumentCreatorAttribute];     // Application name that created the document
NSString *keywords = documentAttributes[CPDFDocumentKeywordsAttribute];    // Document keywords.
NSString *creationDate = documentAttributes[CPDFDocumentCreationDateAttribute];	// Document creation date
NSString *modificationDate = documentAttributes[CPDFDocumentModificationDateAttribute];   // Document last modified date