Advertisement
foadsf

Untitled

Mar 7th, 2024
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $file = "path\to\your\file.pdf"
  2. $content = [System.IO.File]::ReadAllBytes($file)
  3.  
  4. # Convert EOF marker and file content to strings for index search
  5. $eofMarker = [System.Text.Encoding]::ASCII.GetBytes("%%EOF")
  6. $eofString = [System.Text.Encoding]::ASCII.GetString($eofMarker)
  7. $fileContent = [System.Text.Encoding]::ASCII.GetString($content)
  8.  
  9. # Find last occurrence of %%EOF
  10. $lastIndex = $fileContent.LastIndexOf($eofString)
  11.  
  12. if ($lastIndex -ge 0) {
  13.     $newContent = $fileContent.Substring(0, $lastIndex + $eofString.Length)
  14.     [System.IO.File]::WriteAllText($file + ".repaired.pdf", $newContent)
  15.     Write-Output "File repaired and saved as $($file).repaired.pdf"
  16. } else {
  17.     Write-Output "%%EOF not found. File might not need repair."
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement