簡體   English   中英

在 MS Access 和 Foxit Reader webbrowser 控件中預覽 pdf 文件會觸發打印事件

[英]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 查看器時出現麻煩。

像這樣更改 Foxit Reader 首選項

  • 打開福昕閱讀器

  • Go 到文件 | 偏好 | 文件

  • 取消選中“在 web 瀏覽器中,默認在讀取模式下顯示 PDF”


在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM