Click here to Skip to main content
15,892,746 members
Articles / Programming Languages / C#

Tutorials on creating PDF files using C# 2.0

Rate me:
Please Sign up or sign in to vote.
4.88/5 (46 votes)
16 Mar 2007Public Domain10 min read 854.5K   33.1K   328  
Tutorials on creating PDF files using C# (.NET 2.0) and iTextSharp
using System;
using System.Windows.Forms;

namespace VVX
{
    /// <summary>
    /// Simple class to simplify access to OpenFileDialog and SaveFileDialog
    /// WARNING: By no means complete!!!
    /// </summary>
    public static class FileDialog
    {
        public enum FileType
        {
            All,
            Image,
            Text,
            XML
        }

        public static string GetFilters(FileType enFileType)
        {
            string sRet = "";

            switch (enFileType)
            {
                default:
                case FileType.All:
                    break;

                case FileType.Image:
                    sRet = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG";
                    break;

                case FileType.Text :
                    sRet = "Text Files(*.TXT;*.CSV)|*.TXT;*.CSV";
                    break;

                case FileType.XML:
                    sRet = "XML Files(*.XML)|*.XML";
                    break;
            }

            if (sRet.Length > 0)
                sRet += "|";
            sRet += "All files (*.*)|*.*";

            return sRet;
        }

        public static string GetFilenameToOpen(FileType enFileType)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = GetFilters(enFileType);
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return dlg.FileName;
            }
            return "";
        }

        public static string GetFilenameToSave(FileType enFileType, string sFile)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = GetFilters(enFileType);
            dlg.FileName = sFile;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                return dlg.FileName;
            }
            return "";
        }
    }
}

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 A Public Domain dedication


Written By
Software Developer
United States United States
An old dog trying to learn new tricks!

Comments and Discussions