Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-11-05 05:34:52

skewray
Member
From: Sunny Southern California
Registered: 2013-04-25
Posts: 143
Website

Embedded .pdf articles

I would like to have an article in pdf format display as a textpattern article. In other words, the native pdf viewer of the user’s browser displays the pdf file with the textpattern frame surrounding it. Is this possible?

Last edited by skewray (2015-11-05 05:39:15)

Offline

#2 2015-11-05 07:53:23

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: Embedded .pdf articles

There are various ways to do that:

You can use the HTML object tag as described here (see the source code of this demo to see how it is constrained within an element within the page).

<object data="http://domain.com/files/myfile.pdf" type="application/pdf" width="600px" height="500px">

  <p>It appears you don't have a PDF plugin for this browser.
     No biggie... you can <a href="http://domain.com/files/myfile.pdf">click here to download the PDF file.</a></p>

</object>

That example from that page also includes a manual download link for the pdf as fallback in case the visitor doesn’t have a pdf viewer installed.

You can also catch this instance using something like the PDFobject javascript script.

Other options:

You could use google’s doc viewer in an iframe – you can see an example here:

<iframe src="https://docs.google.com/viewer?url=http://domain.com/files/myfile.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>

The viewer is quite powerful and handles other file types, including I believe powerpoint etc.

You could upload your pdfs to a service like issuu.com and then embed their own in-built embeddable viewer. That gives you pdfs that can be flicked through in the page and zoomed to full-screen for reading (Example).

If you have a standard layout in your textpattern site, e.g. you know that the pdf will always appear ahead of the body copy, you can use a custom field to hold the ID number of the file you want to embed if you’ve uploaded them to textpattern or the link to the file if the pdf is located elsewhere and then include one of the above code options in your page template or single article form.

If you want to embed a pdf file somewhere in the middle of your body copy, you can include the embed code from one of the options on a separate line – I’d suggest a blank line above, a blank line below and then to start the code line with a space (that prevents it being treated as a normal paragraph). If that’s going to be a common occurrence that may be too prone to error for the site editors, you can make that tidier by using smd_macro to make a macro with the embed code, and then you use your macro’s simplified code in the body field, e.g.  <txp:pdf_embed file="123" /> which calls the macro and generates the embed code. An advantage here is that you can change your embed method at a later date by editing the macro.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2015-11-05 15:56:16

skewray
Member
From: Sunny Southern California
Registered: 2013-04-25
Posts: 143
Website

Re: Embedded .pdf articles

Very nice! Thank you. I’ve been writing articles in LibreOffice with a lot of equations and then hand-converting the result to HTML with a link to the pdf’s. Any other method I’ve found results in really bad-looking equations. The burden of effort required just discourages me from posting at all. On the other hand, posting just the pdf’s will be easy.

Offline

#4 2015-11-05 16:34:21

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Embedded .pdf articles

I used to use Scribd for that sort of thing – like option 4 here – but I am glad to see some better methods are available for that sort of thing.

Offline

#5 2015-11-05 17:50:02

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,137
GitHub

Re: Embedded .pdf articles

skewray wrote #296444:

I’ve been writing articles in LibreOffice with a lot of equations and then hand-converting the result to HTML with a link to the pdf’s.

With the risk of making a new rabbit hole for you to disappear down, have you tried MathJax for size?

Offline

Board footer

Powered by FluxBB