检查 PDF 是否是 Word VBA 中的 image/OCR'
Checking if PDF is an image/OCR'd in Word VBA
我在 Word 中使用 VBA 打开一堆 PDF 文件(一个接一个),并查找一些文本。我 运行 处理的一些文件实际上是 images/not OCR 的。我只想跳过它们,但我不确定要为此做什么样的检查。在这些文件上,它仍然“找到”字符串,并到达我不希望它处理的代码部分。
Dim pdfDoc As Word.Document
Dim ratingString As String
Set pdfDoc = Documents.Open(FileName:=FSOFile.Path, ConfirmConversions:=False, Format:=wdOpenFormatAuto)
Set ratingString = pdfDoc.Range
ratingString.Find.Execute FindText:="Evaluation Rating", MatchCase:=True
If ratingString.Find.Found = True Then
'Somehow it gets to here when the pdf is an image
End If
有人可以建议如何防止图像 'passing' 我的支票吗?谢谢!
经过 OCR 处理的 PDF 通常还包含原始内容的图像及其背后经过 OCR 处理的再现。而且,根据 OCR 软件和输入图像的质量,您需要的文本可能已正确呈现,也可能未正确呈现。
尝试以下方法:
Dim pdfDoc As Word.Document
Set pdfDoc = Documents.Open(FileName:=FSOFile.Path, ConfirmConversions:=False, Format:=wdOpenFormatAuto)
With pdfDoc
With .Range
.Find.Execute FindText:="Evaluation Rating", MatchCase:=True
If .Find.Found = True Then
' Process the found content, e.g.:
MsgBox .Paragraphs(1).Range.Text
End If
End With
.Close False
End With
我在 Word 中使用 VBA 打开一堆 PDF 文件(一个接一个),并查找一些文本。我 运行 处理的一些文件实际上是 images/not OCR 的。我只想跳过它们,但我不确定要为此做什么样的检查。在这些文件上,它仍然“找到”字符串,并到达我不希望它处理的代码部分。
Dim pdfDoc As Word.Document
Dim ratingString As String
Set pdfDoc = Documents.Open(FileName:=FSOFile.Path, ConfirmConversions:=False, Format:=wdOpenFormatAuto)
Set ratingString = pdfDoc.Range
ratingString.Find.Execute FindText:="Evaluation Rating", MatchCase:=True
If ratingString.Find.Found = True Then
'Somehow it gets to here when the pdf is an image
End If
有人可以建议如何防止图像 'passing' 我的支票吗?谢谢!
经过 OCR 处理的 PDF 通常还包含原始内容的图像及其背后经过 OCR 处理的再现。而且,根据 OCR 软件和输入图像的质量,您需要的文本可能已正确呈现,也可能未正确呈现。
尝试以下方法:
Dim pdfDoc As Word.Document
Set pdfDoc = Documents.Open(FileName:=FSOFile.Path, ConfirmConversions:=False, Format:=wdOpenFormatAuto)
With pdfDoc
With .Range
.Find.Execute FindText:="Evaluation Rating", MatchCase:=True
If .Find.Found = True Then
' Process the found content, e.g.:
MsgBox .Paragraphs(1).Range.Text
End If
End With
.Close False
End With