Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Show thumbnails of XPS documents

, 26 Jan 2010
How to show thumbnails of XPS documents.
XPSImage-Demo.zip
XPSImage.exe
XPSImage-Src.zip
XPSImage
XPSImage
ClassDiagram1.cd
Properties
Settings.settings
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XPS2Image
{
    public partial class XPSThumbnail : Form
    {
        XpsImage converter = null;
        public XPSThumbnail()
        {
            InitializeComponent();
            converter = new XpsImage();
            this.ClientSize = new Size(411, 300);
        }

        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            openFileDialog.ShowDialog(this);
            textBoxSelectedFile.Text = openFileDialog.FileName;
        }


        private void buttonShowThumbnail_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            converter.XpsFileName = openFileDialog.FileName;
            converter.OutputFormat = GetImageFormat();
            converter.OutputQuality = GetImageQuality();
            converter.GenerateThumbnail();
            pictureBox1.Image = Image.FromStream(converter.OutputStream);
            this.ClientSize = new Size(411, 708);
            this.Cursor = Cursors.Arrow;
        }

        private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (converter.OutputFormat)
            {
                case OutputFormat.Jpeg:
                    saveThumbnail.Filter = "JPEG (*.jpg)|*.jpg";
                    break;
                case OutputFormat.Png:
                    saveThumbnail.Filter = "PNG (*.png)|*.png";
                    break;
                case OutputFormat.Gif:
                    saveThumbnail.Filter = "GIF (*.gif)|*.gif";
                    break;
                default:
                    saveThumbnail.Filter = "JPEG (*.jpg)|*.jpg";
                    break;
            }
            saveThumbnail.ShowDialog(this);
        }

        private OutputFormat GetImageFormat()
        {
            if (radioButtonJpeg.Checked)
                return OutputFormat.Jpeg;
            else if (radioButtonPng.Checked)
                return OutputFormat.Png;
            else if (radioButtonGif.Checked)
                return OutputFormat.Gif;
            else
                return OutputFormat.Jpeg;
        }

        private OutputQuality GetImageQuality()
        {
            if (radioButtonQualityLow.Checked)
                return OutputQuality.Low;
            else if (radioButtonQualityNormal.Checked)
                return OutputQuality.Normal;
            else if (radioButtonQualityGood.Checked)
                return OutputQuality.Good;
            else if (radioButtonQualitySuper.Checked)
                return OutputQuality.Super;
            else
                return OutputQuality.Normal;
        }

        private void saveThumbnail_FileOk(object sender, CancelEventArgs e)
        {
            FileStream stream = new FileStream(saveThumbnail.FileName, FileMode.Create, FileAccess.Write);
            converter.OutputStream.WriteTo(stream);
            stream.Close();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pravesh Soni
Team Leader
United States United States
My name is Pravesh Soni and I’m software professional. I got involved with computers since last two decades starting with playing games developed in BASIC. I am a tech enthusiast and I love writing code, blogging, science fiction, cartoons, music, robotics and I am a big Microsoft fan too.
 
I started programming in classic asp but later switch to .net and now at present I have almost 10 years of development experience in Microsoft technologies. I got involved in customized software development in my career of programming, now contributing to some open source community development.
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 26 Jan 2010
Article Copyright 2010 by Pravesh Soni
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid