Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Add-OfficePdfAttachment

Aliases: PdfAttachment
Module
PSWriteOffice
Aliases
PdfAttachment
Inputs
OfficeIMO.Pdf.PdfDocument
Outputs
OfficeIMO.Pdf.PdfDocument

Adds an embedded file attachment to a generated PDF document.

Syntax

Add-OfficePdfAttachment
[-Description <String>]
[-MimeType <String>]
[-Name <String>]
[-PassThru]
[-Path] <String>
[-Relationship <PdfAssociatedFileRelationship>]
[<CommonParameters>]
#
Parameter set: Context
Add-OfficePdfAttachment
[-Description <String>]
-Document <PdfDocument>
[-MimeType <String>]
[-Name <String>]
[-PassThru]
[-Path] <String>
[-Relationship <PdfAssociatedFileRelationship>]
[<CommonParameters>]
#
Parameter set: Document

Examples

Embed source data in a generated PDF.

$dataPath = '.\Examples\Documents\ServiceData.json'
Set-Content -Path $dataPath -Value '{ "service": "Directory", "status": "Healthy" }'
New-OfficePdf -Path .\Examples\Documents\PdfWithAttachment.pdf {
    Add-OfficePdfHeading -Text 'Service report'
    Add-OfficePdfAttachment -Path $dataPath -Name 'service-data.json' -MimeType 'application/json' -Description 'Source data used by the report.'
}

Embeds a supporting JSON file in the generated PDF.

Parameters

-Description String optional
Optional human-readable attachment description.
-MimeType String optional
Optional MIME type for the embedded file.
-Name String optional
Optional embedded file name. The source file name is used when omitted.
-PassThru SwitchParameter optional
Accepted for compatibility. The replacement document is always emitted when -Document is used.
-Path String requiredposition: 0aliases: FilePath
File path to embed in the generated PDF.
-Relationship PdfAssociatedFileRelationship optional
Associated-file relationship between the PDF and the embedded file.
Possible values: Unspecified, Source, Data, Alternative, Supplement, C2paManifest
-Document PdfDocument requiredpipeline: True (ByValue)sets: Document
PDF document to update outside the DSL context.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.