系統追加新功能,需要open pdf
前言
事源︰一個 win form based 的系統需要顯示pdf,即是read的功能
使用者能上載pdf,也需要看見pdf的內容
今次是探討如果c# win form 如何 read pdf (在免費的前提下)
之前也有類似的RAD,不過是生成pdf,今次就是read (打開檔案看見內容)
簡介
最後發現有兩種不錯的方法
- Adobe AxAcroPDFLib
- Microsoft webview2
AxAcroPDFLib.AxAcroPDF
https://community.adobe.com/t5/acrobat-sdk-discussions/add-reference-to-axacropdflib/td-p/8833362
https://stackoverflow.com/questions/41755295/axacropdflib-reference
製作方法如下圖
webview2
它是 Edge 內的一個component 全名 Microsoft Edge WebView2
經過海豚的測試,
the program will work if only install Edge
the program will work if only install WebView2 runtime (64bit)
Both of edge, WebView2 runtime could be installed on the same computer
所以只要安裝 Edge / WebView2 runtime (64bit) 便可,但其後發現個別電腦無法執行
估是到了某一個版本的Edge ,已包含 WebView2,所以不用安裝
一些舊版本的Edge沒有webView2,所以運行失敗
不論你的Edge有沒有,也可以安裝WebView2,兩者可同時並存
所以最後不論什麼電腦,都同時安裝 Edge 和 WebView2
海豚好像搞到 engineer 十分頭大,他要找方法如何 Deploy 到300部電腦,而且在9個不同office
因為他沒有 SCCM (System Center Configuration Manager)
還有一項, WebView2 對5MB大小的 file就開不到,source code 禁止了這件事,說 initialize components 會超吃資源。
但是又留了一道留門,給你overwrite可以自行繞過和處理。
https://github.com/MicrosoftEdge/WebView2Feedback/issues/1355
不用擔心豚已經 handle了
大家去 下載 用便可
剛下載記得按
Restore Nuget Packages ,先抓一下 library
Rebuild Solution
如果出錯,最好 Edge 及 WebView2 runtime 兩個都安裝再試
後記
如果海豚沒記錯,Adobe Acrobat Browser Control Type Library 是引用 Adobe Acrobat Reader 的Library ,即時運行的電腦必須安裝 Adobe Acrobat Reader
所以最好選了 webView2,雖然 webView2 也是要預先安裝
不過最新的電腦本來自帶Edge,而且Edge 和 WebView2 runtime 好像能透過 Windows Server Update Services (WSUS) 或 Microsoft System Center Configuration Manager (SCCM) Deploy
而且也有MSI 安裝檔,實在沒有辦法下,也能寫.ps1 安裝吧。
海豚的Enginer測試後,總之WebView2 比較易安裝和更新數百部電腦
所以最後就選了 WebView2










No comments:
Post a Comment