使用 VBA 写入并保存为 PDF
我已经能够成功写入 PDF,但现在我正在尝试保存它。我知道我需要使用 pddoc 才能保存,但我无法将其设置为与我用来写入 pdf 的 avdoc 相匹配。真正的代码有很多字段,所以我将其减少到一个字段并将其放在下面:
Sub mysub()
'basic declarations and initializations
Dim myfullpath As String
Dim myField As String
myfullpath = "C:\mypdf.pdf"
myField = "Hello"
'pdf overhead declarations and initializations
Dim aApp As Acrobat.AcroApp
Dim av_doc As Acrobat.AcroAVDoc
Dim pdf_form As AFORMAUTLib.AFormApp
Set aApp = CreateObject("AcroExch.App")
Set av_doc = CreateObject("AcroExch.AVDoc")
Set pdf_form = CreateObject("AFORMAUT.App")
If av_doc.Open(myfullpath, "") = True Then
'declare and initialize pdf fields
Dim pdfField As AFORMAUTLib.Field
Set pdfField = pdf_form.Fields("pdfField")
'set value in pdf
pdfField = myField
'declare and initialize pddoc in order to save
Dim PdfDoc As Acrobat.CAcroPDDoc
Set PdfDoc = av_doc 'having trouble here
'“Run-time error ‘13’: Type mismatch”
PdfDoc.Save PDSaveFull, myfullpath
av_doc.Close False
Set pdfField = Nothing
End If
aApp.Exit
Set aApp = Nothing
Set av_doc = Nothing
Set PdfDoc = Nothing
End Sub
I have been able to successfully write to a pdf, but now I am trying to save it. I know I need to use a pddoc in order to save, but I can't set it to match the avdoc that I use to write to the pdf. The real code has a lot of fields so I will just reduce that to one field and put what I have below:
Sub mysub()
'basic declarations and initializations
Dim myfullpath As String
Dim myField As String
myfullpath = "C:\mypdf.pdf"
myField = "Hello"
'pdf overhead declarations and initializations
Dim aApp As Acrobat.AcroApp
Dim av_doc As Acrobat.AcroAVDoc
Dim pdf_form As AFORMAUTLib.AFormApp
Set aApp = CreateObject("AcroExch.App")
Set av_doc = CreateObject("AcroExch.AVDoc")
Set pdf_form = CreateObject("AFORMAUT.App")
If av_doc.Open(myfullpath, "") = True Then
'declare and initialize pdf fields
Dim pdfField As AFORMAUTLib.Field
Set pdfField = pdf_form.Fields("pdfField")
'set value in pdf
pdfField = myField
'declare and initialize pddoc in order to save
Dim PdfDoc As Acrobat.CAcroPDDoc
Set PdfDoc = av_doc 'having trouble here
'“Run-time error ‘13’: Type mismatch”
PdfDoc.Save PDSaveFull, myfullpath
av_doc.Close False
Set pdfField = Nothing
End If
aApp.Exit
Set aApp = Nothing
Set av_doc = Nothing
Set PdfDoc = Nothing
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用:
This worked for me: