Giter Club home page Giter Club logo

electron-pdf-window's People

Contributors

gerhardberger avatar risleylima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

electron-pdf-window's Issues

Printing PDF programatically

I would like to load a PDF in a hidden window, and then programmaticly send this to the printer without any interaction from the user. (The use would click the print button on my app's view)

I'm not sure what the object is that I should be interacting with in the PDFWindow that would give me access to the pdf.js PDFPrintService.

Thanks

Could not call remote function 'BrowserWindow'

Hey I'm trying to test run the PDFWindow from the electron console
win = new PDFWindow() win.loadURL('http://www.aclweb.org/anthology/P/P02/P02-1022.pdf')
but this the error message I'm getting:

remote.js:217 Uncaught Error: Could not call remote function 'BrowserWindow'. Check that the function signature is correct. Underlying error: Requires constructor call(…)
metaToValue @ remote.js:217
remoteFunction @ remote.js:234
PDFWindow @ index.js:57
(anonymous function) @ VM415:1

Quality of printed pdf (windows)

Hi, I noticed that using electron-pdf-window, the print speed is slow and quality not as crisp as using microsoft edge (font color gray vs black using microsoft edge) as default windows pdf viewer. Is there any configuration that I must know about ? Or is the chromium problem ? Thanks

package.json :
"electron-pdf-window": "^1.0.12",

Thanks

Can't load a PDF if the URL has parameters

If I pass a URL that ends with ".pdf" to the loadURL method, it works just fine. But I need to invoke a URL like this:
http://server/controller/action?id=1234&type=something
That URL returns a PDF file automatically generated. If I put that address in a Chrome window it loads the PDF without problem. But with the electron-pdf-window it doesn't. It throws an "Unexpected server response" exception. Then I check the console and I can see it is trying to open the following url:
http://server/controller/action?id
That is not the URL I'm invoking. Where is the url being interrupted? I'm looking for it in the code. I know I can find it sometime, but a little help would be very nice. Thank you anyway for a great plugin.

Can't loadURL from blob

Hi,
i'm trying to load a pdf file from a blob without success.
With a real url it's work, with blob url it render a blank page without error.
My code:
`const filePath = path.join(dirPath, files[0]);

  Utils.decryptStream(filePath, password, (error, content) => {

    const blob = new Blob([content], {type: 'application/pdf'});

    const objectURL = URL.createObjectURL(blob);

    const currentWindow = remote.getCurrentWindow();

    // console.log(objectURL);
    PDFWindow.addSupport(currentWindow);

    currentWindow.loadURL(objectURL);

  });

});`

Can anyone help me please?

Print PDF from Microsoft Windows 10

Hi Gerhard,
I'm having a problem during the test of my web application (into electron), regarding the pdf file printing with electron-pdf-window viewer.
Everything work fine with Linux and OSX too, but with Windows 10, when I click the "print icon" in the pdf viewer, the spool shows a 0KByte file processing and nothing happens anymore.
Have you ever had a similar issue?
Thanks a lot.
Franco

working fine before build using electron . , but not working after i build as exe file

Its working exactly perfect before build but when i build app as installer .exe file for windows and install exe file on windows 8.1 , its not showing pdf window, i am using it through renderer process on click of anchor. I ran out of the day but it doesn't looking to be solved. I total confused how to solve it out. please any help?

here is my code

function pdfWindow() {
const { BrowserWindow } = require('electron').remote
const PDFWindow = require('electron-pdf-window')
const win = new BrowserWindow({ width: 800, height: 800 })
PDFWindow.addSupport(win)
win.loadURL('http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf')
}

and i am calling this function on click of anchor tag

Update dependencies

Hi, please update project dependencies:

  • pdf.js (using: '1.6.264', latest: '1.9.426')
  • got (using: "7.1.0", latest: "9.2.1")

Thank you.

Only prompting to download

I am attempting to have the plugin load a pdf file after it is downloaded to a temporary location but it just prompts to save the file.

My Code Example:

session.defaultSession.on('will-download', (e, item, webContents) => {
    // Set the save path, making Electron not to prompt a save dialog.
    //item.setSavePath('/tmp/' + item.getFilename())
    item.setSavePath('/tmp/saved.pdf')
    var savedHere = item.getSavePath()

    item.on('updated', (event, state) => {
        if (state === 'interrupted') {
            console.log('Download is interrupted but can be resumed')
            item.resume()
        } else if (state === 'progressing') {
            if (item.isPaused()) {
                console.log('Download is paused')
            } else {
                console.log(`Received bytes: ${item.getReceivedBytes()}`)
            }
        }
    })
    item.once('done', (event, state) => {
        if (state === 'completed') {
            var pdfWindow = new PDFWindow({
                title: item.getFilename(),
                icon: path.join(__dirname, "img/64x64.png")
            });
            var fileLocation = url.format({
                pathname: path.join("C:", savedHere),
                protocol: 'file:',
                slashes: true
            })
            console.log("File Location: " + fileLocation)
            pdfWindow.loadURL(fileLocation)
        } else {
            console.log(`Download failed: ${state}`)
        }
    })
})

Shows an invalid package message when in production

Hi, I like your package. Thanks for it very much :)

I'm having an issue in production, and I'm wondering if you've seen it before.
This is my setup:

ipcMain.on('printPreviewPage', () => {
  const printPreviewFilePath = `file://${path.join(__dirname, './print-preview/contract-preview.pdf')}`;
  const newWindow = new BrowserWindow({
    width: 1200,
    height: 900,
    minWidth: 1200,
    minHeight: 900,
  });

  newWindow.setMenu(null);

  PDFWindow.addSupport(newWindow);

  contents.printToPDF({}, (error, data) => {
    if (error) throw error;

    fs.writeFile(printPreviewFilePath, data, (error) => {
      if (error) throw error;

      newWindow.loadURL(printPreviewFilePath)
    })
  })
});

This works like a charm in development mode, but in the production, it results in this error message:
image

PDFWindow does not respect custom protocols

Title speaks for itself, PDFWindow thinks only http, https and file protocols exist, which is not the case, you can register any custom protocol with electron.

Here's the fix, I'm too lazy to fork/pull/commit/push/pr now

function isPDF (url) {
  return new Promise((resolve, reject) => {
    if (url.match(/^file:\/\//i)) {
      const fileUrl = url.replace(/^file:\/\//i, '')
      const buffer = readChunk.sync(fileUrl, 0, 262)
      const ft = fileType(buffer)

      if (!ft) return resolve(false)

      resolve(ft.mime === 'application/pdf')
    } else if (url.match(/\.pdf$/i)) {
      resolve(true)
    } else {
      const m = url.match(/^(https*):\/\//i)
      if (!m)
        resolve(false)
      const prot = m[1] == "http" ? http : https

      prot.get(url, res => {
        if (res.headers.location) {
          isPDF(res.headers.location).then(isit => resolve(isit))
            .catch(err => reject(err))
        } else {
          res.once('data', chunk => {
            res.destroy()

            const ft = fileType(chunk)
            if (ft) {
              resolve(ft.mime === 'application/pdf')
            } else {
              resolve(false)
            }
          })
        }
      })
    }
  })
}

Error using from renderer process

Using PDFWindow in the renderer process causes error.

Uncaught TypeError: Class extends value undefined is not a constructor or null
    at /Users/user/project/node_modules/electron-pdf-window/index.js:51
    at Object.<anonymous> (/Users/user/project/node_modules/electron-pdf-window/index.js:109)
    at Module._compile (module.js:571)
    at Object.Module._extensions..js (module.js:580)
    at Module.load (module.js:488)
    at tryModuleLoad (module.js:447)
    at Function.Module._load (module.js:439)
    at Module.require (module.js:498)
    at require (internal/module.js:20)
    at HTMLButtonElement.openPdfInWindow (script.js:53)

File Not Found When Loading URL

I'm getting this error when trying to load in url.

file:///Users/admin/Documents/ReactApp/repast/app/pdfjs/web/viewer.html?file=http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf
Failed to load resource: net::ERR_FILE_NOT_FOUND

const win = new BrowserWindow({webPreferences: {allowRunningInsecureContent : true, webSecurity: false}})
PDFWindow.addSupport(win)
setTimeout(()=>{
win.loadURL('http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf')
},2000)

Any reason why this is happening?

iframe support possible

Is it possible to support iframes inside the PDFWindow

Using

<html><body>
<iframe width="500" height="500" src="test.pdf"></iframe>
</body></html>

only brings up a "Save As Dialog"

Opening local pdf files on Windows downloads them, shows blank window.

We develop an electron app which displays a local single page application which on occasion contains links to (also local) pdf files.
We have included electron-pdf-window and use it with PDFWindow.addSupport(mainWindow);.
On a mac, when clicking a link to these pdf files (<a> element using target="_blank") a new window opens and the pdf file is displayed - perfect, just as intended.
On windows, when clicking the link, a new blank window opens and the pdf file is offered for download. How can we achieve the same behavior as on the mac?

Thank you guys for all your effort, it is much appreciated.

Pdf empty when created with custom font

So I'm trying to load a pdf created with jspdf using a custom font, but when I try to load the file in a webview it appears as an empty pdf, if I don't use the custom it shows the text but if I try to use a font the text disappear. The pdf created with the custom font works in Firefox, Chrome, and Edge.

This is a piece of code to exemplify what I'm trying to do.

 const PDFWindow = require('electron-pdf-window');
 const fs = require('fs');

 let webview = document.querySelector("webview");
 webview.webContents = webview.getWebContents();
 PDFWindow.addSupport(webview);

 let doc = new jsPDF();
 doc.setFont("Roboto-Regular"); // if I coment this it works
 doc.setFontSize(8);
 doc.setFontType('bold');
 doc.text('Hello world!', 10, 10)
 let file = doc.output();

 fs.writeFile(name_of_file, file, 'utf8', function(err){
   webview.loadURL(path_to_file);
   $("#modalPDF").modal();
 });

Prevent navigation to links in PDF file

I'm currently working with your PDFWindow and it's great except I can't prevent the navigation to an external link when it's clicked. My code to prevent the navigation is

app.on('web-contents-created',function(ev,wc){
  wc.on('will-navigate',ev=>{
    ev.preventDefault();
    wc.stop();
  })
})

and it's working on every window except yours. Am i doing something wrong or this is actually a bug?

加载本地pdf一直是空白

webview = document.getElementById("webview")
let area = document.querySelector(".webview-area")
const PDFWindow = require('electron-pdf-window')
const win = new BrowserWindow({
width: 800,
height: 600 ,
webPreferences: {
plugins: true
}
})
PDFWindow.addSupport(win)
win.loadURL("file:1.pdf"))
`
上面的这样不行,也不报错,pdf也不显示

我的1.pdf在当前页面的同级目录

需要需改一下loadURL地址才行, 使用path模块
PDFWindow.addSupport(win) const path = require("path") win.loadURL(path.resolve(__dirname, "1.pdf"))

这样就没问题
将就着看吧 github这个markdown的解析真的是醉醉的

showMessageBox not working

Hi,

It seems that if I try to use showMessageBox with PDF Window (specifying the pdf window as the browserwindow), the message box no longer works. It just appears to display blank.

Is there a correct way to attach a message box to the PDFWindow?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.