Created attachment 37883 [details] Example script demonstrating the issue with file objects Documentation of pycairo says that PDFSurface accepts as an argument a string or writable file object, but with file objects it doesn't work in all cases. The same is the case for write_to_png(). It works on Linux, but on Windows it doesn't always work. I get blank PDF page on Windows if I pass file object, but the file is not empty. If I pass filename as string then it works. If I pass filename as Python Unicode string on Linux, I get segmentation fault.. the string has to be encoded. I'm using it like this: f = open(filename, 'w') surf = cairo.PDFSurface(f, w, h) ... I have installed pycairo 1.8.6 for Python 2.6 (from ftp.gnome.org) and using Cairo DLLs from the gtk+ bundle 2.20: http://www.gtk.org/download-windows.html The same thing happens on XP and Vista.
Created attachment 37884 [details] Example output file on Windows
Created attachment 37885 [details] Example output file on Linux
pycairo 1.8.10 is the current version - try this version and see if the problems are still there. Could you provide a test case for the Linux segmentation fault. For PDFSurface, write_to_png() (and nearly all other functions) pycairo uses the same code for Linux and Windows. So if something works in Linux and not Windows its unlikely to be a problem in pycairo, and more likely a problem in the specific Windows code in the cairo C library. Try surface.flush() surface.finish() f.close() in that order (flush before finish) - does that work? Which combinations of the 3 work, and do not work?
Created attachment 38680 [details] segmentation fault under Linux
(In reply to comment #3) > pycairo 1.8.10 is the current version - try this version and see if the > problems are still there. I'll try to build and test that, but building it on Win is a pain. > Could you provide a test case for the Linux segmentation fault. This problem is still present in 1.8.10. > For PDFSurface, write_to_png() (and nearly all other functions) pycairo uses > the same code for Linux and Windows. So if something works in Linux and not > Windows its unlikely to be a problem in pycairo, and more likely a problem in > the specific Windows code in the cairo C library. > > Try > surface.flush() > surface.finish() > f.close() > in that order (flush before finish) - does that work? > Which combinations of the 3 work, and do not work? None of the combinations work.
The problem with unicode filenames has been fixed, and changes applied to the git repo. For the Windows problem, use f = open("example.pdf","wb") # write in binary mode
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.