npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-pdf-window-custompdf-private

v1.0.12

Published

view PDF files in electron browser windows

Downloads

6

Readme

electron-pdf-window

view PDF files in electron browser windows. this module adds support for viewing PDF files in electron BrowserWindows. it works even if you navigate to a PDF file from a site, or opening a PDF file in a new window. a PDFWindow instance is just a subclass of BrowserWindow so it can be used just like it.

const { app } = require('electron')
const PDFWindow = require('electron-pdf-window')

app.on('ready', () => {
  const win = new PDFWindow({
    width: 800,
    height: 600
  })

  win.loadURL('http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf')
})

install

$ npm i electron-pdf-window

usage

win = new PDFWindow([opts])

win is an electron BrowserWindow that has support for viewing PDF files.

PDFWindow.addSupport(win)

adds PDF viewing support for win, which is a BrowserWindow instance.

using from the renderer process

Using the PDFWindow class directly from the renderer process is not recommended, because electron doesn't support proper extending of their built-in classes. In order to add PDF support from the renderer, use the addSupport method.

const { BrowserWindow } = require('electron').remote
const PDFWindow = require('electron-pdf-window')

const win = new BrowserWindow({ width: 800, height: 600 })

PDFWindow.addSupport(win)

win.loadURL('file:///a/b/c.pdf')

test

$ npm test

项目定制处理

库内PDF_JS_PATH默认为_dirname 在本项目中 _dirname的地址并不全 因此会导致资源无法正常预览 因此修改了本地electron-pdf-window库内的地址加载方式 1.进入electron-pdf-window的index.js 将 const PDF_JS_PATH = path.join(__dirname, 'pdfjs', 'web', 'viewer.html') 更改为 const URL = require('url'); const isDev = require('electron-is-dev')

const app = isRenderer ? electron.remote.app : electron.app let PDF_JS_PATH = ''

if (isDev) { PDF_JS_PATH = URL.format({ pathname: path.resolve(path.resolve(__dirname), 'pdfjs', 'web', 'viewer.html') }) } else if (process.platform === 'darwin') { PDF_JS_PATH = path.join(app.getAppPath() + '/' + __dirname, 'pdfjs', 'web', 'viewer.html') //mac } else { PDF_JS_PATH = path.join(${app.getAppPath()}\\${__dirname}, 'pdfjs', 'web', 'viewer.html') //windows }

2.为了提高加载速度 ①index.js内 loadURL()方法 改为loadURL(url, options) { super.loadURL(file://${path.join(__dirname, 'pdfjs', 'web', 'viewer.html')}?file=${decodeURIComponent(url)}, options) } ②index.js内 第113行 改为 browserWindow.loadURL = function (url, options) { load.call(browserWindow, file://${PDF_JS_PATH}?file=${decodeURIComponent(url)}, options) }