PDF embed - shortcode showing instead of PDF file on published page

Three years ago, I switched all my sites to WordPress. However, since I am not pleased at all with the move toward Gutenberg, I am now looking at other options for future sites - or possibly future migrations of existing sites.

I have started testing Grav, and I am quite impressed. I am testing it on localhost (MAMP, I am on Mac). Since I need to have the ability to embed a PDF in some of my posts, I have just installed and tested the PDF-JS plugin. I have installed it as instructed, and copied user/plugins/pdf-js/pdf-js.yaml to user/config/plugins/pdf-js.yaml - settings are correct, i.e. enabled: true and height: 300.

I have uploaded the PDF I want to insert in my test page to the media section of that page. It is there, if I click on it I can see it.

However, when I insert the shortcode on my page: [pdfjs file=2018-2019-MUCIVI-conferences.pdf/], or [pdfjs=2018-2019-MUCIVI-conferences.pdf/], I can only see the shortcode on my published page, the PDF itself does not show.

Pretty sure I am missing something here, since I am not yet familiar with Grav, but what? What should I do in order to have the PDF show on the page, and not merely the shortcode?

I thank you in advance for any information.

Unfortunately I do not use OSX so I can hardly understand what the problem may be.

But I would be very sorry if you do not use Grav, this fantastic CMS, just because you do not have the ability to embed pdf files through the library pdf.js

So I updated the plugin and added the PDFObject library or the two html tags: embed and object. There are four options that can be used alternatively

I hope something works and you can get excited about Grav.

Just out of curiosity.

My plugin needs the Shortcode Core plugin that you will have surely installed because it is a requirement.

Could you try to put a quick example of a shortcode on a page?
For example

[color=blue]blue text[/color]
1 Like

Many thanks for your kind answer and your efforts to help.

Indeed, I had not realized that the plugin would need Shortcode Core in order to work. Now I have installed it (as well as the two other required plugins), and your plugin is working indeed. I had started using Grav for the first time yesterday, this explains why I had overlooked that.

I have also been able to resize the PDF embed in config.

It is really a nice tool!

Three small things:

  1. I have noticed that the PDFs does not show in Firefox (v. 63.03.4). I first assumed that this had to do with my Firefox settings, but embedded PDFs on my WordPress sites show, thus this must have something to do either with Grav or with the plugin. The embedded PDF shows fine on Safari and Chrome.

  2. With PDF Embedder on WP, the PDF area is responsive. This does not seem to be the case with the PDF-JS plugin.

  3. On your demo page (http://iusvar.alwaysdata.net/grav/en/blog/pdfjs), the PDF area has a nice toolbar on the top. The same is the case with my embedded PDFs on WordPress. However, on my local test site, the toolbar does not show. Is this because it is on my local machine?

Anyway, I agree with you: Grav looks indeed like a remarkable CMS. I have two small sites that I had intended to move to WP (two of my last three sites that are not yet on WP), and I am now wondering if I will not rather move them to Grav.

The fact of having not only a nice CMS, but also developers eager to provide useful plugins and a supportive form, is also something encouraging. Plus the obvious fact that Grav will continue to develop and improve.

Two things that would prevent me - at this point - from considering to move larger sites to Grav (apart from the fact that it would mean a lot of work: redesigning and moving several sites with hundreds of long articles to WP took me months of work!):

  1. There seems to be no plugin for managing redirections; for existing sites with a long history, it is necessary to have good tools for the management of redirections (since some URLs change with amove to another CMS), something which is available with WP (e.g. the excellent Redirection plugin).

  2. Also missing for the time being is a typography plugin (something like Wp Typography for WP): most of my sites is in French, and a typography plugin is useful for making sure that the specific rules of French typography (small space before some typographical signs, etc,) are enforced.

But I assume that additional plugins will come over time, since Grav is still young, and that such plugins might be available in a not too far future.

In the meantine, I thank you once again for your helpfulness, something which gives me a pleasant impression on my first day of testing Grav.

I answer the three little things.

  1. I always try my plugins with Google Chromium and Firefox Developer Edition 64.0b12 and, in the case of the pdf-js plugin, I see no differences either online or locally, they work in the same way. I also see the result that I expect, Chrome and Firefox, on a smartphone and a tablet.

  2. Until the previous version the pdf took up all the available width in the chosen position while I imposed a limit on the height and therefore everything was reponsive. In fact with this version (0.2.0) I also impose the width: I could go back on my steps in effect … I will investigate.

  3. As I said in answer 1, I do not find differences between local and online, the bar shows itself. Can you show me a savescreen?

For the two following considerations, I do not feel able to give adequate answers. When I met Grav I was ecstatic, it is a light system thanks to the management through flat files but powerful and above all very fast, quite simple to program, being able to choose the environment on which to intervene (PHP, Twig, YAML or other). Initially I made the plugins because I needed them, then I made them available because they could probably be useful and I can improve them according to the user’s recommendations. Unfortunately, but this applies only to me, I am limited to the Ubuntu environment only.

Of course I can tell you that on managing the redirection you can read https://learn.getgrav.org/content/routing

I can still tell you that with each new version Andy Miller, the author of Grav, publishes a post in which he presents the changes and future developments. You can read https://getgrav.org/blog/grav-1.5-released and the Roadmap for Grav 2 https://github.com/getgrav/grav/issues/1767

Enjoy Grav

Many thanks for this detailed and very informative answer. And it is very kind of you to have made plugins available to the wider Grav community.

Yes, I am impressed too by Grav, although I should devote more time to explore it in order to understand fully how it works. I have installed some additional plugins without managing to understand until now how they work. While it was very clear how yours should be used, for some other plugins a simple tutorial would help.

As usual, it is true that there is a learning curve in order to learn using a new CMS, and one has to devote some time to that.

Regarding redirections, your reading suggestion has been very useful. Being more familiar with WP, I had expected some plugin in which redirections could be managed (and also for spotting 404 errors). But the method with simple aliases could work too, and I assume that it could work for several hundred redirections (one one of my websites, moved from a previous CMS, I have 2,000 redirections).

Regarding the PDF not showing at all on Firefox, but showing on other browsers, I really do not understand why it is so. However, I confirm that my PDF embeds on WP show fine on Firefox, so I have no idea why it does not work.

Regarding the upper bar, it shows for embeds on my WP sites on all browsers (using PDF Embedder). This is why I find it puzzling that the bar does not show at all in Safari (see first screenshot) and only in a limited way on Chrome (see second screenshot).

With the WP embeds, they all show the same (as in your demo) on all browsers.

But do not want you to lose time in solving that small mystery. It would be interesting to hear from the experiences of other users.

Many thanks for you kindness once again!