I have one folder with multiple pdf files named like xxx_xxx_01.05.2017.pdf
.
Each day I have one more file and I start this script to merge them and save D:\123\DB052017.pdf
.
The goal is to auto create a new file after merging all the files of the month.
The next files are for the new month like xxx_xxx_01.06.2017.pdf
and I want to create a new file with name DB062017.pdf
and so on...
Can you give me a clue?
Add-Type -Path C:\assemblies\PdfSharp.dll
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)) {
$input = New-Object PdfSharp.Pdf.PdfDocument
$input = $PdfReader::Open($i.fullname, $PdfDocumentOpenMode::Import)
$input.Pages | %{$output.AddPage($_)}
}
$output.Save($filename)
}
Merge-PDF -path c:\fso -filename D:\123\DB052017.pdf
This is what i done for the end file:
Add-Type -Path C:\assemblies\PdfSharp.dll
$MonthName = (Get-Date).Month
$YearName = (Get-Date).Year
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)) {
$input = New-Object PdfSharp.Pdf.PdfDocument
$input = $PdfReader::Open($i.fullname, $PdfDocumentOpenMode::Import)
$input.Pages | %{$output.AddPage($_)}
}
$output.Save($filename)
}
Merge-PDF -path c:\fso -filename D:\Users\h.yordanov\Desktop\WEBDams\Data\CHQ\HQ\DB$MonthName""$YearName.pdf
Now i need to fetch or move the files that are in folder with different month.