[英]Previewing pdf files in MS Access and Foxit Reader webbrowser control fires print event
Long story short, when you use a Web browser control and VBA
to open a pdf file embbeded in a form, the pdf reader fires the print event automatically.
當前設置 Win1064Bit/Office365 版本 16.0.13628.20234 / Foxit Reader
這是一個屏幕截圖來說明會發生什么
這個事件太煩人了,它不是被觸發一次,而是兩次。
用於打開 PDF 文件的代碼
Private Sub Command2_Click()
Me.WebBrowser0.Navigate2 "C:\Temp\Sample.pdf"
End Sub
如果要嵌入文件,則需要使用 HTML。 否則,除非特定插件允許,否則您將擁有默認的“導航下載”行為。
我使用以下代碼創建一個簡單的 web 頁面,該頁面顯示 pdf:
Dim wb As Object
Set wb = WebBrowser0.Object
Dim fileLocation As String
fileLocation = "C:\Temp\Sample.pdf"
wb.Silent = True
With wb
.Navigate2 "about:blank"
Do Until .ReadyState = 4 '=READYSTATE_COMPLETE
'This is a somewhat inefficient way to wait, but loading a blank page should only take a couple of milliseconds
DoEvents
Loop
.Document.Open
.Document.Write "<!DOCTYPE html><HTML><HEAD><TITLE>My title</TITLE></HEAD><BODY scroll=""auto"" style=""margin: 0px; padding: 0px;"">" & _
"<embed src=""" & fileLocation & """ width=""100%"" height=""100%"" />" & _
"</BODY></HTML>"
.Document.Close
End With
這適用於 Adobe Reader、Foxit 或幾乎任何支持在 Internet Explorer 中查看 PDF 的 PDF 查看器。
不要 go 調整 PDF 查看器設置以與您的應用程序一起使用。 相反,創建一個適用於所有 PDF 查看器的應用程序,以避免在用戶實際使用該 PDF 查看器並希望設置不同或想要不同的 ZBCD1B68617759B1DFCFF0403A6BA8 查看器時出現麻煩。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.