Ninh Doan
Apr 22, 2019
  7597
(8 votes)

Introducing: Episerver PDF Preview add-on

The Episerver PDF Preview is the latest add-on that allows editors to preview PDF documents in edit view. 

This add-on is based on PDF.js version 2.0.943. 

Intergration with your current system

In the PdfPreview package, there is a class named PdfFile which handles uploaded files with the .pdf extension. 

1. The system does not have a model for handling PDF files

If the system does not have a model for handling PDF files, the default PdfFile model provided by the package is used. Editors can now preview PDF files in edit view without any extra steps.

2. The system already has a model for handling PDF files

By default, the ContentMediaResolver class from Episerver CMS Core gets the first matching media implementation type registered for an extension. If there is an existing type registered for “pdf”, the PdfFile media implementation in the Episerver package is used, but in this case the existing type should be chosen.

To change this default behavior, a media resolver class named PdfContentMediaResolver is used to ignore the PdfFile type in the Episerver package and thus, the existing registered media type is the candidate.

PdfContentMediaResolver inherits ContentMediaResolver and overrides the Type GetFirstMatching(string extension) method to handle the business logic above. 

To turn on the PDF preview, the PDF media model must implement the IPdfFile interface. For example:

[ContentType(DisplayName = "PdfFile", GUID = "…", Description = "")]

[MediaDescriptor(ExtensionString = "pdf")]

public class PdfFile : MediaData, IPdfFile

{

}

Note: 

PdfContentMediaResolver will ignore the PdfFile type in the Episerver package when system has another type registered for “pdf”, no matter it is created before or after install package. If it is created after install package, AppPool restart is required to reflect the changes.

Demo:

  • Before: 

  • After:

 

Apr 22, 2019

Comments

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024