Пример #1
0
 private void buttonClear_Click(object sender, RoutedEventArgs e)
 {
     if (!_docSaved)
     {
         if (CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                    this,
                                    "PDF not saved - are you sure you want to clear all pages?",
                                    "Clear All Pages? - Catfood PdfScan",
                                    CatfoodMessageBoxType.YesNo,
                                    CatfoodMessageBoxIcon.Question) == CatfoodMessageBoxResult.Yes)
         {
             ResetState();
         }
     }
 }
Пример #2
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (!_docSaved)
     {
         if (CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                    this,
                                    "PDF not saved - are you sure you want to exit?",
                                    "Exit Catfood PdfScan?",
                                    CatfoodMessageBoxType.YesNo,
                                    CatfoodMessageBoxIcon.Question) != CatfoodMessageBoxResult.Yes)
         {
             e.Cancel = true;
         }
     }
 }
Пример #3
0
        private bool SelectDevice()
        {
            try
            {
                CommonDialog commonDialog = new CommonDialog();
                Device       device       = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, true);
                _deviceId = device.DeviceID;
            }
            catch (Exception ex)
            {
                UserSettings.Settings.LogException(LogSeverity.Warning, "Failed to select scanner", ex);

                CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                       this,
                                       WiaErrorOrMessage(ex),
                                       "Failed to select scanner - Catfood PdfScan",
                                       CatfoodMessageBoxType.Ok,
                                       CatfoodMessageBoxIcon.Error,
                                       ex);
            }

            return(!string.IsNullOrEmpty(_deviceId));
        }
Пример #4
0
        private void ShowExceptionAndDie(Exception ex)
        {
            try
            {
                _settings.LogException(LogSeverity.Error,
                                       "Unhandled Exception",
                                       ex);

                CatfoodMessageBox.Show(new BitmapImage(new Uri("pack://application:,,,/PdfScan.ico")),
                                       MainWindow,
                                       "Something has gone horribly wrong and Catfood PdfScan will now close. Sorry about that. Please report the error so that it gets fixed.",
                                       "Fatal Error - Catfood PdfScan",
                                       CatfoodMessageBoxType.Ok,
                                       CatfoodMessageBoxIcon.Error,
                                       ex);
            }
            catch
            {
            }
            finally
            {
                Shutdown(1);
            }
        }
Пример #5
0
        private void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
                sfd.AddExtension    = true;
                sfd.CheckFileExists = false;
                sfd.CheckPathExists = true;
                sfd.DefaultExt      = "pdf";
                sfd.Filter          = "PDF Documents (*.pdf)|*.pdf";
                sfd.OverwritePrompt = true;
                sfd.Title           = "Save PDF - Catfood PdfScan";

                if (textBoxTitle.Text.Length > 0)
                {
                    char[] badFileChars = System.IO.Path.GetInvalidFileNameChars();

                    bool          charIsBad  = false;
                    StringBuilder sbFileName = new StringBuilder(textBoxTitle.Text.Length);
                    foreach (char c in textBoxTitle.Text)
                    {
                        charIsBad = false;

                        foreach (char badChar in badFileChars)
                        {
                            if (c == badChar)
                            {
                                charIsBad = true;
                                break;
                            }
                        }

                        if (!charIsBad)
                        {
                            sbFileName.Append(c);
                        }
                    }

                    sfd.FileName = sbFileName.ToString();
                }

                if (sfd.ShowDialog(this) == true)
                {
                    Mouse.OverrideCursor = Cursors.Wait;

                    _doc.Info.Title    = textBoxTitle.Text.Trim();
                    _doc.Info.Author   = textBoxAuthor.Text.Trim();
                    _doc.Info.Subject  = textBoxSubject.Text.Trim();
                    _doc.Info.Keywords = textBoxKeywords.Text.Trim();
                    _doc.Info.Creator  = "PdfScan by Catfood Software: http://catfood.net/products/pdfscan/";

                    _doc.Save(sfd.FileName);
                    _docSaved = true;

                    if (UserSettings.Settings.CloseOnSave)
                    {
                        this.Close();
                    }
                    else
                    {
                        ResetState();
                    }
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;

                UserSettings.Settings.LogException(LogSeverity.Warning, "Failed to save PDF", ex);

                CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                       this,
                                       WiaErrorOrMessage(ex),
                                       "Failed to save - PdfScan",
                                       CatfoodMessageBoxType.Ok,
                                       CatfoodMessageBoxIcon.Error,
                                       ex);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
Пример #6
0
        private void buttonScanPages_Click(object sender, RoutedEventArgs e)
        {
            // select device if this failed at startup
            if (string.IsNullOrEmpty(_deviceId))
            {
                if (!SelectDevice())
                {
                    return;
                }
            }

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                _width  = Convert.ToDouble(textBoxWidth.Text, CultureInfo.CurrentCulture);
                _height = Convert.ToDouble(textBoxHeight.Text, CultureInfo.CurrentCulture);
                _adf    = (checkBoxADF.IsChecked == true);

                XImage ximage = null;

                while ((ximage = ScanOne()) != null)
                {
                    PdfPage page = _doc.AddPage();
                    page.Width  = XUnit.FromInch(_width);
                    page.Height = XUnit.FromInch(_height);

                    using (XGraphics g = XGraphics.FromPdfPage(page))
                    {
                        g.DrawImage(ximage, 0, 0);
                        ximage.Dispose();
                    }

                    // flag that the document needs saving
                    _docSaved = false;

                    // only scan one page if not using the ADF
                    if (!_adf)
                    {
                        break;
                    }

                    UpdateState();
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;

                UserSettings.Settings.LogException(LogSeverity.Warning, "Failed to scan page", ex);

                CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                       this,
                                       string.Format(CultureInfo.InvariantCulture, "{0} ({1})", WiaErrorOrMessage(ex), _lastItem),
                                       "Failed to scan - Catfood PdfScan",
                                       CatfoodMessageBoxType.Ok,
                                       CatfoodMessageBoxIcon.Error,
                                       ex);
            }
            finally
            {
                Mouse.OverrideCursor = null;
                UpdateState();
            }
        }