balbarak / WeasyPrint-netcore

WeasyPrint Wrapper for .Net on Windows
BSD 3-Clause "New" or "Revised" License
71 stars 19 forks source link

JPG files are not supported #3

Closed lost-RD closed 4 years ago

lost-RD commented 5 years ago

The reason given by OnDataError is (Pixbuf error: Unrecognized image file format) so I took a look into the included files and there was a gdk-pixbuf-query-loaders.exe in the gtk3 folder that instructed me that it would look in gtk3\lib\gdk-pixbuf-2.0\2.10.0\loaders\ for loaders. That directory structure didn't exist so I created it and pulled the loaders from https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/tree/master/gtk-nsis-pack/lib/gdk-pixbuf-2.0/2.10.0/loaders and tried the exe again, this time with better results:

# GdkPixbuf Image Loader Modules file
# Automatically generated file, do not edit
# Created by gdk-pixbuf-query-loaders.exe from gdk-pixbuf-2.38.0
#
# LoaderDir = C:\Users\lost\source\repos\PDFGenFromTemplate\PDFGenFromTemplat
e\bin\Debug\weasyprint-v48\gtk3\lib\gdk-pixbuf-2.0\2.10.0\loaders
#

*snip*

"bin\\Debug\\weasyprint-v48\\gtk3\\lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixb
ufloader-jpeg.dll"
"jpeg" 5 "gdk-pixbuf" "JPEG" "LGPL"
"image/jpeg" ""
"jpeg" "jpe" "jpg" ""
"\377\330" "" 100

*snip*

However, even with the loader that should allow gdk-pixbuf to load a JPG into memory, WeasyPrint still gives me the same error.

Next I tried using the command line in the same manner as you do (I had a poke around in your code using dnSpy):

python.exe weasyprint.exe input.html output.pdf -e utf8

And to my surprise, but not really, the pdf rendered perfectly, JPGs and all. I'm on the right track!

Next step was to see if the issue was in the Path so I modified your code to print the Path when I call GeneratePdf. Nothing showed up in the output. Seems I don't know as much as I think I do. Over to you.

lost-RD commented 5 years ago

I did manage to fix the issue by commenting out the line in WeasyPrintClient.InitProcess that added gtk3 to the front of PATH. Now my own installation of GTK+ 3.0 is doing the heavy lifting.

balbarak commented 5 years ago

Thanks for your comments.

It is seems the gtk3 library that comes with the lib is missing some files, we will investigate the issue

Thanks

P-de-Jong commented 4 years ago

Any update on this? :)

balbarak commented 4 years ago

Now GTK3 has been update in version 2, hope it solves your problem

Kindly, let me know the issue exist

Thanks

P-de-Jong commented 4 years ago

@balbarak Great! I will test it and let you know if it works now 👍

P-de-Jong commented 4 years ago

@balbarak With today's merged PR it seems to work great! So when that's released, it should be all good.

Thanks!

balbarak commented 4 years ago

Pushed to nuget v2.0.1

Thanks