GithubHelp home page GithubHelp logo

artiebits / pdf-to-printer Goto Github PK

View Code? Open in Web Editor NEW
399.0 8.0 118.0 44.31 MB

Print PDFs and images from Node.js and Electron

Home Page: https://artiebits.com

License: MIT License

JavaScript 4.32% TypeScript 95.68%
pdf printer pdf-printer zebra-printer rollo-printer silent-printing nodejs electron windows jpeg

pdf-to-printer's Introduction

Node.js printing

Build Status codecov npm

A utility for printing PDFs and images from Node.js and Electron.

Support This Project

If you rely on this package, please consider supporting it. Maintaining an open source project takes time and your support would be greatly appreciated.

Buy Me A Coffee

Installation

You can install the package using npm:

npm install --save pdf-to-printer

Or yarn

yarn add pdf-to-printer

Basic Usage

To print a file to the default printer:

import { print } from "pdf-to-printer";

print("assets/sample.pdf").then(console.log);

API

.print(pdf[, options]) => Promise<void>

A function that prints your file.

Arguments

  1. pdf (string, required): A path to the file you want to print. An error will be thrown if the PDF is not specified or not found.
  2. options (Object, optional):
    • printer ( string, optional): Sends the file to the specified printer.
    • pages (string, optional): Specifies which pages to print in the PDF document.
    • subset (string, optional): Prints odd pages only when the value is odd, and even pages only when it is even.
    • orientation (string, optional): Provides 90-degree rotation of contents (NOT the rotation of paper which must be pre-set by the choice of printer defaults).
    • scale (string, optional): Supported names are noscale, shrink, and fit.
    • monochrome (boolean, optional): Prints the document in black and white. The default value is false.
    • side (string, optional): Supported names are duplex, duplexshort, duplexlong, and simplex.
    • bin (string, optional): Select tray to print to. Number or name.
    • paperSize (string, optional): Specifies the paper size. A2, A3, A4, A5, A6, letter, legal, tabloid, statement, or a name selectable from your printer settings.
    • silent (boolean, optional): Silences error messages.
    • printDialog (boolean, optional): Displays the print dialog for all the files indicated on this command line.
    • copies(number, optional): Specifies how many copies will be printed.

Returns

Promise<void>: A Promise that resolves with undefined.

Examples

To print a file to the default printer, use the following code:

import { print } from "pdf-to-printer";

print("assets/sample.pdf").then(console.log);

To print to a specific printer:

import { print } from "pdf-to-printer";

const options = {
  printer: "Zebra",
};

print("assets/pdf-sample.pdf", options).then(console.log);

Here is an example with a few print settings. It will print pages 1, 3, and 5, and scale them so that they fit into the printable area of the paper.

import { print } from "pdf-to-printer";

const options = {
  printer: "Zebra",
  pages: "1-3,5",
  scale: "fit",
};

print("assets/pdf-sample.pdf", options).then(console.log);

.getPrinters() => Promise<Printer[]>

A function to get a list of available printers.

Returns

Promise<Printer[]>: a Promise that resolves with a list of available printers.

Examples

import { getPrinters } from "pdf-to-printer";

getPrinters().then(console.log);

.getDefaultPrinter() => Promise<Printer | null>

A function to get the default printer information.

Returns

Promise<Printer | null>: a Promise that resolves with the default printer information, or null if there is no default printer.

Examples

import { getDefaultPrinter } from "pdf-to-printer";

getDefaultPrinter().then(console.log);

License

MIT

pdf-to-printer's People

Contributors

artiebits avatar brunoguschagas avatar ccarnivore avatar codacy-badger avatar dattn avatar dependabot-preview[bot] avatar dependabot[bot] avatar ferretwithaberet avatar gallyamow avatar github-actions[bot] avatar ibrahimelaradi avatar joaodematejr avatar joshycube avatar khannanova avatar matyx avatar mcdado avatar milburngomes avatar patrick-remy avatar prayuj avatar rasgo-cc avatar sebastianroming avatar smallsoft-gustavo 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  avatar

pdf-to-printer's Issues

Angular 6 - ERROR in ./node_modules/pdf-to-printer/dist/bundle.js

ERROR in ./node_modules/pdf-to-printer/dist/bundle.js
Module not found: Error: Can't resolve 'child_process' in 'D:\MyWorkPlace\set-fusion\social-document-service\frontend\node_modules\pdf-to-printer\dist'
ERROR in ./node_modules/pdf-to-printer/dist/bundle.js

My code -
import ptp from "pdf-to-printer";

ptp
.print("assets/file.pdf")
.then(console.log)
.catch(console.error);

}

How to change A4 printing to A6

My original PDF file is A6 size, but I can only print and save it as an A4 size PDF file through your extension, forcibly changing its size. Is there any way to adjust the size of the printed PDF?

Print cut into stripes

Describe the bug
The printe comes out cut into stripes, I don't know if it's a problem with my pdf or if I'm doing something wrong.

To Reproduce
Steps to reproduce the behavior:

  1. Print a PDF like in the documentation example.

Expected behavior
Print a nice document.

Screenshots

This is how it prints the document:

image

And this is a basic print from crhome, it is what it should be:

image

Desktop (please complete the following information):

  • OS: Windows 10 2004
  • Node 15.2.0
  • Version 1.7.0

TypeError: printer.list is not a function in version 1.4.1

I tried to recreate your express-server example. But when I installed pdf-to-printer, it installed to the latest version. On hitting http://localhost:8080/list, I get the below error:
TypeError: printer.list is not a function
at list (C:\Users\DELL\Desktop\print-app-node\src\list.js:13:6)
at Layer.handle [as handle_request] (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\index.js:275:10)
at jsonParser (C:\Users\DELL\Desktop\print-app-node\node_modules\body-parser\lib\types\json.js:110:7)
at Layer.handle [as handle_request] (C:\Users\DELL\Desktop\print-app-node\node_modules\express\lib\router\layer.js:95:5)

However, if I revert to the version used in the example (i.e. version 1.1.1) it works fine.

My printer does not have toner, so printing status is not returning here.

Describe the bug
The problem is when i send print command to printer, the printer does not have enough page or toner to print then any error or printer status is not returning here.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Send printer command with using pdf-to-printer package in electron.'
  2. Printer does not have enough page or toner to print.
  3. Showing empty status in then block

Expected behavior
Behavior as returning exception message from printer related to hardware or some problems or status of printer
Like Paper is not there. please add papers.

Desktop (please complete the following information):

  • OS: Windows 10

** Needed proper exception status from printer, like status of printer.

Not possible to print when printer is in black/white mode

Describe the bug
I only have one black ink cartridge in the printer. What makes it impossible for me to print a black page. If I only allow black and white printing in the print settings, the print job cannot be started because the program wants to print in color.

To Reproduce
Steps to reproduce the behavior:

  1. Remove the color ink from your printer.
  2. Try to print a pdf with only black content.
  3. You will get an empty sheet "printed".

Expected behavior
If i want to print a black page, the pinter should be able to print it without color ink

Screenshots

Desktop (please complete the following information):

  • OS: [Mac OS]
  • Version [10.14.5]
  • Printer: [Canon IP2700]

Run ESLint on __test__ folder

Existing lint script runs ESLint on src, webpack.production.config.js, and examples folders only. The solution might be adding __test__ and __mock__ folders to that script as well.

Uncaught No such file local

Hello everyone, I have a problem where the pdf file is not found even though the path is correct.

Follows code below.

`const options = {
printer: "ELGIN-I9"
};

	    	printer
	    	  .print("req.pdf", options)
	    	  .then(console.log)
	    	  .catch(console.error);`

I am sorry for my english.

Getting Error while sent document for print

Hello, I'm using Electron and angular I'm saved my pdf in pdf dir but getting error when printing

zone.js:391 Error: Command failed: "C:\Users\Desktop\node_modules\electron\dist\resources\electron.asar\renderer\SumatraPDF.exe" -print-to "Zebra" -silent "C:\Users\AppData\Roaming/pdf/digi-50726_1568982692.pdf"
The system cannot find the path specified.

at ChildProcess.exithandler (child_process.js:299)
at ChildProcess.emit (events.js:182)
at maybeClose (internal/child_process.js:962)
at Socket.stream.socket.on (internal/child_process.js:381)
at Socket.emit (events.js:182)
at Pipe._handle.close (net.js:606)

Error while installing on windows

Describe the bug
When I set up my project with Node.js on Windows, install the pdf-to-printer and try to run the application it returns an error.

Capture

To Reproduce
Steps to reproduce the behavior:

  1. Set up the project on windows environment (with node.js)
  2. Open the cmd
  3. run yarn
  4. run yarn start
  5. See the error

Expected behavior
The application should start without any problems.

Screenshots
Capture

Desktop (please complete the following information):

  • OS: Windows 10
  • Node.js application

Print process fails when a printer name is given .

Describe the bug
When I am trying to print to a any specific printer name (using the -print-to arguement), that exist and is installed in my system, the childprocess fials. However using the exact same command that was generated, directly through cmd, it works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. add a specific printer name to the printer options
  2. try to print a document
  3. See error

Expected behavior
Expected result was to print the document using the printer that was provided

Desktop (please complete the following information):

  • OS: Windows 10
  • NodeJS v12.16.2

Additional context

i have tried to add the printer name in the options like this

    print(options) {
        const printer = this.settings.printer || 'default';
        if (printer === 'default') {
            ptp.getDefaultPrinter()
                .then(printerResp => {
                    return Promise.resolve({
                        ...options,
                        printer: printerResp
                    })
                })
                .then(options => {
                    ptp.print(this.path, options)
                })
                .catch(console.error);
        } else {
            ptp.print(this.path, {
                ...options,
                printer: printer
            })
                .catch(console.error);
        }
    }

in this function i am checking if the name of the given printer is explicitely "default" in this case i am using the getDefautlfPrinter method and then i am using its response as the printer name. The response always gives the name of the Default printer as expected, and then print works just fine.

However if I give an explicit printer name to the option as it it seems on the second part of the conditional, i get the following error

(I am omiting the full path to the module and the input pdf file, for the shake of clarity)

Error: Command failed: C:\...\pdf-to-printer\dist\SumatraPDF.exe -print-to LEXLUTHOR -print-settings "fit,paper=A5" -silent C:\...\123print.pdf

    at ChildProcess.exithandler (child_process.js:303:12)
    at ChildProcess.emit (events.js:310:20)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:443:11)
    at Socket.emit (events.js:310:20)
    at Pipe.<anonymous> (net.js:672:12) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'C:\\...\\pdf-to-printer\\dist\\SumatraPDF.exe -print-to LEXLUTHOR -print-settings "fit,paper=A5" -silent C:\\...\123print.pdf'
}

the generated command.

'C:\\...\\pdf-to-printer\\dist\\SumatraPDF.exe -print-to LEXLUTHOR -print-settings "fit,paper=A5" -silent C:\\...\\123print.pdf

If I copy the command and paste directly into cmd, and execute it from there it works as expected.

This might be some problem with my system as well, since I haven't seen this issue here. It might even have to do with SumtraPdf. However any guidance on what might cause this would be very helpful

__dirname in electron&vue (webpack) context not working

I am having a tough time to get pdf silent print working in our electron-vue app.
The reason is, that pdf-to-printer is using __dirname in pdf-to-printer/src/win32/print.js, and in webpack context, this does not return the expected path as stated here:
https://simulatedgreg.gitbooks.io/electron-vue/content/en/main-process.html#on-the-subject-of-using-dirname--filename

const getCommand = (pdf, options) => {
  let command = path.join(__dirname, "SumatraPDF.exe");

  command = fixPathForAsarUnpack(command);
  command = `"${command}"`;

__dirname returns instead of the path to the module, just the path to the electron app root in dev mode (electron:serve) and to this in bundles app mode (electron:build)

In production I get this error:
'"C:\Users\MYUSER\AppData\Local\Programs\my-electron-app\resources\app.asar.unpacked\SumatraPDF.exe"' is not recognized as an internal or external command, operable program or batch file.

Possible solution
I suggest, that you enable the user of your module to hand over the path to the Executable via another parameter or option.

Alternatives I've considered
I tried to move SumatraPDF.exe with different attempts. The last one was to add an extraFIles section into the electronBuild configuration. But then, the SumatraPDF.exe ends up in the App root or resource folder, but not in resource/app.asar
Because electron-vue abstracts so much away, it is not easy to add stuff to webpack or electronBuilder config. The configuration options are sometimes not so well documented, and because I'm working on a Mac, it takes ages in my Virtualbox Windows environment to build the app each time I change something.

Additional context
I wonder, why this is working for others. You code suggests, that you have tested, because you event have fixPathForAsarUnpack in place.

Cheers,
@matths

win32 settings didn't work

Describe the bug
I want to pop up the Print dialog , thie options are defined as follows, but it It didn't work.
let options = {
'win32': ['-print-dialog', '-print-settings "2x"']
}
ptp.print(filePath, options).then((res) => {
console.log('print res:', res)
}).catch((err) => {
console.error('print err:', err)
});

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

License question

Hi,
this project is licensed under MIT, but SumatraPDF executable is part of the repository with is GPLv3 as far as I can see.
How is this working out?

What do I need to do, when I want to use this package in a commercial electron shell application?

Best
Michael

When pdf path contains space,throws error

This is my code:

import printer from 'pdf-to-printer';

let filePath = '/Users/xionglei/Library/Application Support/Electron/web_cache/out.pdf';

const options = {
  printer: 'PDFwriter'
};

printer
  .print(filePath, options)
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err);
  });

logs:

 Error: Command failed: lp /Users/xionglei/Library/Application\ Support/Electron/web_cache/out.pdf -d PDFwriter
  lp:error - “/Users/xionglei/Library/Application\ Support/Electron/web_cache/out.pdf”- No such file or directory
  
      at ChildProcess.exithandler (child_process.js:308:12)
      at ChildProcess.emit (events.js:203:13)
      at maybeClose (internal/child_process.js:1021:16)
      at Socket.<anonymous> (internal/child_process.js:430:11)
      at Socket.emit (events.js:203:13)
      at Pipe.<anonymous> (net.js:588:12) {
    killed: false,
    code: 1,
    signal: null,
    cmd: 'lp /Users/xionglei/Library/Application\\ Support/Electron/web_cache/out.pdf -d PDFwriter'
  }

/Users/xionglei/Library/Application Support/Electron/web_cache/out.pdf is exist

Return job ID when using on windows

At the moment when using this module on mac, the job ID is returned together with the printer name. When using this on windows, nothing is returned. Is there a way to make this possible so we can monitor the print job?

Printer listing fails on macOS

Printer listing fails on macOS 10.12 and the child process exits with the following error.
Ti seems like lpstat uses different arguments.

Error: Command failed: lpstat -e
[1] lpstat: Error - unknown option “e”.

Printer name with space in it errors

Describe the bug
On windows platform, when there is a printer with a space in it's name, and you pass a printer, the command fails to run as it's not escaped with quotes.

To Reproduce
Steps to reproduce the behavior:

  1. Rename printer with a space in it
  2. Pass that printer name as returned by getPrinters()
  3. Command that is produced doesn't run as there's a space.

Expected behavior
The printer name to be escaped with quotes on the commandline. I believe this is a similar error to the path of the file to print.

I know this isn't your main focus, but would be greatly appreciated fix. Thank you!

More options to print a PDF

I would like to know if there is a way to set more options (not just the printer name) to the 'print' function.

At the moment on windows, if I print a PDF manually the result is not the same if I use the 'print' function. I'm pretty sure this is related with the option 'fit to page'.

Is there a way to include this option together with the printer name ?

Setting Copies in the Win32 Options Array is ignored.

So, i set the options for win32 to 3 copies, as thats what i need.

const options = {
        printer: printer_name,
        win32: ['-print-settings "3x"']
    };

And then i do the print...

ptp.print(filePath, options).then(res => {
        console.log('Print Complete');
    }).catch(err => {
        console.log(err);
    });

But i still only ever get 1 copy sent to my printer.. Am i doing something wrong?

Printing cut-off pages ('fit-to-page' print setting not working - using default Windows 10 print settings)

Describe the bug
Unable to format the print. The print does not have "fit-to-page" settings. It has the Windows 10 default print settings that cuts off part of the page.

To Reproduce
Steps to reproduce the behavior:

  1. Install pdf-to-printer, write the script written in the documentation:
 const options = {
  printer: "Zebra",
  unix: ["-o fit-to-page"],
  win32: ['-print-settings "fit"']
};

ptp
  .print("assets/pdf-sample.pdf", options)
  .then(console.log)
  .catch(console.error);
  1. Run the script

Expected behavior
You want to print the PDF file with print-settings set to "fit-to-page"

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Google Chrome
  • Version: v89
  • Printer: HP Printer, I think. I do not have SumatraPDF installed on the computer.

Additional context
Does "pdf-to-printer" npm package use SumatraPDF in the background? You are using this in the documentation. Do I have to download SumatraPDF for this npm package to work? I expect not to download anything else. Windows 10 printer does not need any software to download PDF so.... Please instruct me if I need to download SumatraPDF separately

Print Color Settings?

Could you please tell me how to set the printing color, color, black and white?
There is a need to set the printing color of the printer, but see the UNIX system, print command parameters, do not find the option to set the color. Please tell me how to set it.

Possibility to set the print size

Describe the solution you'd like
I have a problem with the size of the printed label on the Zebra printer. I have a label that has to be 10x15 and when I print it manually out of the pdf file it is printed correctly (10x15), but when I have printed the same pdf using the library the end result is 70% of the destination size.

Describe alternatives you've considered
I was thinking about the printer configuratiin but I have ended up with the solution that was acceptable.

Additional context
Maybe we could provide the printing size via additional params that we are able to pass to the print function?

Cannot be called after wrapping with electron

Sorry, I don't know English very well, so I am Posting the code snippet

SumatraPDF.exe ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21)

Then I changed the path code on the 'electron-util.js'
export const fixPathForAsarUnpack = (path) => { // return isUsingAsar ? path.replace("app.asar", "app.asar.unpacked") : path; return path.replace("/app.asar", "") };

And then the print worked

printing from main process?

To Reproduce
Steps to reproduce the behavior:
calling printer.print in the main process. error message should cannot read property 'print' of undefined.

Expected behavior
the pdf should be printed

Screenshots

Desktop (please complete the following information):

  • OS: windows 10
  • Browser chrome
  • Version 78.0.3904.70

saw the react example, question is, does it has to print in the renderer process?

gsprint in addition to SumatraPDF

I'd like to use gsprint as alternative to sumatrapdf.

I think the main reason why you've chosen sumatrapdf is the portable executable.
But in my eyes sumatrapdf is not a good pdf-printing tool.

What do you think when adding an ENV_Parameter to configure pdf-to-printer to use gsprint (installer won't be included) over sumatra?

If its okay for you, I'd start working on this and opening a PR when I'm @#done.
@artiebits

Print specific pages

Hi there,

Is there an option to print only specific pages of the document? Cheers.

Error in the docs

The docs are saying that to fit the print in the page size, you have to do this:
const options = { printer: "Zebra", unix: ["-n 2"], win32: ['-print-settings "2x"'] };

But this actually prints the same page two times.

To fit the page the settings should be:
const options = { printer: "Zebra", unix: ["-o fit-to-page"], win32: ['-print-settings "fit"'] };

Add human readable name to the list returned by getPrinters

Is your feature request related to a problem? Please describe.
We only have the printer code name, with _, which is not nice for displaying.

Describe the solution you'd like
Electron's getPrinters returns a list of objects representing printers which got properties for name(device code) and a displayName which contains the human readable name of the printer without _.

Describe alternatives you've considered
None

Additional context
None

Error: Command failed: <path to nodejs application>\node_modules\pdf-to-printer\dist\SumatraPDF.exe -print-to PRINTERNAME -silent filename.pdf

I have been butting my head against this problem and I can't find the solution. I've uninstalled and reinstalled the package multiple times and it doesn't work, my code looks like this:

const options = {
printer: localPrinter // local printer provided as a string of the printer name
}

printer
.print(customer, options)
.then(console.log("File printed."))
.catch(console.error)

Integrate with Vuejs using vue-cli-plugin-electron-builder

When using this plug in on a normal electron app, it works as intended.

When spinning up a vuejs app, along with the electron builder. I install pdf-to-printer plug in I get the below error

bundle.js?50d2:1 Uncaught Error: Platform not supported
at eval (bundle.js?50d2:1)
at Object.eval (bundle.js?50d2:1)
at r (bundle.js?50d2:1)
at eval (bundle.js?50d2:1)
at eval (bundle.js?50d2:1)
at eval (bundle.js?50d2:1)
at Object.eval (bundle.js?50d2:1)
at eval (bundle.js:2)
at Object../node_modules/pdf-to-printer/dist/bundle.js (chunk-vendors.js:172)
at webpack_require (app.js:849)

I have looked high and low for a solution but not come across anything.

Below are my dependencies

"dependencies": {
"pdf-to-printer": "^1.5.0",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-service": "~4.5.0",
"electron": "^9.0.0",
"electron-devtools-installer": "^3.1.0",
"vue-cli-plugin-electron-builder": "~2.0.0-rc.4",
"vue-template-compiler": "^2.6.11"
}

Please let me know if you need any more information.

SLOW printing time 3-4 minutes

On Windows Server 2016 i'm using this module and i saw on node_modules SumatraPDF.exe is used versione 3.0.0 i had slow performances printing PDF. I updated the sumatraPDF.exe file to versione 3.1.2 inside node modules and solved the issue!
Hope you can update the sumatraPDF.exe file inside your dependencies !

Cheers !

Uncaught No such file

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Type definitions for typescript

Is your feature request related to a problem? Please describe.
I cant use this library in TS, because there are missing type definitions (TS wont compile).

Describe the solution you'd like
Include types in github repo (I can send PR).

Describe alternatives you've considered

Additional context

Print specific pages results in Bad page-ranges values 0-0

Describe the bug
Using example from issue #71, I'm not able to get this module to print a specific number of pages.

To Reproduce
Steps to reproduce the behavior:

  1. Print multipage document using default printer and for options pass {unix: ['-P "1,3"']}
  2. See error, and it prints all pages.

Command failed: lp Labels-1584027849474.pdf -P "1,3" lp: Bad page-ranges values 0-0.

Expected behavior
Print page 1 and 3

Desktop (please complete the following information):

  • OS: Ubuntu 18.04LTS
  • Browser electron/chrome
  • Version 1.1.1 and updated to 1.4.0 with same problem after removing node modules and re-installing

Additional context
I am using the module in a electron app.

    const options = {};
    options.unix = ['-P "1,3"'];
    options.win32 = ['-print-settings "1,3"'];

    reader.onload = async function () {
      const writeFileAsync = promisify(fs.writeFile);
      await writeFileAsync(saveToPath, Buffer.from(new Uint8Array(this.result)));
      printer.print(saveToPath, options); // print to default printer
    };

win10 electron print failure

Error: spawn cmd.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:264)
at onErrorNT (internal/child_process.js:456)
at processTicksAndRejections (internal/process/task_queues.js:80)

print() fails when there is a space in the path from which the script is run

Hey,

.print() fails when there is a space in the path when using on Windows OS.

Error: Command failed: C:\Anuraag\<path with space>\node_modules\pdf-to-printer\dist\SumatraPDF.exe -print-to-default -silent assets/temp.pdf
'<path with space comes here>' is not recognized as an internal or external command,
operable program or batch file.

    at ChildProcess.exithandler (child_process.js:304:12)
    at ChildProcess.emit (events.js:196:13)
    at maybeClose (internal/child_process.js:1000:16)
    at Socket.<anonymous> (internal/child_process.js:405:11)
    at Socket.emit (events.js:196:13)
    at Pipe.<anonymous> (net.js:586:12) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'C:\\Anuraag\\' +
    '<path with space>\\node_modules\\pdf-to-printer\\dist\\SumatraPDF.exe ' +
    '-print-to-default -silent assets/temp.pdf'

To Reproduce
Steps to reproduce the behavior:

  1. Create a directory with spaces on it on Windows 10 OS
  2. Store a PDF in an "assets" folder
  3. Copy commands from the readme.

Expected behavior
Path should be placed in quotes when sending to PDF engine

Desktop (please complete the following information):

  • OS: Windows 10
  • NodeJS v12

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.