Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $file = "path\to\your\file.pdf"
- $content = [System.IO.File]::ReadAllBytes($file)
- # Convert EOF marker and file content to strings for index search
- $eofMarker = [System.Text.Encoding]::ASCII.GetBytes("%%EOF")
- $eofString = [System.Text.Encoding]::ASCII.GetString($eofMarker)
- $fileContent = [System.Text.Encoding]::ASCII.GetString($content)
- # Find last occurrence of %%EOF
- $lastIndex = $fileContent.LastIndexOf($eofString)
- if ($lastIndex -ge 0) {
- $newContent = $fileContent.Substring(0, $lastIndex + $eofString.Length)
- [System.IO.File]::WriteAllText($file + ".repaired.pdf", $newContent)
- Write-Output "File repaired and saved as $($file).repaired.pdf"
- } else {
- Write-Output "%%EOF not found. File might not need repair."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement