久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Electron JS 打印 PDF 文件

Printing a PDF file with Electron JS(使用 Electron JS 打印 PDF 文件)
本文介紹了使用 Electron JS 打印 PDF 文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試創建一個用于打印字母大小 PDF 的 Electron JS 應用程序.

I am trying to create an Electron JS app that has the purpose to print letter size PDFs.

這是我的打印代碼片段:

This is my snippet of code for printing:

win = new BrowserWindow({
  width: 378, 
  height: 566, 
  show: true, 
  webPreferences: {
    webSecurity: false,
    plugins: true
  }
});

// load PDF
win.loadURL('file://' + __dirname + '/header1_X_BTR.pdf');

// if pdf is loaded start printing
win.webContents.on('did-finish-load', () => {
  win.webContents.print({silent: true, printBackground:true});
});

我的問題是:如果我有 print({silent:true}),我的打印機會打印一個空白頁.如果我有 print({silent:false}),打印機的打印方式與屏幕截圖相同,帶有標題、控件等.

My issues are: if I have print({silent:true}) my printer prints an empty page. If I have print({silent:false}), the printer prints in the same way as the screenshot, with headers, controls, etc.

我需要 PDF 內容的靜默打印,但我好幾天都做不了.有人對 Electron 有過同樣的經歷嗎?

I need a silent print of the PDF content, and I can't manage to do it for days. Did anyone experience the same thing with Electron?

推薦答案

如果你已經有pdf文件或者你在打印我假設是"之前保存了pdf,那么你可以獲取文件位置然后你可以使用使用 child_process 進行打印的外部進程.

If you have already have the pdf file or you save the pdf before printing "I assuming it is", then you can grab the file location then you can use externals process to do the printing using child_process.

您可以使用 lp 命令 或 PDFtoPrinter窗戶

You can use lp command or PDFtoPrinter for windows

const ch = require('os');

switch (process.platform) {
    case 'darwin':
    case 'linux':
        ch.exec(
            'lp ' + pdf.filename, (e) => {
                if (e) {
                    throw e;
                }
            });
        break;
    case 'win32':
        ch.exec(
            'ptp ' + pdf.filename, {
                windowsHide: true
            }, (e) => {
                if (e) {
                    throw e;
                }
            });
        break;
    default:
        throw new Error(
            'Platform not supported.'
        );
}

希望對你有幫助.

您也可以使用 SumatraPDF for windows https://github.com/sumatrapdfreader/sumatrapdf

You can also use SumatraPDF for windows https://github.com/sumatrapdfreader/sumatrapdf

這篇關于使用 Electron JS 打印 PDF 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久久久久精 | 欧美久久久久久久久 | 成人av观看 | 精品久久不卡 | 国产精品一码二码三码在线 | 不用播放器看的av | 亚洲视频在线观看一区二区三区 | 毛片高清| 国产一级电影在线 | 国产精品黄色 | 国产精品成人免费 | 欧美一区久久 | 国产精品美女久久久久久久网站 | www.99re | 亚洲人成人一区二区在线观看 | 午夜午夜精品一区二区三区文 | 欧美aaa级| 偷拍自拍网 | 色成人免费网站 | 亚洲区视频 | 91九色porny首页最多播放 | 欧美日韩中文字幕在线 | 亚洲色图综合网 | 韩日av在线 | 久久性色 | 国产高清在线观看 | 久久综合狠狠综合久久综合88 | 99精品国产一区二区三区 | 亚洲国产精品一区二区第一页 | 亚洲午夜精品 | 亚洲欧美中文日韩在线v日本 | 国产精品日韩高清伦字幕搜索 | 欧美大片黄 | 韩日有码| 综合久久av | 99精品视频一区二区三区 | 日本淫视频 | 国产日产欧产精品精品推荐蛮挑 | 亚洲国产一区在线 | 国产免费观看一区 | 久久成人精品一区二区三区 |