MoinMoin EmbedObject macro patch for PDF scaling

MoinMoin wiki offers a default macro for embedding objects, like video, audio or pdfs etc. into a wiki page using HTML raw markup: the <object> node. For different types you can change parameter values in the output, most important the height and width of the embedding canvas. But Adobe Acrobat(r) offers also an object attribute to set the initial scaling of the document displayed, called zoom.

In order to add this attribute to the EmbedObject macro (resides in the macro directory of MoinMoin, like <moin-install-dir>/MoinMoin/macro/ for PDF embedding follow this steps:

  1. Add the zoom parameter (green highlighted) to the macro_EmbedObject function definition:
    def macro_EmbedObject(macro, target=wikiutil.required_arg(unicode), pagename=None,
        width=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
        height=wikiutil.UnitArgument(None, float, ['px', 'em', 'pt', 'in', 'mm', '%'], defaultunit='px'),
        play=False, stop=True, loop=False, quality=(u'high', u'low', u'medium'),
        op=True, repeat=False, autostart=False, align=(u'middle', u'top', u'bottom'), hidden=False,
        menu=True, wmode=u'transparent', url_mimetype=None):
  2. Extend the the application type handling section with the two green highlighted lines (in MoinMoin 1.9 it’s around line 197):
    elif mt.major == 'application':
        # workaround for the acroread browser plugin not knowing the size to embed
         # we use a width of 100% for the case that there is no width given.
         # A height of 100% gives a fullscreen pdf file view without embedding it into the wikicontent.
         if mt.minor == 'pdf':
             width = width or '100%'
             height = height or '800px'
             zoom = zoom or '100'
             embed_src = '''
    <object %(ob_data)s %(ob_type)s %(ob_width)s %(ob_height)s %(ob_align)s %(ob_zoom)s>
    </object>''' % {
     "ob_data": _check_object_value("data", url),
     "ob_width": _check_object_value("width", width),
     "ob_height": _check_object_value("height", height),
     "ob_type": _check_object_value("type", mime_type),
     "ob_align": _check_object_value("align", align),
     "ob_zoom": _check_object_value("zoom", zoom),
     "alt": wikiutil.escape(alt),

That’s it. Please note that the zoom scaling attribute is only used by the Acrobat browser plugin. Safari’s included PDF viewing support ignores this attribute. If you know of another PDF viewer which interprets the zoom value to, feel free to leave a comment.

Einen Kommentar hinterlassen

Ihre E-Mail wird niemals veröffentlicht oder weitergegeben. Erforderliche Felder sind mit * markiert

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Ich stimme der Datenschutzerklärung zu

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.