How To Open A PDF In A New Tab or Window in Drupal

Whenever I embed a PDF, or any document for that matter in a Drupal website, I always prefer to have the document open in a new tab or window, so that it’s easier to download and also easier to get back to the main site since it’s still there when you close out the PDF. Drupal doesn’t do that “out-of-the-box”. Don’t fear, you can definitely do that in Drupal.

The EXTLink Module For Drupal

When you want to add a feature to your Drupal website, you typically look for a contributed module that will provide that functionality. In Drupal 10, one of the projects (modules) that does that is the EXTLink module and it’s the one we’ll use to add that functionality to our site (https://drupal.org/project/extlink).

Steps:

  1. Install end enable the module using Composer/Drush or manually in the user interface from the link above.
  2. Head over to Configuration -> User Interface -> External Links
  1. Find the checkbox that says: “Open external links in a new window or tab” and put a check mark in the box.
  2. Scroll down to “Patterns” and open the drop down.
  3. In the “Include links matching the pattern field type: .*.pdf
  4. Click Save
  5. Add a PDF to a node and click on the link – it will open in a new tab/window!

Note: Following the above steps will open every pdf in a new tab or window. There is currently no “switch” to opt-out of that behavior.

If you’d like to see it in action, please watch the following OSTip!

If you have any suggestions for OSTip videos, feel free to leave a comment!

Author

  • Rod Martin

    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 and Drupal 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
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x