Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
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
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
Offline
Pages: 1