-
-
Notifications
You must be signed in to change notification settings - Fork 704
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
Error rendering file using windows executable #2230
Comments
Hi! I’ve never seen this error on my Windows VM or on CI. Is that a fresh Windows install on a server, or on a laptop? Looks like there’s something wrong with fonts. Do you have fonts installed on your Windows system, and can your user reach them? |
Hi, I am using WinDev2407Eval on VirtualBox. Other applications are able to use fonts without any issue. For ex: I am able to use fonts in WordPad. Is there any test I can do ? |
I’ll try the VM on my computer. |
I think I have figured out the cause of the error. I have in my path variable set the path to a build of GTK with Pango build without fontconfig & pangoft2 support. Once this path is removed, the errors are not shown and the pdf is generated fine. It seems weasyprint.exe is using the external pango libraries when available in path. |
I also tested this on a different system with an older build of GTK which had Pango build with support for both libraries. The error is not displayed and pdf is generated fine in this case. But when I delete the dlls for fontconfig and pangoft2, the same error is reproduced. |
Since Python 3.8, Python doesn’t search libraries in the Are you sure that removing GTK from |
I have the build of Gtk including Pango and fontconfig setup at Once this location is deleted from |
Please see screencast. |
Thanks for the screencast. Your GTK install is not even in the default install path, the problem doesn’t come from this: WeasyPrint/weasyprint/text/ffi.py Lines 474 to 481 in f17bd4b
I just don’t understand what’s going on. Many users complained that with Python 3.8+, setting the To be honest, we’ve already spent so many days trying to provide a simple way to get WeasyPrint working on Windows that it’s becoming ridiculous. Nobody knows how DLL loading works on Windows, and we have random different behaviors on systems that are supposed to be the same. If you (or anyone else) wants to spend some time understanding what exactly happens here, and then provide a PR to fix this, I’ll be happy to merge it. But otherwise, I’ll just close this issue and let users tweak their install paths and environment variables until it works. At least we now know that having GTK installed in a folder set in the |
Hi, I did some troubleshooting and I think I have figured out the source of the issue. Error seems to be related to the order of libraries listed here. WeasyPrint/weasyprint/text/ffi.py Lines 483 to 502 in f17bd4b
The WeasyPrint/weasyprint/text/ffi.py Lines 456 to 458 in f17bd4b
Since the libraries, copied by The error could be resolved by changing the order of names for modules to give preference to the libraries packaged by
Reference: |
I did a build using |
Thanks A LOT for this information. I understand why changing the order works, and that we should reference the name as used by MSYS before other names (used by GTK for example).
That’s the last thing I don’t understand. Windows searches DLL files in |
I think it is to do with the flags passed to
Values for the flag are listed here https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa For the
WeasyPrint/weasyprint/text/ffi.py Line 458 in f17bd4b
Modifying the above line as follows to include the flag should limit the dll search to the given library locations.
|
Without modifying the library order with the above fix alone, I did a build using PS: The above code modification will have to be limited to Windows. |
WeasyPrint 62.3’s executable has been built with cffi 1.16, so that’s probably unrelated to your original problem. Moreover, from what I can understand, the behavior only changed when filenames contain a slash or a backslash, but that’s not our case.
Well, it may work, thanks a lot for the hint, I’ll try. I suppose that it requires cffi 1.17, but that the flags are just discarded for older versions, so we don’t care. And if anybody reports a problem with that, I’ll burn all the Windows DVDs of the world until Bill Gates comes and finds a solution himself. |
The https://github.com/python-cffi/cffi/blob/release-1.17/src/c/misc_win32.h#L194-L205 From
For cffi v1.16, the https://github.com/python-cffi/cffi/blob/release-1.16/src/c/misc_win32.h#L194-L197 When |
I’ve open #2238, could you please check that everything’s OK for you? |
Changes seem OK to me. I think it may also be better to change the order of libraries to give preference to the pyinstaller bundled libraries. Especially since following locations are hardcoded, and in future there is no guarantee that they ship compatible builds. 'C:\Program Files\GTK3-Runtime Win64\bin;' |
Done! |
Let’s merge it! Thanks a lot for your time and your advice. |
OS: Windows 11
WeasyPrint: v62.3
When rendering an html file with or without css using
weasyprint.exe
, following repeated error messages are displayed and the rendered pdf has no font characters displayed..\weasyprint.exe .\report.html out.pdf -s .\report.css -v
report.zip
The html file displays fine in web browser and renders alright while using weasyprint python API under Linux (Ubuntu 24.04 with latest weasyprint)
The text was updated successfully, but these errors were encountered: