<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Blog posts by Ninh Doan</title><link href="http://world.optimizely.com" /><updated>2019-04-22T08:47:02.0000000Z</updated><id>https://world.optimizely.com/blogs/ninh-doan/</id> <generator uri="http://world.optimizely.com" version="2.0">Optimizely World</generator> <entry><title>Introducing: Episerver PDF Preview add-on</title><link href="https://world.optimizely.com/blogs/ninh-doan/dates/2019/4/pdfviewer-introduction/" /><id>&lt;p&gt;The &lt;a href=&quot;/link/f7f020d815674508bd7fdc247e0d837b.aspx&quot;&gt;Episerver PDF Preview&lt;/a&gt; is the latest&amp;nbsp;add-on that allows editors to preview PDF documents in edit view.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This add-on is based on&amp;nbsp;&lt;a href=&quot;https://mozilla.github.io/pdf.js/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PDF&lt;/span&gt;.js&lt;/a&gt; version&amp;nbsp;2.0.943.&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Intergration with your current system&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;In the&amp;nbsp;&lt;/span&gt;&lt;strong&gt;PdfPreview&lt;/strong&gt;&lt;span&gt;&amp;nbsp;package, there is a class named&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;PdfFile&lt;/span&gt;&lt;span&gt;&amp;nbsp;which handles uploaded files with the .pdf extension.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;1. The system does not have a model for handling PDF files&lt;/h3&gt;
&lt;p&gt;If the system does not have a model for handling PDF files, the default&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;PdfFile&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;model provided by the package is used. Editors can now preview PDF files in edit view without any extra steps.&lt;/p&gt;
&lt;h3&gt;2. The system already has a model for handling PDF files&lt;/h3&gt;
&lt;p&gt;By default, the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;span class=&quot;classLib&quot;&gt;ContentMediaResolver&lt;/span&gt;&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;class from Episerver CMS Core gets the first matching media implementation type registered for an extension. If there is an existing type registered for &amp;ldquo;pdf&amp;rdquo;, the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;PdfFile&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;media implementation in the Episerver package is used, but in this case the existing type should be chosen.&lt;/p&gt;
&lt;p&gt;To change this default behavior, a media resolver class named&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;strong&gt;&lt;em&gt;&lt;span class=&quot;classLib&quot;&gt;PdfContentMediaResolver&lt;/span&gt;&amp;nbsp;&lt;/em&gt;&lt;/strong&gt;is used to ignore the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;PdfFile&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;type in the Episerver package and thus, the existing registered media type is the candidate.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;classLib&quot;&gt;PdfContentMediaResolver&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;inherits&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;ContentMediaResolver&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and overrides the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;classLib&quot;&gt;Type GetFirstMatching(string extension)&amp;nbsp;&lt;/span&gt;&lt;/em&gt;method to handle the business logic above.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To turn on the PDF preview, the PDF media model must implement the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;em&gt;&lt;span class=&quot;classLib&quot;&gt;IPdfFile&lt;/span&gt;&amp;nbsp;&lt;/em&gt;interface. For example:&lt;/p&gt;
&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;[ContentType(DisplayName = &quot;PdfFile&quot;, GUID = &quot;&amp;hellip;&quot;, Description = &quot;&quot;)]

[MediaDescriptor(ExtensionString = &quot;pdf&quot;)]

public class PdfFile : MediaData, IPdfFile

{

}&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Note:&amp;nbsp;&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&lt;span class=&quot;classLib&quot;&gt;PdfContentMediaResolver&lt;/span&gt;&lt;/em&gt;&lt;em&gt; &lt;/em&gt;will ignore the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;classLib&quot;&gt;PdfFile&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;type in the Episerver package when system has another&amp;nbsp;type registered for &amp;ldquo;pdf&amp;rdquo;, no matter it is created before or after install package. If it is created after install package, AppPool restart is required to r&lt;span&gt;eflect the changes.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Before:&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;/link/c821c71eb59146129d041db7e3fe8521.aspx&quot; /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;/link/ae61d5e784024a359cacb7816a22fc5f.aspx&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</id><updated>2019-04-22T08:47:02.0000000Z</updated><summary type="html">Blog post</summary></entry></feed>