[Bugs] #2833 UNSP: add support for PDF export (was: Browse must be save a page to PDF for offline reading.)
Sugar Labs Bugs
bugtracker-noreply at sugarlabs.org
Sat May 21 07:28:08 EDT 2011
#2833: add support for PDF export
------------------------------------------+---------------------------------
Reporter: godiard | Owner: lucian
Type: enhancement | Status: new
Priority: Unspecified by Maintainer | Milestone: Unspecified by Release Team
Component: Browse | Version: Git as of bugdate
Severity: Unspecified | Keywords:
Distribution: | Status_field: New
------------------------------------------+---------------------------------
Changes (by sascha_silbe):
* distribution: Unspecified =>
* version: Unspecified => Git as of bugdate
* status_field: Unconfirmed => New
Comment:
For reading web pages offline there are other, potentially better
solutions (e.g. Lucians [http://wiki.sugarlabs.org/go/Webified Webified]
work, wwwoffle). Nevertheless I took a stab at implementing PDF support.
This is the code I added to {{{browser.Browser}}}:
{{{
def export_pdf(self):
cls = components.classes['@mozilla.org/gfx/printsettings-
service;1']
setting_service =
cls.getService(interfaces.nsIPrintSettingsService)
req =
self.get_dom_window().QueryInterface(interfaces.nsIInterfaceRequestor)
print_iface = req.getInterface(interfaces.nsIWebBrowserPrint)
temp_dir = os.path.join(activity.get_activity_root(), 'instance')
pdf_file = tempfile.NamedTemporaryFile(suffix='.pdf',
dir=temp_dir,
delete=False)
settings = setting_service.newPrintSettings
settings.printSilent = True
settings.printToFile = True
settings.toFileName = pdf_file.name
settings.outputFormat =
interfaces.nsIPrintSettings.kOutputFormatPDF
# print_iface.print(printSettings, None)
getattr(print_iface, 'print')(printSettings, None)
}}}
It fails with the following error:
{{{
Traceback (most recent call last):
File "/home/sascha.silbe/sugar-
jhbuild/install/share/sugar/activities/Browse.activity/webtoolbar.py",
line 494, in _export_pdf_cb
browser.export_pdf()
File "/home/sascha.silbe/sugar-
jhbuild/install/share/sugar/activities/Browse.activity/browser.py", line
320, in export_pdf
logging.debug('print: %r', getattr(print_iface, 'print'))
File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 374,
in __getattr__
return getattr(interface, attr)
File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 466,
in __getattr__
unbound_method = BuildMethod(method_info, self._iid_)
File "/usr/lib/pymodules/python2.6/xpcom/client/__init__.py", line 125,
in BuildMethod
codeObject = compile(method_code, "<XPCOMObject method '%s'>" %
(name,), "exec")
File "<XPCOMObject method 'print'>", line 2
def print(self, Param1, Param2):
^
SyntaxError: invalid syntax
}}}
The problem is that {{{print}}} is a reserved keyword in Python 2. XPCOM
would need to rename {{{print}}} to something else, e.g. {{{print_}}}. I'm
not sure how feasible it is to get that fix rolled out to the
distributions that still ship a python-xpcom we can use in the first place
(Ubuntu doesn't ship it at all and recent versions of Fedora are
[ticket:2772 broken], too).
--
Ticket URL: <http://bugs.sugarlabs.org/ticket/2833#comment:4>
Sugar Labs <http://sugarlabs.org/>
Sugar Labs bug tracking system
More information about the Bugs
mailing list