Switch to full style
Project under GPL source codes are posted here
Post a reply

The Paperless Desktop

Fri Nov 07, 2008 1:00 pm

 Project Name:   The Paperless Desktop
 Programmer:   Martin Welker
 Type:   Applcation
 Technology:  C#
 IDE:   NONE
 Description:   After playing around with Microsoft's Document Imaging Library (MODI) in OCR with Microsoft Office, I decided to add some features to the primary MODI application like scanning, multi TIFF rearrangement and Outlook export. The Outlook export enables you to organize your documents by email folders. Since tools like LookOut, this might be faster than the walk to the good old file cabinet.

ToMail.jpg
ToMail.jpg (204.65 KiB) Viewed 5396 times

csharp code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using DocumentProcessing;
using System.Drawing.Printing;

using System.Drawing.Imaging;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Diagnostics;
using Util;
using Util.Modi;
/*

Please note:
The Microsoft® Office Document Imaging Library 2003 (MODI) object model makes
it possible to develop custom applications for managing document images
(such as scanned and faxed documents) and the recognizable text that they
contain. The MODI components include the MODI Viewer Control, an ActiveX® control
that you can use to display MODI documents.

Important: The MODI programmability features described in this document are
available only in Microsoft Office Document Imaging 2003. The Microsoft Office XP
version of document imaging does not include a programmable object model."

*/

namespace DocumentProcessing
{

public class Form1 : System.Windows.Forms.Form
{
private const string CONFIG_FILE = "MartinsPaperlessDesktop.Configuration";

Util.Outlook.DocumentMailer _documentMailer = new Util.Outlook.DocumentMailer();
private MODIOCRParameters _MODIParameters = new MODIOCRParameters();
private MODI.Document _MODIDocument = null;
private string _filename = "";
private bool _changed = false;
private Configuration _configuation = new Configuration();

private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem miFile;
private System.Windows.Forms.MenuItem miOpen;
private AxMODI.AxMiDocView axMiDocView1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem miCopy;
private System.Windows.Forms.MenuItem miAnalyse;
private System.Windows.Forms.MenuItem miSave;
private System.Windows.Forms.MenuItem miOCRParameters;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem miExit;
private System.Windows.Forms.ToolBarButton tbbPan;
private System.Windows.Forms.ToolBarButton tbbSelect;
private System.Windows.Forms.ToolBarButton tbbZoomOut;
private System.Windows.Forms.ToolBarButton tbbZoomIn;
private System.Windows.Forms.ToolBarButton tbbNextPage;
private System.Windows.Forms.ToolBarButton tbbPrevPage;
private System.Windows.Forms.ToolBarButton tbbRotateLeft;
private System.Windows.Forms.ToolBarButton tbbRotateRight;
private System.Windows.Forms.ToolBarButton tbbOpen;
private System.Windows.Forms.ToolBarButton ttbSave;
private System.Windows.Forms.ToolBarButton tbbPrint;
private System.Windows.Forms.ToolBarButton tbbOCR;
private System.Windows.Forms.MenuItem miPrint;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem miAbout;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private Util.TwainLib.TwainControl twainControl1;
private System.Windows.Forms.ToolBarButton tbbScan;
private System.Windows.Forms.MenuItem miScanDevice;
private System.Windows.Forms.MenuItem miScan;
private System.Windows.Forms.MenuItem miSearch;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.ToolBarButton tbbMail;
private System.Windows.Forms.StatusBarPanel sbpStatus;
private System.Windows.Forms.StatusBarPanel sbPPage;
private System.Windows.Forms.MenuItem miSaveAs;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton tbbFitHeight;
private System.Windows.Forms.ToolBarButton tbbFitWidth;
private System.Windows.Forms.ToolBarButton tbb2P;
private System.Windows.Forms.ToolBarButton tbbSinglePage;
private System.Windows.Forms.ToolBarButton tbbContPage;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.Windows.Forms.MenuItem miNew;
private System.Windows.Forms.MenuItem miAppendImage;
private System.Windows.Forms.StatusBarPanel sbpBounds;
private System.Windows.Forms.StatusBarPanel sbpDPI;
private System.Windows.Forms.StatusBarPanel sbpCompression;
private System.Windows.Forms.MenuItem miScanAndAppend;
private System.Windows.Forms.ToolBarButton tbbScanPlus;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem miRemove;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem miConfiguration;
private System.Windows.Forms.ToolBarButton tbbAppend;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.ToolBarButton tbbInfo;
private System.Windows.Forms.MenuItem miMoveUp;
private System.Windows.Forms.MenuItem miMoveDown;
private System.Windows.Forms.MenuItem miCopyPage;
private System.Windows.Forms.MenuItem miExportNotepad;
private System.Windows.Forms.MenuItem miExportMail;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.ToolBarButton tbbExportTxt;
private System.ComponentModel.IContainer components;

public Form1(string[] args)
{
InitializeComponent();

InitScanning();
LoadConfiguation();
statusBar1.ShowPanels = true;

ShowStatus("Ready.");
ApplicationGlobals.InitDocumentPath();
axMiDocView1.DocViewMode = MODI.MiDocviewMode.miDOCVIEWMODE_TWOCOLUMNS_CONTINOUSPAGEVIEW;
axMiDocView1.FitMode = MODI.MiFITMODE.miByWindow;
if (args.Length > 0)
{
if (args[0] != "")
{
SetImage(args[0],true);
}
}

axMiDocView1.Refresh();
}


protected override void Dispose( bool disposing )
{
ReleaseScanning();
ReleaseOutlook();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


#region Vom Windows Form-Designer generierter Code

private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.miFile = new System.Windows.Forms.MenuItem();
this.miNew = new System.Windows.Forms.MenuItem();
this.miOpen = new System.Windows.Forms.MenuItem();
this.miAppendImage = new System.Windows.Forms.MenuItem();
this.miSave = new System.Windows.Forms.MenuItem();
this.miSaveAs = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.miPrint = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.miExit = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.miAnalyse = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.miCopy = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.miRemove = new System.Windows.Forms.MenuItem();
this.miMoveUp = new System.Windows.Forms.MenuItem();
this.miMoveDown = new System.Windows.Forms.MenuItem();
this.miCopyPage = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.miScan = new System.Windows.Forms.MenuItem();
this.miScanAndAppend = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.miSearch = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.miOCRParameters = new System.Windows.Forms.MenuItem();
this.miScanDevice = new System.Windows.Forms.MenuItem();
this.miConfiguration = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.miAbout = new System.Windows.Forms.MenuItem();
this.axMiDocView1 = new AxMODI.AxMiDocView();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.sbpStatus = new System.Windows.Forms.StatusBarPanel();
this.sbPPage = new System.Windows.Forms.StatusBarPanel();
this.sbpBounds = new System.Windows.Forms.StatusBarPanel();
this.sbpDPI = new System.Windows.Forms.StatusBarPanel();
this.sbpCompression = new System.Windows.Forms.StatusBarPanel();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.tbbOpen = new System.Windows.Forms.ToolBarButton();
this.tbbAppend = new System.Windows.Forms.ToolBarButton();
this.ttbSave = new System.Windows.Forms.ToolBarButton();
this.tbbPrint = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.tbbScan = new System.Windows.Forms.ToolBarButton();
this.tbbScanPlus = new System.Windows.Forms.ToolBarButton();
this.tbbOCR = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.tbbMail = new System.Windows.Forms.ToolBarButton();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.tbbPan = new System.Windows.Forms.ToolBarButton();
this.tbbSelect = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.tbbZoomOut = new System.Windows.Forms.ToolBarButton();
this.tbbZoomIn = new System.Windows.Forms.ToolBarButton();
this.tbbFitWidth = new System.Windows.Forms.ToolBarButton();
this.tbbFitHeight = new System.Windows.Forms.ToolBarButton();
this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
this.tbbSinglePage = new System.Windows.Forms.ToolBarButton();
this.tbbContPage = new System.Windows.Forms.ToolBarButton();
this.tbb2P = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.tbbRotateLeft = new System.Windows.Forms.ToolBarButton();
this.tbbRotateRight = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.tbbPrevPage = new System.Windows.Forms.ToolBarButton();
this.tbbNextPage = new System.Windows.Forms.ToolBarButton();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.tbbInfo = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.twainControl1 = new Util.TwainLib.TwainControl();
this.panel1 = new System.Windows.Forms.Panel();
this.miExportNotepad = new System.Windows.Forms.MenuItem();
this.miExportMail = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.tbbExportTxt = new System.Windows.Forms.ToolBarButton();
((System.ComponentModel.ISupportInitialize)(this.axMiDocView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sbPPage)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sbpBounds)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sbpDPI)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.sbpCompression)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miFile,
this.menuItem1,
this.menuItem5,
this.menuItem2});
//
// miFile
//
this.miFile.Index = 0;
this.miFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miNew,
this.miOpen,
this.miAppendImage,
this.miSave,
this.miSaveAs,
this.menuItem4,
this.miExportMail,
this.miExportNotepad,
this.menuItem12,
this.miPrint,
this.menuItem3,
this.miExit});
this.miFile.Text = "File";
//
// miNew
//
this.miNew.Index = 0;
this.miNew.Text = "New";
this.miNew.Click += new System.EventHandler(this.miNew_Click);
//
// miOpen
//
this.miOpen.Index = 1;
this.miOpen.Text = "Open..";
this.miOpen.Click += new System.EventHandler(this.miOpen_Click);
//
// miAppendImage
//
this.miAppendImage.Index = 2;
this.miAppendImage.Text = "Append images..";
this.miAppendImage.Click += new System.EventHandler(this.miAppendImage_Click);
//
// miSave
//
this.miSave.Index = 3;
this.miSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.miSave.Text = "Save";
this.miSave.Click += new System.EventHandler(this.miSave_Click);
//
// miSaveAs
//
this.miSaveAs.Index = 4;
this.miSaveAs.Text = "Save as..";
this.miSaveAs.Click += new System.EventHandler(this.miSaveAs_Click);
//
// menuItem4
//
this.menuItem4.Index = 5;
this.menuItem4.Text = "-";
//
// miPrint
//
this.miPrint.Index = 9;
this.miPrint.Text = "Print";
this.miPrint.Click += new System.EventHandler(this.miPrint_Click);
//
// menuItem3
//
this.menuItem3.Index = 10;
this.menuItem3.Text = "-";
//
// miExit
//
this.miExit.Index = 11;
this.miExit.Text = "Exit";
this.miExit.Click += new System.EventHandler(this.miExit_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miAnalyse,
this.menuItem9,
this.miCopy,
this.menuItem10,
this.miRemove,
this.miMoveUp,
this.miMoveDown,
this.miCopyPage,
this.menuItem8,
this.miScan,
this.miScanAndAppend,
this.menuItem6,
this.miSearch});
this.menuItem1.Text = "Edit";
//
// miAnalyse
//
this.miAnalyse.Index = 0;
this.miAnalyse.Shortcut = System.Windows.Forms.Shortcut.F5;
this.miAnalyse.Text = "Start OCR";
this.miAnalyse.Click += new System.EventHandler(this.miAnalyse_Click);
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "-";
//
// miCopy
//
this.miCopy.Index = 2;
this.miCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.miCopy.Text = "Copy text to clipboard";
this.miCopy.Click += new System.EventHandler(this.miCopy_Click);
//
// menuItem10
//
this.menuItem10.Index = 3;
this.menuItem10.Text = "-";
//
// miRemove
//
this.miRemove.Index = 4;
this.miRemove.Shortcut = System.Windows.Forms.Shortcut.Del;
this.miRemove.Text = "Remove page";
this.miRemove.Click += new System.EventHandler(this.miRemove_Click);
//
// miMoveUp
//
this.miMoveUp.Index = 5;
this.miMoveUp.Shortcut = System.Windows.Forms.Shortcut.CtrlIns;
this.miMoveUp.Text = "Move page up";
this.miMoveUp.Click += new System.EventHandler(this.miMoveUp_Click);
//
// miMoveDown
//
this.miMoveDown.Index = 6;
this.miMoveDown.Shortcut = System.Windows.Forms.Shortcut.CtrlDel;
this.miMoveDown.Text = "Move page down";
this.miMoveDown.Click += new System.EventHandler(this.miMoveDown_Click);
//
// miCopyPage
//
this.miCopyPage.Index = 7;
this.miCopyPage.Text = "Copy page";
this.miCopyPage.Click += new System.EventHandler(this.miCopyPage_Click);
//
// menuItem8
//
this.menuItem8.Index = 8;
this.menuItem8.Text = "-";
//
// miScan
//
this.miScan.Index = 9;
this.miScan.Text = "Scan New Document";
this.miScan.Click += new System.EventHandler(this.miScan_Click);
//
// miScanAndAppend
//
this.miScanAndAppend.Index = 10;
this.miScanAndAppend.Text = "Scan and append to Document";
this.miScanAndAppend.Click += new System.EventHandler(this.miScanAndAppend_Click);
//
// menuItem6
//
this.menuItem6.Index = 11;
this.menuItem6.Text = "-";
//
// miSearch
//
this.miSearch.Index = 12;
this.miSearch.Shortcut = System.Windows.Forms.Shortcut.CtrlF;
this.miSearch.Text = "Find..";
this.miSearch.Click += new System.EventHandler(this.miSearch_Click);
//
// menuItem5
//
this.menuItem5.Index = 2;
this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miOCRParameters,
this.miScanDevice,
this.miConfiguration});
this.menuItem5.Text = "Options";
//
// miOCRParameters
//
this.miOCRParameters.Index = 0;
this.miOCRParameters.Shortcut = System.Windows.Forms.Shortcut.F7;
this.miOCRParameters.Text = "Select OCR Parameters..";
this.miOCRParameters.Click += new System.EventHandler(this.miOCRParameters_Click);
//
// miScanDevice
//
this.miScanDevice.Index = 1;
this.miScanDevice.Text = "Select Scan Device..";
this.miScanDevice.Click += new System.EventHandler(this.miScanDevice_Click);
//
// miConfiguration
//
this.miConfiguration.Index = 2;
this.miConfiguration.Text = "Configuration..";
this.miConfiguration.Click += new System.EventHandler(this.miConfiguration_Click);
//
// menuItem2
//
this.menuItem2.Index = 3;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miAbout});
this.menuItem2.Text = "Help";
//
// miAbout
//
this.miAbout.Index = 0;
this.miAbout.Text = "About";
this.miAbout.Click += new System.EventHandler(this.miAbout_Click);
//
// axMiDocView1
//
this.axMiDocView1.ContainingControl = this;
this.axMiDocView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axMiDocView1.Enabled = true;
this.axMiDocView1.Location = new System.Drawing.Point(0, 0);
this.axMiDocView1.Name = "axMiDocView1";
this.axMiDocView1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMiDocView1.OcxState")));
this.axMiDocView1.Size = new System.Drawing.Size(760, 479);
this.axMiDocView1.TabIndex = 2;
this.axMiDocView1.PageChanged += new System.EventHandler(this.axMiDocView1_PageChanged);
this.axMiDocView1.CurPageNumChanged += new System.EventHandler(this.axMiDocView1_CurPageNumChanged);
this.axMiDocView1.SelectionChanged += new System.EventHandler(this.axMiDocView1_SelectionChanged);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 507);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.sbpStatus,
this.sbPPage,
this.sbpBounds,
this.sbpDPI,
this.sbpCompression});
this.statusBar1.Size = new System.Drawing.Size(760, 22);
this.statusBar1.TabIndex = 4;
//
// sbpStatus
//
this.sbpStatus.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.sbpStatus.Width = 300;
//
// sbPPage
//
this.sbPPage.Width = 40;
//
// sbpBounds
//
this.sbpBounds.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.sbpBounds.MinWidth = 100;
//
// sbpCompression
//
this.sbpCompression.Width = 200;
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbbOpen,
this.tbbAppend,
this.ttbSave,
this.tbbPrint,
this.toolBarButton5,
this.tbbScan,
this.tbbScanPlus,
this.tbbOCR,
this.toolBarButton6,
this.tbbMail,
this.tbbExportTxt,
this.toolBarButton1,
this.tbbPan,
this.tbbSelect,
this.toolBarButton2,
this.tbbZoomOut,
this.tbbZoomIn,
this.tbbFitWidth,
this.tbbFitHeight,
this.toolBarButton7,
this.tbbSinglePage,
this.tbbContPage,
this.tbb2P,
this.toolBarButton3,
this.tbbRotateLeft,
this.tbbRotateRight,
this.toolBarButton4,
this.tbbPrevPage,
this.tbbNextPage,
this.toolBarButton8,
this.tbbInfo});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(760, 28);
this.toolBar1.TabIndex = 5;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// tbbOpen
//
this.tbbOpen.ImageIndex = 0;
this.tbbOpen.Tag = "Open";
this.tbbOpen.ToolTipText = "Open";
//
// tbbAppend
//
this.tbbAppend.ImageIndex = 22;
this.tbbAppend.Tag = "Append";
this.tbbAppend.ToolTipText = "Append Image";
//
// ttbSave
//
this.ttbSave.ImageIndex = 1;
this.ttbSave.Tag = "Save";
this.ttbSave.ToolTipText = "Save";
//
// tbbPrint
//
this.tbbPrint.ImageIndex = 2;
this.tbbPrint.Tag = "Print";
this.tbbPrint.ToolTipText = "Print";
//
// toolBarButton5
//
this.toolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbScan
//
this.tbbScan.ImageIndex = 20;
this.tbbScan.Tag = "Scan";
this.tbbScan.ToolTipText = "Scan and create new document";
//
// tbbScanPlus
//
this.tbbScanPlus.ImageIndex = 21;
this.tbbScanPlus.Tag = "ScanPlus";
this.tbbScanPlus.ToolTipText = "Scan and append to Document";
//
// tbbOCR
//
this.tbbOCR.ImageIndex = 13;
this.tbbOCR.Tag = "OCR";
this.tbbOCR.ToolTipText = "OCR";
//
// toolBarButton6
//
this.toolBarButton6.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbMail
//
this.tbbMail.ImageIndex = 9;
this.tbbMail.Tag = "Mail";
this.tbbMail.ToolTipText = "Mail";
//
// toolBarButton1
//
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbPan
//
this.tbbPan.ImageIndex = 4;
this.tbbPan.Tag = "Pan";
this.tbbPan.ToolTipText = "Pan";
//
// tbbSelect
//
this.tbbSelect.ImageIndex = 3;
this.tbbSelect.Tag = "Select";
this.tbbSelect.ToolTipText = "Select";
//
// toolBarButton2
//
this.toolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbZoomOut
//
this.tbbZoomOut.ImageIndex = 6;
this.tbbZoomOut.Tag = "-";
this.tbbZoomOut.ToolTipText = "Zoom Out";
//
// tbbZoomIn
//
this.tbbZoomIn.ImageIndex = 5;
this.tbbZoomIn.Tag = "+";
this.tbbZoomIn.ToolTipText = "Zoom In";
//
// tbbFitWidth
//
this.tbbFitWidth.ImageIndex = 12;
this.tbbFitWidth.Tag = "FitW";
this.tbbFitWidth.ToolTipText = "Fit Width";
//
// tbbFitHeight
//
this.tbbFitHeight.ImageIndex = 10;
this.tbbFitHeight.Tag = "FitH";
this.tbbFitHeight.ToolTipText = "Fit Height";
//
// toolBarButton7
//
this.toolBarButton7.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbSinglePage
//
this.tbbSinglePage.ImageIndex = 19;
this.tbbSinglePage.Tag = "SinglePage";
this.tbbSinglePage.ToolTipText = "Show Single Page";
//
// tbbContPage
//
this.tbbContPage.ImageIndex = 18;
this.tbbContPage.Tag = "ContPage";
this.tbbContPage.ToolTipText = "Show Continous Page";
//
// tbb2P
//
this.tbb2P.ImageIndex = 17;
this.tbb2P.Tag = "DV2P";
this.tbb2P.ToolTipText = "Show Two Pages";
//
// toolBarButton3
//
this.toolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbRotateLeft
//
this.tbbRotateLeft.ImageIndex = 16;
this.tbbRotateLeft.Tag = "rotLeft";
this.tbbRotateLeft.ToolTipText = "Rotate Left";
//
// tbbRotateRight
//
this.tbbRotateRight.ImageIndex = 15;
this.tbbRotateRight.Tag = "rotRight";
this.tbbRotateRight.ToolTipText = "Rotate Right";
//
// toolBarButton4
//
this.toolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbPrevPage
//
this.tbbPrevPage.ImageIndex = 8;
this.tbbPrevPage.Tag = "<";
this.tbbPrevPage.ToolTipText = "Prev Page";
//
// tbbNextPage
//
this.tbbNextPage.ImageIndex = 7;
this.tbbNextPage.Tag = ">";
this.tbbNextPage.ToolTipText = "Next Page";
//
// toolBarButton8
//
this.toolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbbInfo
//
this.tbbInfo.ImageIndex = 23;
this.tbbInfo.Tag = "Info";
this.tbbInfo.ToolTipText = "About";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// twainControl1
//
this.twainControl1.FinishScanning += new Util.TwainLib.FinishScanningEventHandler(this.twainControl1_FinishScanning);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.SteelBlue;
this.panel1.Controls.Add(this.axMiDocView1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 28);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(760, 479);
this.panel1.TabIndex = 6;
//
// miExportNotepad
//
this.miExportNotepad.Index = 7;
this.miExportNotepad.Text = "Export to Notepad..";
this.miExportNotepad.Click += new System.EventHandler(this.miExportNotepad_Click);
//
// miExportMail
//
this.miExportMail.Index = 6;
this.miExportMail.Text = "Export to Outlook..";
this.miExportMail.Click += new System.EventHandler(this.miExportMail_Click);
//
// menuItem12
//
this.menuItem12.Index = 8;
this.menuItem12.Text = "-";
//
// tbbExportTxt
//
this.tbbExportTxt.ImageIndex = 24;
this.tbbExportTxt.Tag = "ExportTxt";
this.tbbExportTxt.ToolTipText = "Export to nodepad";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(760, 529);
this.Controls.Add(this.panel1);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.statusBar1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Martin\'s Paperless Desktop";
this.Closed += new System.EventHandler(this.Form1_Closed);
((System.ComponentModel.ISupportInitialize)(this.axMiDocView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sbpStatus)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sbPPage)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sbpBounds)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sbpDPI)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.sbpCompression)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1(args));
}


#region Configuation
private void LoadConfiguation()
{
if (File.Exists(Application.StartupPath+"\\"+CONFIG_FILE))
{
_configuation = Configuration.LoadFromFile(Application.StartupPath+"\\"+CONFIG_FILE);
}
}
private void miConfiguration_Click(object sender, System.EventArgs e)
{
// simple dialog to modify the MODI OCR parameters..
// !!no OK checking provided!!
DialogConfiguration dialog = new DialogConfiguration();
dialog.Settings = _configuation;
if (dialog.ShowDialog() == DialogResult.OK)
{
_configuation.SaveToFile(Application.StartupPath+"\\"+CONFIG_FILE);
}
}

#endregion

#region Misc

private void About()
{
DialogAbout d = new DialogAbout();
d.ShowDialog();
}


private void miAbout_Click(object sender, System.EventArgs e)
{
About();
}


private void miExit_Click(object sender, System.EventArgs e)
{
this.Close();
}


private void NewDocument()
{
// create filename with time stamp
string TEMP =
ApplicationGlobals.GetDocumentPath()
+ "Doc_"
+ DateTime.Now.ToShortDateString()+"_"
+ DateTime.Now.ToShortTimeString().Replace(":","_")
+".tif";
SetImage("",false);
_filename = TEMP;
ShowStatus();
}


private void miNew_Click(object sender, System.EventArgs e)
{
// new document
SetImage("",false);
}

private void Form1_Closed(object sender, System.EventArgs e)
{
EnsureSaveChanges();
}




private void miRemove_Click(object sender, System.EventArgs e)
{
if (_MODIDocument == null) return;
if (_MODIDocument.Images.Count == 0) return;
MODI.Image img = (MODI.Image) _MODIDocument.Images[axMiDocView1.PageNum];
if (img != null)
{
_MODIDocument.Images.Remove(img);
_changed = true;
axMiDocView1.Refresh();
}
}

#endregion

#region Toolbox

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch((string)e.Button.Tag )
{
case "Open":
OpenFile(); break;
case "Append":
AppendImages();
break;
case "Save":
SaveFile();break;
case "ExportTxt":
ExportTxt();break;
case "Print":
PrintFile();break;
case "Info":
About();break;
case "Scan":
ScanNewDocument();break;
case "ScanPlus":
StartScanning();break;
case "Mail":
Mail();break;
case "OCR":
DoOCR();break;
case "DV2P":
axMiDocView1.DocViewMode = MODI.MiDocviewMode.miDOCVIEWMODE_TWOCOLUMNS_CONTINOUSPAGEVIEW;break;
case "ContPage":
axMiDocView1.DocViewMode = MODI.MiDocviewMode.miDOCVIEWMODE_CONTINOUSPAGEVIEW;break;
case "SinglePage":
axMiDocView1.DocViewMode = MODI.MiDocviewMode.miDOCVIEWMODE_SINGLEPAGEVIEW;break;
case "Select":
axMiDocView1.ActionState = MODI.MiActionState.miASTATE_SELECT;break;
case "Pan":
{
axMiDocView1.DocViewMode = MODI.MiDocviewMode.miDOCVIEWMODE_CONTINOUSPAGEVIEW;
axMiDocView1.ActionState = MODI.MiActionState.miASTATE_PAN;
break;
}
case "FitH":
axMiDocView1.FitMode = MODI.MiFITMODE.miByHeight;break;
case "FitW":
axMiDocView1.FitMode = MODI.MiFITMODE.miByWidth;break;

case "-":
{
axMiDocView1.FitMode = MODI.MiFITMODE.miFree;
double sx = 0; double sy = 0;
axMiDocView1.GetScale(ref sx,ref sy);
axMiDocView1.SetScale(sx*0.9,sx*0.9);
break;
}
case "+":
{
axMiDocView1.FitMode = MODI.MiFITMODE.miFree;
double sx = 0; double sy = 0;
axMiDocView1.GetScale(ref sx,ref sy);
axMiDocView1.SetScale(sx*1.1,sx*1.1);
break;
}
case "<":
{
if (axMiDocView1.PageNum > 0)
axMiDocView1.PageNum--;
break;
}

case ">":
if (axMiDocView1.PageNum < axMiDocView1.NumPages-1)
axMiDocView1.PageNum++;
break;

case "rotLeft":
{
if (_MODIDocument == null) return;
MODI.Image img = (MODI.Image)_MODIDocument.Images[axMiDocView1.PageNum];
img.Rotate(270);
_changed = true;
break;
}

case "rotRight":
{
if (_MODIDocument == null) return;
MODI.Image img = (MODI.Image) _MODIDocument.Images[axMiDocView1.PageNum];
img.Rotate(90);
_changed = true;
break;
}
}
ShowStatus();
}

#endregion

#region Updating
private void ShowStatus()
{
sbPPage.Text = (axMiDocView1.PageNum+1).ToString() +"/" + axMiDocView1.NumPages.ToString();
if (axMiDocView1.NumPages > 0)
{
if (_MODIDocument != null)
{
MODI.Image img = (MODI.Image) _MODIDocument.Images[axMiDocView1.PageNum];
sbpBounds.Text = "W:"+img.PixelWidth.ToString() + " H:"+img.PixelHeight.ToString();
sbpDPI.Text = "DPI:"+img.XDPI.ToString() + "/"+img.YDPI.ToString();
sbpCompression.Text = img.Compression.ToString();
}
}
ShowTitle();
}

private void ClearStatus()
{
sbPPage.Text = "";
sbpBounds.Text = "";
sbpDPI.Text = "";
sbpCompression.Text = "";
ShowTitle();
}

private void ShowStatus(string message)
{
sbpStatus.Text = message;

}

private void ShowTitle()
{
string TITLE = "Martin's Paperless Desktop";
this.Text = TITLE;
if (_filename != "")
{
FileInfo fi = new FileInfo(_filename);
this.Text = TITLE + " - "+fi.Name;
if (_changed)
this.Text += "*";
}

}

public void ShowProgress(int progress, ref bool cancel)
{
ShowStatus(progress.ToString() + "% processed.");
}

private void axMiDocView1_PageChanged(object sender, System.EventArgs e)
{
ShowStatus();
}

private void axMiDocView1_SelectionChanged(object sender, System.EventArgs e)
{
ShowStatus();
}

private void axMiDocView1_CurPageNumChanged(object sender, System.EventArgs e)
{
ShowStatus();
}
#endregion

#region Opening
private void OpenFile()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Image files|*.tif;*.tiff;*.bmp|All files (*.*)|*.*" ;
if (dialog.ShowDialog() == DialogResult.OK)
{
SetImage(dialog.FileName,true);
}
}

private void miOpen_Click(object sender, System.EventArgs e)
{
// open document file..
OpenFile();
}


private void EnsureSaveChanges()
{
if (_changed)
{
if (MessageBox.Show("File has changed! Save?","Saving",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
SaveFile();
}

}
}
private void SetImage(string filename,bool open)
{
EnsureSaveChanges();
// set image..
ClearStatus();
try
{
if (_MODIDocument != null) _MODIDocument.Close(false);
_filename = filename;
_MODIDocument = new MODI.Document();

_MODIDocument.Create(filename);

axMiDocView1.Document = _MODIDocument;
_changed = false;
axMiDocView1.Refresh();

}
catch(System.Runtime.InteropServices.COMException ee)
{
MessageBox.Show(ee.Message);
}
ShowStatus();
}




#endregion

#region Appending
private void AppendImages()
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true;
dialog.Title = "Appending images";
dialog.Filter = "Image files|*.tif;*.tiff;*.jpg;*.bmp|All files (*.*)|*.*" ;
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
for (int i = 0; i < dialog.FileNames.Length; i++)
{
AppendImage(dialog.FileNames[i]);
}
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
}
_changed = true;
ShowStatus();
}

private void AppendImage(string source)
{
if (_MODIDocument == null)
{
SetImage(source,true);
}
else
{
MODI.Document document = new MODI.Document();
document.Create(source);
_changed = true;
for (int i = 0; i < document.Images.Count; i++)
{
_MODIDocument.Images.Add(document.Images[i],null);
}
}
}


private void miAppendImage_Click(object sender, System.EventArgs e)
{
AppendImages();
}
#endregion

#region OCR

public void EnsureOCR(int page)
{
MODI.Image img = (MODI.Image) _MODIDocument.Images[page];
try
{

// just ask and expect an exception
int voidReturn = img.Layout.NumChars;
return;
}
catch(Exception ee)
{
img.OCR(_MODIParameters.Language,_MODIParameters.WithAutoRotation,_MODIParameters.WithStraightenImage);
}
}

public void EnsureOCR()
{
if (_MODIDocument == null) return;
for (int i = 0; i < _MODIDocument.Images.Count; i++)
{
EnsureOCR(i);
}
}

public void DoOCR()
{

if (_MODIDocument == null) return;
try
{

// add event handler for progress visualisation
_MODIDocument.OnOCRProgress += new MODI._IDocumentEvents_OnOCRProgressEventHandler(this.ShowProgress);

// the MODI call for OCR
_MODIDocument.OCR(_MODIParameters.Language,_MODIParameters.WithAutoRotation,_MODIParameters.WithStraightenImage);

}
catch(Exception ee)
{
// simple exception "handling"
MessageBox.Show(ee.Message);
}

ShowStatus("Ready.");
}

private void miAnalyse_Click(object sender, System.EventArgs e)
{
// analyse document..
if (_MODIDocument == null)
{
MessageBox.Show("No document selected!");
return;
}
DoOCR();
}

private void miOCRParameters_Click(object sender, System.EventArgs e)
{
// simple dialog to modify the MODI OCR parameters..
// !!no OK checking provided!!
DialogMODISettings dialog = new DialogMODISettings();
dialog.Settings = _MODIParameters;
dialog.ShowDialog();
}
#endregion

#region Content Operations

/// <summary>
/// very trivial convert to html
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
private string ConvertToHTML(string content)
{
return content.Replace("\r\n","<br>");
}

private string GetDocumentText()
{

Model.Document doc = Model.Document.CreateByMODI(_MODIDocument);
return doc.GetText();
}

#endregion

#region Clipboard
private void miCopy_Click(object sender, System.EventArgs e)
{
// copy to clipboard..
if (axMiDocView1.TextSelection != null)
{
axMiDocView1.TextSelection.CopyToClipboard();
}
}

#endregion

#region Saving
private void SaveFile()
{
if (_MODIDocument != null)
{
_MODIDocument.SaveAs(_filename,MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF_LOSSLESS,MODI.MiCOMP_LEVEL.miCOMP_LEVEL_LOW);
_changed = false;
}
ShowStatus();
}

private void SaveFileAs(string fn)
{
if (_MODIDocument != null)
{
_MODIDocument.SaveAs(fn,MODI.MiFILE_FORMAT.miFILE_FORMAT_TIFF_LOSSLESS,MODI.MiCOMP_LEVEL.miCOMP_LEVEL_LOW);
_changed = false;
}
ShowStatus();
}


private void miSave_Click(object sender, System.EventArgs e)
{
// save
SaveFile();
}


private void miSaveAs_Click(object sender, System.EventArgs e)
{
SaveFileDialog d = new SaveFileDialog();
d.FileName = _filename;
if (d.ShowDialog() == DialogResult.OK)
{
_filename = d.FileName;
SaveFile();
}
}

#endregion

#region Printing
private void PrintFile()
{
if (_MODIDocument != null)
{
PrintDialog d = new PrintDialog();
d.AllowSomePages = true;
d.AllowSelection = false;
d.PrintToFile = false;
PrinterSettings ps = new PrinterSettings();
ps.MinimumPage = 0;
ps.MaximumPage = _MODIDocument.Images.Count-1;
ps.FromPage = 0;
ps.ToPage =_MODIDocument.Images.Count-1;

d.PrinterSettings = ps;
if (d.ShowDialog() == DialogResult.OK)
{
_MODIDocument.PrintOut

(d.PrinterSettings.FromPage,d.PrinterSettings.ToPage,

d.PrinterSettings.Copies,d.PrinterSettings.PrinterName,"",false,MODI.MiPRINT_FITMODES.miPRINT_ACTUALSIZE);

}
}
}

private void miPrint_Click(object sender, System.EventArgs e)
{
// print
PrintFile();
}

#endregion

#region Outlook Export
private void Mail()
{
if (_documentMailer == null) return ;
if (_MODIDocument == null) return ;
EnsureOCR();
string content = GetDocumentText();
content = ConvertToHTML(content);
ArrayList attachments = new ArrayList();
if (_configuation.AppendImagesToMail)
{
attachments.Add(_filename);
}
try
{
_documentMailer.AddToOutBox("[email protected]",
"Document from "+DateTime.Now.ToLongTimeString(),
content,
attachments);
}
catch(Exception ee)
{
MessageBox.Show("Outlook export error: "+ee.Message);
}
}


private void ReleaseOutlook()
{
if (_documentMailer != null)
_documentMailer.Release();
}
#endregion

#region Scanning
public void InitScanning()
{
try
{
twainControl1.Init(this.Handle);
}
catch(Exception ee)
{
MessageBox.Show("No scanning available!");
}
}

public void ReleaseScanning()
{
twainControl1.Release();
}


public void StartScanning()
{
twainControl1.StartScanning(_configuation.OpenSettingsDialogBeforeScanning, false);
}


private void miScanAndAppend_Click(object sender, System.EventArgs e)
{
_changed = true;
StartScanning();

}

public void AppendScannedImages(ArrayList imagefilenames)
{
try
{
for (int i = 0 ; i < imagefilenames.Count; i++)
{
string img = (string) imagefilenames[i];
AppendImage(img);
}
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
}
}


private void twainControl1_FinishScanning(object sender,Util.TwainLib.FinishScanningEventArgs e)
{
if (e.scanned)
{
ArrayList images = twainControl1.PopImages();
AppendScannedImages(images);
SaveFile();
}
}


private void miScanDevice_Click(object sender, System.EventArgs e)
{
// select scan device
twainControl1.SelectDevice();
}

private void ScanNewDocument()
{
NewDocument();
StartScanning();
}

private void miScan_Click(object sender, System.EventArgs e)
{
ScanNewDocument();
}

private void miScanPlus_Click(object sender, System.EventArgs e)
{
StartScanning();
}

#endregion

#region Searching
private void FindFirst()
{
if (_MODIDocument == null) return;
DialogSearch d = new DialogSearch();
if (d.ShowDialog() == DialogResult.OK)
{
if (d.SearchText.Trim() != "")
{
EnsureOCR();
object n1 = null;
object n2 = null;
object n3 = null;
object n4 = null;
MODI.IMiSelectableItem sel = null;

MODI.MiDocSearchClass search = new MODI.MiDocSearchClass();

search.Initialize(_MODIDocument,d.SearchText,ref n1,ref n2,ref n3,ref n4,false,false,false,true);
search.Search(null,ref sel);
if (sel != null)
{
axMiDocView1.TextSelection = sel;
}
}
}
}

private void miSearch_Click(object sender, System.EventArgs e)
{
// find
FindFirst();
}
#endregion

#region Moving
private void MoveImage(int pageNumber, bool up)
{
if (_MODIDocument == null) return;
MODI.Image img = (MODI.Image) _MODIDocument.Images[pageNumber];
if (up)
{

if (pageNumber-1 >= 0)
{
MODI.Image prevImg = (MODI.Image) _MODIDocument.Images[pageNumber-1];
_MODIDocument.Images.Add(img,prevImg);
MODI.Image removeImg = (MODI.Image) _MODIDocument.Images[pageNumber+1];
_MODIDocument.Images.Remove(removeImg);
axMiDocView1.PageNum = pageNumber-1;
}

}
else
{
if (pageNumber+1 < axMiDocView1.NumPages)
{
MODI.Image nextImg = null;
if (pageNumber+2 < _MODIDocument.Images.Count)
{
nextImg = (MODI.Image) _MODIDocument.Images[pageNumber+2];
}
_MODIDocument.Images.Add(img,nextImg);
MODI.Image removeImg = (MODI.Image) _MODIDocument.Images[pageNumber];
_MODIDocument.Images.Remove(removeImg);
axMiDocView1.PageNum = pageNumber+1;
}
}
_changed = true;
ShowStatus();
}


private void miMoveUp_Click(object sender, System.EventArgs e)
{
MoveImage(axMiDocView1.PageNum,true);
}

private void miMoveDown_Click(object sender, System.EventArgs e)
{
MoveImage(axMiDocView1.PageNum,false);
}
#endregion

#region Duplicating
private void DuplicateImage(int pageNumber)
{
if (_MODIDocument == null) return;
MODI.Image img = (MODI.Image) _MODIDocument.Images[pageNumber];

_MODIDocument.Images.Add(img,img);
_changed = true;
ShowStatus();

}

private void miCopyPage_Click(object sender, System.EventArgs e)
{
DuplicateImage(axMiDocView1.PageNum);
}
#endregion

#region Export
private void miExportMail_Click(object sender, System.EventArgs e)
{
Mail();
}

private void ExportTxt()
{
if (_MODIDocument == null) return;

string txtfile = _filename + ".txt";

Stream myStream = new System.IO.FileStream( txtfile,System.IO.FileMode.Create);
StreamWriter writer = new StreamWriter(myStream);
writer.WriteLine(GetDocumentText());
writer.Close();
myStream.Close();

Process notePad = new Process();

notePad.StartInfo.FileName = "notepad.exe";

notePad.StartInfo.Arguments = txtfile;

notePad.Start();
}

private void miExportNotepad_Click(object sender, System.EventArgs e)
{
ExportTxt();
}

#endregion
}

[Serializable]
public class Configuration
{
private string _mailAddress = "[email protected]" ;
[Description("The mail address used by default for mail export.")]
public string MailAddress
{
get { return _mailAddress; }
set { _mailAddress = value; }
}

private bool _appendImagesToMail = true;
[Description("Pages images should be attached to the mail.")]
public bool AppendImagesToMail
{
get { return _appendImagesToMail; }
set { _appendImagesToMail = value; }
}

private bool _openSettingsDialogBeforeScanning = true;
[Description("Scan device specific dialog appears before scanning.")]
public bool OpenSettingsDialogBeforeScanning
{
get { return _openSettingsDialogBeforeScanning; }
set { _openSettingsDialogBeforeScanning = value; }
}

public bool SaveToFile(string path)
{
try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, this);
stream.Close();
}
catch(System. Exception ee)
{
return false;
}
return true;

}


public static Configuration LoadFromFile(string path)
{
IFormatter formatter = new BinaryFormatter();

Stream streamS = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
object o = formatter.Deserialize(streamS);
Configuration solution = (Configuration) o;
streamS.Close();
return solution ;
}

}
}



Attachments
MartinsPaperlessDesktop.zip
(119.47 KiB) Downloaded 945 times

Re: The Paperless Desktop

Sun Jan 20, 2013 9:49 pm

updated.

Post a reply
  Related Posts  to : The Paperless Desktop
 can't able to change my windows desktop     -  
 Desktop/Network Engineer - South Korea     -  

Topic Tags

C# Projects