Search code examples
delphiimageviewerdocumentviewer

Universal "document/image viewer" for Delphi?


I want to view (only) images files and some common documents (PDF, RTF, TEXT, etc) in my Delphi program, I've found two ways of doing that,

  1. via AtViewer, but the file size is too large.
  2. Via the embedded Internet Explorer installed on the end user's computer directly.

I'm wondering, are there alternatives? Thanks.


Solution

  • There are two ways to go here:

    1. Use whatever software is provided by Windows
    2. Stick to native Delphi components

    I personally like to keep my source "all delphi". When it comes to displaying images Delphi is blessed with many third party libraries that provides you with support for almost every image format imaginable.

    Images

    ImageEN is a good package (commercial) and you might also like the free Vapyre Image Library (the name is a bit.. well, but its a great product). To quickly add support for the most common formats, GraphicsEX is a traditional Delphi extension a lot of developers use. You also have FreeImage, which is collection of DLL files - but with Delphi wrapper classes to make them easy to use. take a look in the graphics section on Torry's Delphi Pages (google it) and you will find robust support.

    PDF

    For PDF preview/reading I would take a look at Gnostice's product-line. They provide native Delphi components for generating and viewing PDF files (http://www.gnostice.com/). Alternatively (for PDF) I would probably go for the ActiveX components that ship with Adobe's PDF reader. But then you will have to check that these objects are registered and available to your application at startup.

    So for your "universal viewer" I would

    1. Create a base viewer-form (to provide buttons, statusbar etc.)
    2. Add a virtual method for opening a file
    3. Decend 3 forms from this that each deal with a different media type. So you get TfrmPDF, TfrmImage and TfrmHTML. In each, override the open() method. This way your main application dont have to bother with the details of each format.

    HTML

    For viewing HTML you are in luck, as Delphi has it's own native Web renderer. It was written by Steve Baldwin and is called THTMLViewer. It has been released as opensource and you will find it on google projects.