<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/DocumentAttributeKey",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@T@NSAttributedStringDocumentAttributeKey"
  },
  "title" : "NSAttributedString.DocumentAttributeKey"
}
-->

# NSAttributedString.DocumentAttributeKey

The attributes you apply to an entire document.

```
struct DocumentAttributeKey
```

## Overview

The [`NSAttributedString.DocumentAttributeKey`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey) type defines attributes that apply to an entire attributed string, and not to specific ranges of characters. You specify these attributes when writing an attributed string to disk, or reading text from a file on disk. Use these attributes to specify metadata about the overall document, including its author or title, page margin details, font-scaling options for cross-platform interchange, and more.

## Topics

### Getting document type keys

[`documentType`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/documentType)

The document type.

[`fileType`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/fileType)

The document type for interpreting the document.

[`textEncodingName`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/textEncodingName)

The name of the text encoding to use.

### Getting document metadata keys

[`author`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/author)

The author of the document.

[`category`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/category)

The document’s category.

[`characterEncoding`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/characterEncoding)

The string encoding for the document.

[`cocoaVersionDocumentAttribute`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/cocoaVersionDocumentAttribute)

The version of Cocoa that created the file.

[`comment`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/comment)

The document comments.

[`company`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/company)

The company or organization name associated with the document.

[`converted`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/converted)

A value that indicates whether a filter service converted the file.

[`copyright`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/copyright)

The document’s copyright information.

[`creationTime`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/creationTime)

The creation date of the document.

[`editor`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/editor)

The name of person who last edited the document.

[`keywords`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/keywords)

The document keywords.

[`manager`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/manager)

The name of the author’s manager.

[`modificationTime`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/modificationTime)

The modification date of the document.

[`readOnly`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/readOnly)

An indication of whether the document is read-only.

[`subject`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/subject)

The subject of the document.

[`title`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/title)

The document title.

### Getting document appearance keys

[`appearance`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/appearance)

The appearance of the document.

[`backgroundColor`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/backgroundColor)

The background color of the document.

[`bottomMargin`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/bottomMargin)

The bottom margin of the document.

[`defaultFontExcluded`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/defaultFontExcluded)

[`defaultTabInterval`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/defaultTabInterval)

The default tab stop interval for the document.

[`excludedElements`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/excludedElements)

The HTML elements to exclude in generated HTML.

[`hyphenationFactor`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/hyphenationFactor)

The hyphenation factor of the document.

[`leftMargin`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/leftMargin)

The left margin of the document.

[`paperMargin`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/paperMargin)

The paper margin of the document.

[`paperSize`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/paperSize)

The paper size for the document.

[`prefixSpaces`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/prefixSpaces)

The number of spaces for indenting nested HTML elements.

[`rightMargin`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/rightMargin)

The right margin of the document.

[`textLayoutSections`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/textLayoutSections)

The layout orientations for each section.

[`topMargin`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/topMargin)

The top margin of the document.

[`viewMode`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/viewMode)

The view mode.

[`viewSize`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/viewSize)

The view size.

[`viewZoom`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/viewZoom)

The view zoom.

### Getting the font-scaling options

[`sourceTextScaling`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/sourceTextScaling)

The text-scaling mode you used when creating the text.

[`textScaling`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/textScaling)

The text-scaling mode to use when displaying the text.

### Getting the default attributes

[`defaultAttributes`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/defaultAttributes)

The default document attributes.

### Initializers

[`init(_:)`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/init(_:))

Creates a document attribute key.

[`init(rawValue:)`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/init(rawValue:))

Creates a document attribute key with the specified raw value.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`RawRepresentable`](/documentation/Swift/RawRepresentable)

[`Hashable`](/documentation/Swift/Hashable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)