Thomas Hoevel wrote:
The name is PDFsharp because it was developed with C#. I am not a PowerShell guru.
In C# I can use "Reverse()" if I want to stick to foreach:
Code:
var reversedList = pdfRenderer.PdfDocument.Pages.PagesArray.Reverse();
foreach (var page in reversedList)
{
// ...
}
I don't know how that translates to PowerShell. OTOH PowerShell may have other options I am completely unaware of.
I just figured out. In Powershell you can use the Sort-Object Aliases - "sort". Like this:
Code:
gci $path *.pdf -Recurse|sort -Descending
Thank you for finding time to help.
Final code:
Code:
Add-Type -Path C:\assemblies\PdfSharp.dll
$MYName = Get-Date -format "MMMM yyyy"
Function Merge-PDF {
Param($path, $filename)
$output = New-Object PdfSharp.Pdf.PdfDocument
$PdfReader = [PdfSharp.Pdf.IO.PdfReader]
$PdfDocumentOpenMode = [PdfSharp.Pdf.IO.PdfDocumentOpenMode]
foreach($i in (gci $path *.pdf -Recurse|sort -Descending)) {
$input = New-Object PdfSharp.Pdf.PdfDocument
$input = $PdfReader::Open($i.fullname, $PdfDocumentOpenMode::Import)
for ($index = 0; $index -lt $input.PageCount; $index++) {
$page = $input.Pages[$index]
$null = $output.AddPage($page)
}
}
$output.Save($filename)
}
Merge-PDF -path c:\fso -filename C:\WEB\Apache24\htdocs\WEBDams\Data\CHQ\HQ\1\$MYName.pdf
Write-Host "Файлът е създаден и качен на сайта!"
Start-Sleep -s 4