Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Set-OfficePdfHeader

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

Sets a simple or fully composed running PDF header.

Syntax

Set-OfficePdfHeader [-Align <Left|Center|Right|Justify>] [-Compose <ScriptBlock>] [-FontSize <Double>] [-PassThru] [[-Text] <String>] [<CommonParameters>]
#
Parameter set: Context
Set-OfficePdfHeader [-Align <Left|Center|Right|Justify>] [-Compose <ScriptBlock>] -Document <PdfDocument> [-FontSize <Double>] [-PassThru] [[-Text] <String>] [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Add a running report header.

New-OfficePdf -Path .\Examples\Documents\PdfHeader.pdf {
    Set-OfficePdfHeader -Text 'Service Review' -Align Right -FontSize 9
    Add-OfficePdfHeading -Text 'Service Review'
    Add-OfficePdfParagraph -Text 'The header repeats on generated pages.'
}

Sets header text for the generated PDF.

Compose styled default, first-page, and even-page headers.

New-OfficePdf -Path .\Examples\Documents\RichHeader.pdf {
    Set-OfficePdfHeader -Compose {
        param($header)
        $label = New-OfficeTextRun -Text 'Service report ' -Bold | ConvertTo-OfficePdfTextRun
        $pageStyle = New-OfficeTextRun -Italic | ConvertTo-OfficePdfTextRun
        $null = $header.Text({
            param($text)
            $null = $text.Run($label).CurrentPage($pageStyle)
        })
        $null = $header.FirstPageText('Service report cover')
        $null = $header.EvenPagesZones('Service report', $null, 'Page {page}/{pages}')
    }
    Add-OfficePdfParagraph -Text 'Generated report body.'
}

The native composer owns rich runs, page tokens, zones, images, shapes, and page variants.

Parameters

-Align PdfAlign optional
Header alignment.
Possible values: Left, Center, Right, Justify
-Compose ScriptBlock optional
Advanced header composer. The script receives a PdfHeaderBuilder and can configure default, first-page, and even-page text, zones, images, shapes, rich text, and page tokens.
-FontSize Double optional
Header font size in PDF points.
-PassThru SwitchParameter optional
Emit the updated document.
-Text String optionalposition: 0
Header text. Supports {page} and {pages}.
-Document PdfDocument requiredpipeline: True (ByValue)sets: Document
Compatibility parameter. Page composition is supported only inside New-OfficePdf.

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.