|
用VB如何对PDF文件里的某些特殊字符串进行置换处理 - 我爱学习网 (5axxw.com)
用VB如何对PDF文件里的某些特殊字符串进行置换处理 - 我爱学习网 (5axxw.com)
Sub test()
'引用Adobe Acrobat对象模型
Dim AcroApp As Acrobat.CAcroApp
Dim AcroAVDoc As Acrobat.CAcroAVDoc
Dim AcroPDDoc As Acrobat.CAcroPDDoc
Dim AcroHiliteList As Acrobat.CAcroHiliteList
Dim AcroTextSelect As Acrobat.CAcroPDTextSelect
'创建Acrobat App
Set AcroApp = CreateObject("AcroExch.App")
AcroApp.Show
'打开PDF文件
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open("D:\Test.pdf", "") Then
Set AcroPDDoc = AcroAVDoc.GetPDDoc
'查找并替换字符串
Set AcroHiliteList = CreateObject("AcroExch.HiliteList")
Set AcroTextSelect = CreateObject("AcroExch.PDTextSelect")
AcroTextSelect.SelectAll
AcroTextSelect.FindText "hello", False, False
AcroHiliteList.Add 0, AcroTextSelect
Do While Not AcroHiliteList Is Nothing And AcroHiliteList.GetNumText = 1
AcroTextSelect.Start = AcroHiliteList.GetFirstSelected
AcroTextSelect.End = AcroHiliteList.GetLastSelected
AcroTextSelect.Replace "world"
AcroHiliteList.RemoveAll
AcroTextSelect.SelectAll
AcroTextSelect.FindText "hello", False, False
AcroHiliteList.Add 0, AcroTextSelect
Loop
'保存并关闭文件
AcroPDDoc.Save PDSaveFull, "D:\Test_New.pdf"
AcroAVDoc.Close True
End If
'释放资源
Set AcroHiliteList = Nothing
Set AcroTextSelect = Nothing
Set AcroPDDoc = Nothing
Set AcroAVDoc = Nothing
AcroApp.Exit
Set AcroApp = Nothing
End Sub
|
|