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

電子,來自 BrowserWindow 的 printToPDF

electron, printToPDF from BrowserWindow(電子,來自 BrowserWindow 的 printToPDF)
本文介紹了電子,來自 BrowserWindow 的 printToPDF的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我了解電子中 printToPDF 的常用方法是在 main 進程中調用以下代碼:-

I understand the usual method within electron to printToPDF is within the main process to call the following code:-

const {BrowserWindow} = require('electron')
const fs = require('fs')

let win = new BrowserWindow({width: 800, height: 600})
win.loadURL('http://github.com')

win.webContents.on('did-finish-load', () => {
  // Use default printing options
  win.webContents.printToPDF({}, (error, data) => {
    if (error) throw error
    fs.writeFile('/tmp/print.pdf', data, (error) => {
      if (error) throw error
      console.log('Write PDF successfully.')
    })
  })
})

但是,我想要實現的是通過單擊按鈕從 BrowserWindow 中有效地調用 printToPDF.

However, what I am trying to achieve is to effectively call printToPDF from within BrowserWindow on the click of a button.

我由此理解:https://github.com/electron/electron/pull/1835/commits/1eba552a8d1ab4479824275f0e0a2cea9337bd8c 已將 printToPDF 暴露給 BrowserWindow,但沒有關于如何從網頁中實際調用 printToPDF 的文檔.

I understand from this: https://github.com/electron/electron/pull/1835/commits/1eba552a8d1ab4479824275f0e0a2cea9337bd8c that printToPDF has been exposed to BrowserWindow, but there is no documentation on how to actually call printToPDF from within a webpage.

它的谷歌也沒有顯示一個例子.有什么線索嗎?

A google of it doesn't reveal an example either. Any clues?

推薦答案

renderer.js

renderer.js

const ipc = require('electron').ipcRenderer

const printPDFBtn = document.getElementById('pdfME')

printPDFBtn.addEventListener('click', function (event) {
  ipc.send('print-to-pdf')
})

main.js

const electron = require('electron')
const fs = require('fs')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const Menu = electron.Menu
const Tray = electron.Tray
const ipc = electron.ipcMain

const path = require('path')
const url = require('url')
const shell = electron.shell

let mainWindow

ipc.on('print-to-pdf', function (event) {
  const pdfPath = path.join(__dirname, '/reports/print.pdf')
  const win = BrowserWindow.fromWebContents(event.sender)
  win.webContents.printToPDF({printBackground: true, landscape: true}, function (error, data) {
    if (error) throw error
    fs.writeFile(pdfPath, data, function (error) {
      if (error) {
        throw error
      }
      shell.openExternal('file://' + pdfPath)
      event.sender.send('wrote-pdf', pdfPath)
    })
  })
})

這篇關于電子,來自 BrowserWindow 的 printToPDF的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 美女天天干 | 中文在线播放 | 中文字幕黄色大片 | 日本大片在线播放 | 久久久久久久综合色一本 | 欧美日韩一区二区视频在线观看 | 99av成人精品国语自产拍 | www亚洲精品| 亚洲成a人片 | 欧美男人天堂 | 黄色精品 | 青娱乐自拍 | www.99热| 高清视频一区二区三区 | 欧美成年人视频在线观看 | 91av入口| 免费一区 | www.天堂av.com| 欧美在线视频网 | 天堂色 | 热99在线| 91精品免费| 欧美中文字幕一区二区三区亚洲 | 日本中文在线视频 | 日批日韩在线观看 | 欧美极品在线观看 | 综合久久亚洲 | 久草成人网 | 欧美成人一区二区三区片免费 | 亚洲一一在线 | 国产免费又色又爽又黄在线观看 | 香蕉国产在线视频 | 精品国产一区二区三区久久狼黑人 | 九九在线视频 | xxxxx黄色片 欧美一区免费 | 九九视频网| 成人免费在线 | 国产精品一区二区在线免费观看 | 成人精品视频在线 | 国产成人99久久亚洲综合精品 | 97精品超碰一区二区三区 |