{"action":"closed","issue":{"url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/119","labels_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/119/comments","events_url":"https://api.github.com/repos/Kozea/WeasyPrint/issues/119/events","html_url":"https://github.com/Kozea/WeasyPrint/issues/119","id":18519839,"number":119,"title":"Gtk introspection error with weasyprint using Gtk.PrintOperation","user":{"login":"BobBowles","id":5305570,"avatar_url":"https://avatars.githubusercontent.com/u/5305570?v=3","gravatar_id":"","url":"https://api.github.com/users/BobBowles","html_url":"https://github.com/BobBowles","followers_url":"https://api.github.com/users/BobBowles/followers","following_url":"https://api.github.com/users/BobBowles/following{/other_user}","gists_url":"https://api.github.com/users/BobBowles/gists{/gist_id}","starred_url":"https://api.github.com/users/BobBowles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BobBowles/subscriptions","organizations_url":"https://api.github.com/users/BobBowles/orgs","repos_url":"https://api.github.com/users/BobBowles/repos","events_url":"https://api.github.com/users/BobBowles/events{/privacy}","received_events_url":"https://api.github.com/users/BobBowles/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2013-08-25T11:40:19Z","updated_at":"2015-04-25T18:19:14Z","closed_at":"2015-04-25T18:19:14Z","body":"Running the following script in Python3 generates an error traceback when introspecting the print context while rendering the page:\r\n\r\n    #!/usr/bin/env python3 \r\n\r\n    import os\r\n    from gi.repository import Gtk\r\n    from weasyprint import HTML\r\n\r\n    testFile = os.path.join(os.getcwd(), 'printTestHtml.html')\r\n    pdfDocument = HTML(filename=testFile).render()\r\n\r\n    class Example(Gtk.Window):\r\n\r\n        def __init__(self):\r\n            super(Example, self).__init__()        \r\n            self.init_ui()\r\n            \r\n        def init_ui(self):    \r\n            self.set_title(\"Print Html Weasyprint Test\")\r\n            self.resize(230, 150)\r\n            self.set_position(Gtk.WindowPosition.CENTER)\r\n            self.connect(\"delete-event\", Gtk.main_quit)\r\n            \r\n            printButton = Gtk.Button('Press Me')\r\n            self.add(printButton)\r\n            printButton.connect('clicked', self.on_printButton_clicked)\r\n\r\n            self.show_all()\r\n\r\n        def on_printButton_clicked(self, widget):\r\n            printOperation = Gtk.PrintOperation()\r\n            printOperation.connect('begin-print', self.on_printOperation_begin_print)\r\n            printOperation.connect('draw-page', self.on_printOperation_draw_page)\r\n            printOperation.set_job_name('Print HTML Weasyprint Test')\r\n            printOperation.set_n_pages(len(pdfDocument.pages))\r\n            printOperation.run(Gtk.PrintOperationAction.PRINT_DIALOG,\r\n                               parent=self)\r\n            \r\n        def on_printOperation_begin_print(self, printOperation, context):\r\n    #        printOperation.set_n_pages(len(self.pdfDocument.pages))\r\n            pass\r\n\r\n        def on_printOperation_draw_page(self, printOperation, context, pageNo):\r\n            cr = context.get_cairo_context()\r\n            page = pdfDocument.pages[pageNo]\r\n            page.paint(cr)\r\n\r\n    def main():\r\n        \r\n        app = Example()\r\n        Gtk.main()\r\n                        \r\n    if __name__ == \"__main__\":    \r\n        main()\r\n\r\n\r\nThe error in the terminal window is as follows:\r\n\r\n    Traceback (most recent call last):\r\n      File \"printTestHtmlWeasyprint.py\", line 42, in on_printOperation_draw_page\r\n        cr = context.get_cairo_context()\r\n      File \"/usr/lib/python3/dist-packages/gi/types.py\", line 43, in function\r\n        return info.invoke(*args, **kwargs)\r\n    TypeError: Couldn't find conversion for foreign struct 'cairo.Context'\r\n\r\n\r\nThe error does not happen if the html is pre-processed into pdf and handled via Poppler, nor does it happen when the html rendering is handled via WebKit, as in this example:\r\n\r\n    #!/usr/bin/env python3 \r\n\r\n    import os\r\n    from gi.repository import Gtk, WebKit\r\n\r\n    testFile = 'file://' + os.path.join(os.getcwd(), 'printTestHtml.html')\r\n\r\n    class Example(Gtk.Window):\r\n\r\n        def __init__(self):\r\n            super(Example, self).__init__()        \r\n            self.init_ui()\r\n            \r\n        def init_ui(self):    \r\n            self.set_title(\"Print Html WebKit Test\")\r\n            self.resize(230, 150)\r\n            self.set_position(Gtk.WindowPosition.CENTER)\r\n            self.connect(\"delete-event\", Gtk.main_quit)\r\n            \r\n            printButton = Gtk.Button('Press Me')\r\n            self.add(printButton)\r\n            printButton.connect('clicked', self.on_printButton_clicked)\r\n\r\n            self.show_all()\r\n\r\n        def on_printButton_clicked(self, widget):\r\n            webView = WebKit.WebView()\r\n            webView.load_uri(testFile)\r\n            webFrame = webView.get_main_frame()\r\n            webFrame.print_full(Gtk.PrintOperation(),\r\n                                Gtk.PrintOperationAction.PRINT_DIALOG)\r\n\r\n    def main():    \r\n        app = Example()\r\n        Gtk.main()\r\n                        \r\n    if __name__ == \"__main__\":    \r\n        main()\r\n"}}