-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can the PDF viewer have the node context? #5002
Comments
What's the details of the issue? It may not be related with Node context. On Sun, Jun 19, 2016, 2:22 AM IBSNA notifications@github.com wrote:
|
Hi @rogerwang, Basically I am programmatically opening a window to a PDF file and then executing the print method in that window, however it only fires the standard window.print() function, When I inspected the PDF page, it appears it does not have access to the node context ( I tried requiring something directly in pdf.js source within the DevTools but it didn't recognize the require method ) I know I can use Kiosk mode to automate the printing, however the problem is that I am choosing which printer to print to, but the standard window.print doesn't support the printer option. Offtopic: thank you for creating this project. Regards. |
@rogerwang A short term solution would be a way to set the default printer programmatically, so I was wondering is there an exposed API that does this? I assume the chrome printing window has something like this because when you change the printer, it persists if you close the print window and open it again. Regards. |
Have you tried setting |
@joshterrill Hi, yes I tried, unfortunately "chrome-extension://" is considered an invalid scheme. |
@rogerwang Any suggestion on how to do this? |
I didn't mean to try |
@joshterrill Thank you, I tried that as well, but I am getting this error: "Missing scheme separator" Looks like in the new build you must include a scheme. and "chrome-extension://" Happens to be considered invalid. Regards. |
What are you putting into the |
I also tried using {nodejs: true} with Window.open, but it didn't recognize that attribute. |
@joshterrill Here you go:
|
How would you modify the chrome-extension file you're looking to modify to add node to anyway? Where would you modify the file at? Are you compiling webkit yourself? |
@joshterrill The idea is to programatically open a new window to a PDF file like so:
and then execute the new print method, to print to a specific printer. However since it runs the PDF viewer extension which doesn't happen to have the node context it ends up running the normal browser .print() method. which doesn't support the |
So your end goal is to just use the print api in nwjs to automatically print a PDF? You could do this by |
@joshterrill I want to open an existing PDF and send it to the printer of my choice. the example you gave is used to print the current page to a new PDF file. Basically: open an existing PDF file in a new window, and execute the .print method. however as I explained there is no node context in the PDF viewer extension, so it just executes the normal browser I hope the idea is clear now. Thanks! |
I've almost got it working. Try |
@joshterrill Yes that almost did the job. however it looks like |
@joshterrill I Inspected the PDF viewer window just to be sure and it looks like it doesn't have the node context even with the nifty |
So here's how I'm able to interact with the new window:
So interestingly enough, when you call just |
@joshterrill Interesting... I just tried this however I am still getting the same behavior. If only there is a way to get the node context available when the PDF viewer extension runs. that would solve all of this. What version have you tested this with? |
It doesn't act the same though... when I just call |
@joshterrill Very peculiar, I just downloaded the last 0.15.3 sdk version and tried the exact code you provided and I am getting the old behavior :( |
@joshterrill For some reason I don't, I just downloaded a new Can you share your package.json file? Thanks! |
Unfortunately the pdf viewer is opened in new process, so accessing the nw.Window object from the main process is not working. Will look to fix this. |
@rogerwang Thank you, this will be amazing when it's added.. Let me know if you need any help with it, I am happy to assist in anyway I can ( Testing, etc. ) @joshterrill Thank you for your effort as well. |
This is fixed in git and will be available in the next nightly build. |
Hi @rogerwang I just downloaded the latest build and tested my code, and it is working flawlessly. Thank you very much for your amazing speed and support! |
Is there a way to catch the callback, after sending the print job to the printer, to close the PDF Print preview page , or better print a PDF file silently ?
|
@jasminmif win.print({}) is a sync function win.close() will always happen after the job is sent to the printer in theory but sometimes not... if you want to be sure you can do something like this.
the setTimeout will put the win.close() to the begining of the next call stack after the win.print is finished + 100 ms. |
@jasminmif Try this
|
Hi guys. Printing works, but (in same context) Thanks. |
Maybe you already figured it out by yourself, but I hope it may help others as well. I ran over this problem myself and solved it.
Now that you should be able to see something, it should be clear how to access the printer information.
|
Hi everyone,
I was wondering why the PDF viewer doesn't have access to the node context, I was trying to find a way to use the custom print feature however after testing it appears this extension doesn't have access to the node context.
I tried using "node-remote": "chrome-extension:///" but it said that it is an invalid scheme.
Is there anyway around this?
Thanks!
The text was updated successfully, but these errors were encountered: