問題描述
我有一個運行票房服務的網站,可以發行門票和報告.我想弄清楚如何將票證(當前為 PDF)直接發送到本地/客戶端 PC 上的指定打印機.
I have a website which runs a box office service which issues tickets and reports. I am trying to figure out how to get tickets (currently PDFs) sent directly to a specified printer on a local/client PC.
我已經關注了許多舊的/死的/無用的鏈接,但沒有找到任何最新的解決方案,盡管有許多誘人的希望.
I have followed many old/dead/useless links and have not found any up-to-date solutions to this although many tantalising glimmers of hope.
場景是這樣的:遠程托管網站 - 連接了 1 個或多個用戶 - 網頁生成票證/s (PDF),以靜默方式發送到用戶電腦上的指定打印機(不是默認打印機)(無需額外點擊打印提示).
The scenario is this: Remote hosted website - 1 or more users connected - web page generates ticket/s (PDF) which is sent to a specified printer on the user pc (not the default printer) silently (no extra clicking through of print prompts).
我知道 PHP 無法連接到客戶端的 pc,但是有沒有辦法讓網頁(可能通過 jQuery)連接到已安裝的腳本/服務?
I know PHP does not connect to a clients pc but is there a way for a web page (via jQuery perhaps) to connect to an installed script/service?
我在想本地 PC 上的腳本(它建立可信鏈接、設置要使用的打印機等)會從 Web 服務器接收數據/文件,然后只要它在同一位置就可以處理它每臺機器.然后可以將此(本地)腳本添加到需要運行該服務的任何 PC.這項工作需要由正在發送的文件觸發,并且沒有腳本/服務每隔幾秒輪詢一個位置.
I was thinking the script on a local PC (which establishes a trusted link, sets the printer to use, etc) would receive data/file from the web server and then process it as long as it was in the same place on every machine. This (local) script then can be added to any PC that needs to run the service. The work would need to be trigged by the file being sent and not having a script/service which is sat polling a location every few seconds.
任何指針將不勝感激.
我嘗試過 jZebra java 小程序,但在它壞掉之前只打印了一次.有興趣是否有人真正讓它工作(以及如何工作).
I have tried the jZebra java applet but only got it printing once before it broke. Interested if anyone has actually got it to work (and how).
推薦答案
我最近遇到了完全相同的問題.谷歌瀏覽器具有所謂的信息亭"模式.因此,它將在沒有用戶干預的情況下打印.
I ran into the EXACT same question recently myself. Google Chrome has what's called a "kiosk" mode. Therefore, it will print without user intervention.
為此,請使用以下命令打開 Google Chrome(您需要找到 chrome 可執行文件,或 *nix 機器的 chrome 命令):
To do this, open Google Chrome with the following command (you need to find the chrome executable, or chrome command for *nix machines):
chrome.exe "http://www.example.com/mypage.php" --kiosk --kiosk-printing
這將打開一個沒有任何工具欄、地址欄、多功能框等的窗口.
This will open a window without any toolbars, address bars, omniboxes, etc.
接下來,您需要打印頁面.為此,請自動打開一個打印對話框(為了演示,我將使用簡單的 Javascript):
Next, you need to make a page print. To do this, automatically open a print dialog (for demonstration, I'll use simple Javascript):
<script>
window.print();
</script>
在跳轉到開發環境之前,window.print()
確實不允許允許任何參數(即 URL).
Before you jump over to your development environment, window.print()
does NOT allow any arguments (i.e. a URL).
此代碼打開一個打印對話框.但是,在 kiosk 模式下,打印對話框將被繞過,頁面將自動打印到默認打印機.
This code opens a print dialog. However, in kiosk mode, the print dialog will be bypassed, and the page will be automatically printed to the default printer.
現在您提到了一個 PDF,并且很有可能是您通過 PHP 生成它(如果您正在打印發布/生成的文件),您可能會想哦,我不能在 PDF 中放入 HTML 來執行 javascript".您不需要!要解決打印正確頁面的問題,方法如下:
Now you mentioned a PDF, and chances are, your generating it via PHP (if you are printing issued/generated files), your probably thinking "oh, well I can't put HTML in the PDF to execute the javascript". You don't need to! To solve the issue of printing the correct page, here's how:
將以下內容插入到用戶發送到的 HTML/PHP 頁面中(對于此解決方案,用戶不需要訪問 .pdf),在 ;
登陸/成功頁面:
Insert the following into an HTML/PHP page that the user is sent to (for this solution, the user does not need to visit the .pdf), in the <head>
of the landing/success page:
<link rel="alternate" media="print" href="LINK TO PDF FILE">
如果你的頁面中有上面的代碼,當你執行window.print();
時,它會打印上面指定的頁面.如果您不在本地保存 PDF,您可以將它放在一個臨時目錄中,該目錄以某種方式(超出本問題的范圍)按基于時間或基于操作的計劃清除,以防止磁盤空間增加.
If you have the above code in your page, when you execute window.print();
, it will print the page specified above. If you don't save the PDF locally, you can put it in a temporary directory that is somehow (out of the scope of this question) cleared on a time based or action based schedule, to prevent disk space buildup.
請記住以下幾點:
- 信息亭模式沒有退出按鈕.要退出,請按
ALT + F4
. - 在 kiosk 模式下打印時,您需要
--kiosk
AND--kiosk-printing
.打印參數需要--kiosk
參數. - 在自助服務終端模式下打印時,打印對話框出現然后突然消失是正常.如果沒有高級窗口分層等,就無法防止這種情況發生.
- Kiosk mode doesn't have an exit button. To exit, press
ALT + F4
. - When printing in kiosk mode, you need both
--kiosk
AND--kiosk-printing
. The printing argument requires the--kiosk
argument. - When printing in kiosk mode, it is normal for the print dialog to appear and then suddenly disappear. It can't be prevented without advanced window layering and whatnot.
我確信其他瀏覽器也有類似的功能來繞過打印對話框,但是,我發現谷歌瀏覽器在這種功能中效果最好.如果您在 Linux 機器上,Google 有一個 .deb 文件,您可以使用該命令在 Linux 上安裝 Google Chrome,使用命令 sudo dpkg -i(包/下載的 .deb 文件路徑)
.Chromium -- 可能 -- 支持這種功能.據我所知,應該.
I'm sure that other browsers have similar functionality to bypass the print dialog, however, I have found that Google Chrome works best in this kind of functionality. If your on a Linux machine, Google has a .deb file that you can install Google Chrome on Linux with, by using the command sudo dpkg -i (package / downloaded .deb file path)
. Chromium --might-- support this kind of functionality. As far as I know, it should.
如果您需要其他幫助,請在下面的評論中留下您的問題,我會盡快回復.
If you need additional help, leave your question in the comments below, I'll respond ASAP.
我希望我有所幫助.如果我這樣做了,請隨時給我一張你左邊的綠色支票.;)
I hope I helped. If I did, feel free to give me a green check to your left. ;)
這篇關于POS:讓網站直接打印到定義的本地打印機的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!