【发布时间】:2021-07-21 20:11:11
【问题描述】:
寻找一些指针/提示来提高下面的速度和/或功效。对其他方法开放,但只涉足 powershell、cmd 和 python。
还应归功于信用:这是对以下内容的黑客工作:https://stackoverflow.com/a/44183234/12834479
我不是在本地工作,而是通过 VPN 以极低的连接速度进行网络共享。 粗略地说,它的工作时间为 8 秒/PDF。
我试图解决的问题,目标是确保每个 PDF 都可以被 Adobe 阅读。保存为 PDF(但不是 pdf)的图像将在某些 PDF 软件中打开,但 Adobe 讨厌它们。我有转换的方法,但我的速率限制器正在识别它们。
- Adobe PDF - 以 %PDF 开头
- 一些银行 PDF - 以“空格”开头,然后是 %PDF
- 第三方软件 - 垃圾标题,但 %PDF 在文档中
$items = Get-ChildItem | Where-Object {$_.Extension -eq ".pdf"}
$arrary = @()
$logFile = "RESULTS_$(get-date -Format yyyymmdd).log"
$badCounter = 0
$goodCounter = 0
$msg = "`n`nProcessing " + $items.count + " files... "
Write-Host -nonewline -foregroundcolor Yellow $msg
foreach ($item in $items)
{
trap { Write-Output "Error trapped: $_"; continue; }
try {
$pdfText = Get-Content $item -raw
$ptr3 = '%PDF'
if ('%PDF' -ne $pdfText.SubString(([System.Math]::Max(0,$pdfText.IndexOf($ptr3))),4)) { $arrary+= "$item |-failed" >>$logfile;$badCounter += 1; $badCounter} else { $goodCounter += 1; $goodCounter}
continue;}
catch [System.Exception]{write-output "$item $_";}}
$totalCounter = $badCounter + $goodCounter
Write-Output $arrary >> $logFile
1..3 | %{ Write-Output "" >> $logFile }
Write-Output "Total: $totalCounter / BAD: $badCounter / GOOD: $goodCounter" >> $logFile
Write-Output "DONE!`n`n"
如果目前在 PS 版本 7.1.3 上运行有任何差异/但在本地也有 5.1.18。
【问题讨论】:
-
请说您是在网络共享所在的远程计算机上执行此操作,或者至少是在它附近的服务器上执行此操作。
-
@TheMadTechnician 对我来说听起来不像“而不是在本地工作”,但是这里的魔杖是在带有 PDF 或至少相同物理网络的服务器上运行。
标签: powershell pdf .net-core adobe