views:

201

answers:

2

I'm using Crystal to display the reports in my project, and I'd like to be able to display a small preview or thumbnail image of the report to the user when he or she is picking a report to display from my UI. Is there any way to produce these thumbnails dynamically from code?

The user has the option to add or remove reports by adding or removing them from the reports folder, so just making all the thumbnail images by hand isn't really an option.

A: 
  1. If you keep reports in files make an images with tha same name in the same folder (export to jpg first page by "on before save" event of report designer - if it is possiblie in CR) and show them / open report by click on image.
  2. If in database - same in database field.
Merl
+1  A: 

I used the DSOFile object to obtain the thumbnail inside the report then used AxHost to convert the returned object to an image I could display. This wasn't the solution I wanted but the DSOFile is freely distributable so I guess this will work until I find something better.

  1. Download and install the DSOFile DLL from Microsoft.
  2. Add a reference to **DSO OLE Document Properties Reader 2.1
  3. code

Here is my code, boiled down to the bare minimum:

  namespace Ibs.Ui.OrderPrint
  {
    public partial class OrderPrintEdit
    {
       public OrderPrintEdit()
       {
        InitializeComponent();
       }

       #region -- reports_SelectedIndexChanged(sender, e) Event Handler --
       private void reports_SelectedIndexChanged(object sender, EventArgs e)
       {
           try
           {
               DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = new DSOFile.OleDocumentPropertiesClass();
               DirectoryInfo reportDirectory = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Reports");
               oleDocumentPropertiesClass.Open(reportDirectory + "\\" + reports.Text,true,DSOFile.dsoFileOpenOptions.dsoOptionDontAutoCreate);
               Object thumbnail = oleDocumentPropertiesClass.SummaryProperties.Thumbnail;
               if (thumbnail != null)
               {
                   reportThumbnail.BackgroundImage = IPictureDispHost.GetPictureFromIPicture(thumbnail);
               }
               else
               {
                   reportThumbnail.BackgroundImage = null;
               }
               oleDocumentPropertiesClass.Close(false);
           }
           catch (Exception ex)
           {
           }
       }
       #endregion
   }

   internal sealed class IPictureDispHost : AxHost
   {
       private IPictureDispHost() : base("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
       {
       }
       /// <summary>
       /// Convert the dispatch interface into an image object.
       /// </summary>
       /// <param name="picture">The picture interface</param>
       /// <returns>An image instance.</returns>
       public new static Image GetPictureFromIPicture(object picture)
       {
           return AxHost.GetPictureFromIPicture(picture);
       }
   }

}

I am filling a combobox with report names on the form load. In the SelectedIndexChanged event I get the Thumbnail object from the report and pass it to the conversion method. This should work for Office documents too.

Beaner
I haven't tried this myself but if we decide to look at implementing this again this is definitely where I'll start.
Lawrence Johnston