OSTips – How to Display a PDF in Browser with Drupal 9 & 8

We’ve been posting blogs about Drupal for over 10 years at OSTraining, and so every once in a while someone finds an old blog post from Drupal 6 or even Drupal 7 and asks a question.  Well that’s exactly what happened this week when somebody asked, “How do we display a pdf in the browser with Drupal 9 when someone clicks on a link?”

Keep reading to learn how!

“Hi! This is OSTips from OSTraining.  My name is rod martin, and in this video, I’m going to answer that question.

Actually, it’s a really simple answer with Drupal 9. So a few years ago this was a big issue.  Before the Media Manager came along, we were left with modules like PDF Reader (which now really isn’t being maintained) or Embedded Google Docs Viewer which is still only in Drupal 8 and hasn’t been updated since 2018. Now we have the Media Module that allows us to embed pdfs right on our site! 

  • Click Structure/Content types/Testing/Manage fields

I have just a simple PDF Demo field which is a “media field”. 

NOTE: You will need to have installed that over here under the extend menu (see below) – nothing fancy.

  • Return to Manage Fields tab
  • Click Edit button
  • Select Document under Media type
  • Click Manage display tab

NOTE: The format is Rendered entity and it is Rendered as Default. That’s important!

  • Click Content tab

I have a node in this content type.

  • Click Edit tab
  • Click Add media button

I have one pdf uploaded.

  • Click Insert selected button
  • Click Save button

Now when I click on the pdf link, it’s going to open it right up in my browser.  And of course, site visitors can save it from here.

So a difficult thing to do in Drupal 7 has now been brought into core in Drupal 8 and 9 and is now something that’s really simple.

Well thanks for joining me again today. This has been OSTips from OSTraining, and I’m Rod Martin.”

Instructor

  • Rod holds two masters degrees and has been training people how to do "things" for over 25 years. Originally from Australia, he grew up in Canada and now resides just outside Cincinnati, Ohio. He has worked in both the non-profit and for-profit worlds, in small companies and large corporations. His extensive open source experience includes WordPress, Joomla, Drupal and Moodle and he really knows how to help you get the most out of the system you chose. Rod plays ice hockey a couple of times a week and rides his Goldwing motorcycle pretty much everywhere he can.

0 0 votes
Blog Rating
Subscribe
Notify of
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tobias B

Displaying a PDF in a browser has nothing todo with version of drupal or other cms. The browser itself does the work. 😉

Niklas

This only shows how to add the media field and uploaded file, this didn’t show how to actually display the PDF content into the page.

4
0
Would love your thoughts, please comment.x
()
x