Click here to Skip to main content
12,354,330 members (69,342 online)
Click here to Skip to main content

Tagged as

Stats

23.1K views
1.5K downloads
39 bookmarked
Posted

Show thumbnails of XPS documents

, 26 Jan 2010 CPOL
How to show thumbnails of XPS documents.
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
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 15 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.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 26 Jan 2010
Article Copyright 2010 by Pravesh Soni
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid