<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/pdf417BarcodeGenerator()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)PDF417BarcodeGenerator"
  },
  "title" : "pdf417BarcodeGenerator()"
}
-->

# pdf417BarcodeGenerator()

Generates a high-density linear barcode.

```
class func pdf417BarcodeGenerator() -> any CIFilter & CIPDF417BarcodeGenerator
```

## Return Value

The generated image.

## Discussion

This method generates a PDF417 barcode as an image. PDF417 is a high-density stacked linear barcode format defined in the ISO 15438 standard. Use this filter to generate alphanumeric or numeric-only barcodes. Commonly used on identification cards or inventory management because of the large amount of data the barcode can hold.

The PDF417 barcode generator filter uses the following properties:

- `message`: An <doc://com.apple.documentation/documentation/Foundation/NSData> object representing the data to be encoded as a barcode.
- `minWidth`: A `float` representing the minimum width of the barcode’s data area, in pixels as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `maxWidth`: A `float` representing the maximum width of the barcode’s data area, in pixels, as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `maxHeight`: A `float` representing the maximum height of the barcode’s data area, in pixels, as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `minHeight`: A `float` representing the minimum height of the barcode’s data area, in pixels, as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `dataColums`: A `float` representing the number of columns in the data area as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `rows`: A `float` representing the number of rows in the data area as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `preferredAspectRatio`: A `float` representing the desired aspect ratio as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `compactionMode`: An option that determines which method the generator uses to compress data as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>. See the note below for the possible values.
- `compactStyle`: A `Boolean` value of `0` or `1` that determines the omission of redundant elements to make the generated barcode more compact as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>.
- `correctionLevel`: A `float` between 0 and 8 that determines the amount of redundancy to include in the barcode’s data to prevent errors when the barcode is read. If left unspecified, the generator chooses a correction level based on the size of the message data.
- `alwaysSpecifyCompaction`: A `Boolean` value of `0` or `1` that determines the inclusion of information about the compaction mode in the barcode as an <doc://com.apple.documentation/documentation/Foundation/NSNumber>. If a PDF417 barcode doesn’t contain compaction mode information, the reader assumes text-based compaction.

The `compactionMode` property takes one of the following numeric values:

|Value|Name     |Description                                                                                                                                   |
|-----|---------|----------------------------------------------------------------------------------------------------------------------------------------------|
|`1`  |Automatic|The generator automatically chooses a compression method. This option is the default.                                                         |
|`2`  |Numeric  |Valid only when the message is an ASCII-encoded string of digits, achieving optimal compression for that type of data.                        |
|`3`  |Text     |Valid only when the message is all ASCII-encoded alphanumeric and punctuation characters, achieving optimal compression for that type of data.|
|`4`  |Byte     |Valid for any data, but least compact.                                                                                                        |

Select either 1 or the appropriate valid value for your data that gives the most compact output.

The following code creates a filter that generates a PDF417 barcode:

```swift
func pdf417Barcode(inputMessage: String) -> CIImage {
    let pdf417BarcodeGenerator = CIFilter.pdf417BarcodeGenerator()
    pdf417BarcodeGenerator.message = inputMessage.data(using: .ascii)!
    pdf417BarcodeGenerator.minWidth = 56
    pdf417BarcodeGenerator.maxWidth = 58
    pdf417BarcodeGenerator.maxHeight = 283
    pdf417BarcodeGenerator.minHeight = 13
    pdf417BarcodeGenerator.dataColumns = 9
    pdf417BarcodeGenerator.rows = 6
    pdf417BarcodeGenerator.preferredAspectRatio = 0.0
    pdf417BarcodeGenerator.compactionMode = 1
    pdf417BarcodeGenerator.compactStyle = 1
    pdf417BarcodeGenerator.correctionLevel = 0.01
    pdf417BarcodeGenerator.alwaysSpecifyCompaction = 0
    return pdf417BarcodeGenerator.outputImage!
}
```

![An image of a black and white PDF417 barcode made of vertical lines of various widths and squares representing the encoded data of 47212826.](images/com.apple.coreimage/media-3546316@2x.png)

---

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)