Open tiddler containing pdf (canonical_uri) at specific page? aka. Passing info to opening tiddler

Hi there,

I try to link to a tiddler containing an external pdf-file which should open on a specific page.
This would work fine with the embed tag, by appending ‘#page=’.
Is there any way, to pass information to a tiddler on opening? I couldn’t spot anything like that.

Thanks a lot.

You can embed the pdf with an object tag (or an iframe) :

Open pdf : <$edit-text field="pdf-url"/>
Open at page : <$edit-text field="pdf-page"/>

<object type="application/pdf"
    data={{{ [{!!pdf-url}] [[#page=]] [{!!pdf-page}] +[join[]]}}}
    width="100%"
    style="height:calc(100vh - 60px)">
</object>

https://demos.tiddlyhost.com/#Open%20a%20pdf%20at%20a%20specific%20page

EDIT: My bad, I didn’t see that you wanted a link. This is the same principle but with an a tag :

<a href={{{ [{!!pdf-url}] [[#page=]] [{!!pdf-page}] +[join[]]}}}>link to the pdf</a>

You can also create a macro, in a tiddler with the tag $:/tags/Macro/View :

\define pdf-link(url,page,text:"link to the pdf")
<a href="$url$#page=$page$">$text$</a>
\end

Then you can insert a link to a pdf like this

<<pdf-link "https://www.scoilnet.ie/uploads/resources/35767/35535.pdf" "3">>

2 Likes

@telumire Thanks.

I think the macro helped. Even so it wasn’t exactly what I was looking for.

But seems I haven’t been clear enough.
I have a tiddler with the _canonical_uri. If I link to it in WikiText normally, then it opens a tiddler with the pdf file embedded.

I was looking for a possibility to set the page this tiddler opens the pdf. Like the attributes in the image tags.

The nearest I got there was using a separate tiddler, which has two fields:
pdf and page and the following content:

\define pdfpage() $(pdf)$#page=$(page)$

<$set name="pdf" filter="[get[pdf]get[_canonical_uri]]">
<$set name="page" value={{!!page}}>
<embed src=<<pdfpage>> class="w-100" style="height: 600px;"/>
</$set>
</$set>

And a button on other toddlers to set the page and open the tiddler.

But I still need an additional tiddler, that was something I would like to avoid. On the other hand it is something I could life with.

You could edit the _canonical_uri url with a button with the appearance of a link that open it, e.g :

In a tiddler with the tag $:/tags/Macro/View

\define open-pdf(tiddler,page)
<$tiddler tiddler=<<__tiddler__>>>
<$button class="tc-tiddlylink tc-tiddlylink-resolves" tag="a" set="!!_canonical_uri" setTo={{{ [{!!_canonical_uri}split[#page=]first[]] [[#page=]] [<__page__>] +[join[]] }}} actions="<$action-navigate/>">
Open "{{!!title}}" to page $page$
</$button>
</$tiddler>
\end

<<open-pdf tiddler:"pdf" page:"4">>

Demo

If you want your pdfs to reset at startup then you could add a startup action. In a tiddler with the tag $:/tags/StartupAction :

<$list filter="[type[application/pdf]search:_canonical_uri[#page=]]">

<$action-setfield _canonical_uri={{{ [{!!_canonical_uri}split[#page=]first[]] }}}/>

</$list>

Make a backup of your wiki before trying this !

2 Likes

Thank you again, @telumire. Works like charm!

And I have my wiki in git repository which automatically commits and syncs my changes :slight_smile:

1 Like