Skip to content
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

Sometimes a printable area is sent to print before styles have loaded. #7

Closed
MikeSha opened this issue Mar 29, 2018 · 14 comments
Closed

Comments

@MikeSha
Copy link
Contributor

MikeSha commented Mar 29, 2018

It happens when copyStyles set to true. I have an idea how to fix it. I'll try it when I have a free time and I'll make a merge request.
I think loading styles should be "promisified". When all styles is loaded, then target.print() should be called. Sorry for my English, I hope you understand what I mean :)

@gregnb
Copy link
Collaborator

gregnb commented Mar 29, 2018

Mike, your English is fine. I understand. It's weird that not all the styles are coming over considering that it's copying style sheets from a parent window that should have already downloaded them and been cached in the browser. Do you maybe have caching disabled?

Could you walk me though the steps you take to trigger the bug? Is it consistent?

@MikeSha
Copy link
Contributor Author

MikeSha commented Mar 29, 2018

Sure. I'll do it a little bit later.

@MikeSha
Copy link
Contributor Author

MikeSha commented Mar 30, 2018

Sorry for the delay, a lot of work :) Yes, I have caching enabled and I do everything like in the documentation. On my localhost it works fine. But when I'm trying to print on server, I get this issue. I know, it's a little bit weird :) It could be fixed by increasing timeout. But I think it's better to wait all styles loading.

@gregnb
Copy link
Collaborator

gregnb commented Mar 30, 2018

Yeah it's still an odd issue I haven't had time myself to test this out more. I'll try to get around to it. It can't hurt to see an implementation with it being promisfied if you still want to complete that

@MikeSha
Copy link
Contributor Author

MikeSha commented Mar 30, 2018

Sure!

@gregnb
Copy link
Collaborator

gregnb commented Apr 1, 2018

I think I have an easier way to solve this problem. In the latest version I added onload/onerror callbacks on copied stylesheets so once they're triggered we will know that they are loaded in the print window and only then do we trigger print.

If that doesn't solve the issue I'll reopen this

@gregnb gregnb closed this as completed Apr 1, 2018
@thamjieying
Copy link

Hi, I have been using the library to try to generate some pdf. It's a great and easy way to use the library by only using html and css to style the invoice, and it works great on localhost. However, when i use it on production, the style always fails to load on the first attempt to print the file. The print window still pops up before the style loads, or rather the style does not load at all. If i close the window and try a second time the style will load properly after waiting for a while. (sometimes the print window does not even pops up after the style is loaded).

@gregnb
Copy link
Collaborator

gregnb commented Apr 23, 2018

@thamjieying could you share your environment details with us? OS, node version, etc

@thamjieying
Copy link

I am using this library on the client side using react, and nodejs v8.7.0 as the server. I am developing using macOS. Does these affect the performance?

@gregnb
Copy link
Collaborator

gregnb commented Apr 23, 2018

No, just trying to understand what your environment is. Which browser are you using? If you try different browsers do you still have issues?

@thamjieying
Copy link

I have tried on mac with chrome, firefox, Opera and safari,
and windows on chrome firefox, Opera and edge.

the browser on mac always fails on the first attempt to download, as i have described,
on pc, chrome has the same problem, firefox rendered correctly on screen but style is never transferred to the downloaded pdf. Only opera and edge works fine on windows.

@gregnb
Copy link
Collaborator

gregnb commented Apr 23, 2018

I'm not seeing an issue @thamjieying look at this example here where I pull in a completely foreign CSS file from w3c schools: https://3vqww5xo0m.codesandbox.io/#

Do you see the styling come over?

@thamjieying
Copy link

@gregnb I tried yours and it worked fine. I don't know what's wrong with mine. maybe the style fine is too big? Thanks for the prompt reply. I might try another library if the problem still persist.

@codeslayer1
Copy link

@thamjieying Hey. Were you able to solve the issue. I am also facing the same issue. The styles are not loaded the first time print window opens. On subsequent opens, the styles get loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants