Give this a try:
\procedure object(src, width:"100%", height:"100%",params,fallback:"cannot load <<src>>")
<$let type={{{ [<src>get[type]] }}}
pre={{{ [[data:]] [<type>] [[;base64,]] +[join[]] }}}
uri={{{ [<src>get[_canonical_uri]] ~[<src>get[text]addprefix<pre>] ~[<src>prefix[http]] }}}>
<% if [<uri>!match[]] %>
<object data={{{ [<uri>addsuffix<params>] }}} type={{{ [<src>get[type]] }}}
style.width=<<width>> style.height=<<height>>>
<<fallback>>
</object>
<%else%>
<<fallback>>
<%endif%>
</$let>
\end
Usage:
<<object src:"test.pdf" height:"50vh">>
Notes:
- This procedure can handle ANY type of embeddable object, not just PDFs
-
src
can be any of the following:- the title of a tiddler containing a
_canonical_uri
field - the title of a tiddler containing embedded base64-encoded binary data
- an external URL starting with
http://
orhttps://
- the title of a tiddler containing a
-
height
andwidth
are specified using CSS units -
params
are optional. Useparams:"#toolbar=0&scrollbar=0"
to hide the PDF toolbar and scrollbar controls -
fallback
can be any wiki content you want displayed if the embed fails to load- You could use this to specify a secondary
<<embed ...>>
macro to display a fallback PDF
- You could use this to specify a secondary
How it works:
- get the tiddler’s
type
field (if any) - construct a prefix (e.g.,
data:application/pdf,base64,
) to use if the tiddler contains embedded base64-encoded binary data. - get the uri which is either a
_canonical_uri
field value or the tiddler’s base64-encoded content (with the added prefix), or a direct external reference to a URL - if a URI was retrieved, append the params and embed it. If the embed fails to load, show the fallback content.
- if a URI was not retrieved, just show the fallback content.
This might not be a 100% perfect solution, but it should handle most use-cases.
Let me now how it goes…
enjoy,
-e