private void ScannerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Iniciar Proceso de Digitalización
            if (_twain.State == 4)
            {
                //_twain.CurrentSource.CapXferCount.Set(4);

                _stopScan  = false;
                frmPreview = new ScanPreview();
                frmPreview.StartPosition = FormStartPosition.CenterScreen;
                frmPreview.tblPreview.changeSizeThumb(new Size(96, 96));
                frmPreview.Show();

                if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
                {
                    // hide scanner ui if possible
                    if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                        bSoloTipoActual        = true;
                    }
                }
                else
                {
                    if (_twain.CurrentSource.Enable(SourceEnableMode.ShowUI, true, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                        bSoloTipoActual        = true;
                    }
                }
            }
        }
        private void desdePDFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Multiselect     = false,
                CheckFileExists = true,
                DefaultExt      = "pdf",
                Filter          = "Archivos PDF (*.pdf)|*.pdf",
                Title           = "Abrir Archvivo PDF"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            frmPreview = new ScanPreview();
            frmPreview.StartPosition = FormStartPosition.CenterScreen;
            frmPreview.tblPreview.changeSizeThumb(new Size(96, 96));
            frmPreview.Show();

            PdfiumViewer.IPdfDocument documento;

            documento = PdfiumViewer.PdfDocument.Load(ofd.FileName);

            frmPrincipal.Instance.TSPBGeneral.Visible = true;

            for (int i = 0; i < documento.PageCount; i++)
            {
                using (var image = documento.Render(i, (int)(documento.PageSizes[i].Width * 2.5), (int)(documento.PageSizes[i].Height * 2.5), 150, 150, true))
                {
                    Scan.Images.IScannedImage imagen1 = new Scan.Images.ScannedImage(new Bitmap(image), ScanBitDepth.C24Bit, false);
                    imagenesCapturadas[iActualTipoDocumento].Images.Add(imagen1);
                    frmPreview.tblPreview.AppendImage(imagen1);
                    Application.DoEvents();
                }
            }

            tblImagenes.UpdateImages(imagenesCapturadas[iActualTipoDocumento].Images);
            frmPrincipal.Instance.TSPBGeneral.Visible = false;

            if (frmPreview != null)
            {
                frmPreview.Close();
                frmPreview.Dispose();
            }
        }
        private void btnDigitalizar_Click(object sender, EventArgs e)
        {
            if (imagenesCapturadas.Images.Count > 0)
            {
                if (MessageBox.Show("Esto borra las imagenes actuales en memoria,\n\rDesea continuar", "Precaución", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            tblImagenes.Clear();
            imagenesCapturadas.Images.Clear();

            //Iniciar Proceso de Digitalización
            if (_twain.State == 4)
            {
                //_twain.CurrentSource.CapXferCount.Set(4);

                _stopScan  = false;
                frmPreview = new ScanPreview();
                frmPreview.StartPosition = FormStartPosition.CenterScreen;
                frmPreview.tblPreview.changeSizeThumb(new Size(96, 96));
                frmPreview.Show();

                if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
                {
                    // hide scanner ui if possible
                    if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                    }
                }
                else
                {
                    if (_twain.CurrentSource.Enable(SourceEnableMode.ShowUI, true, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                    }
                }
            }
        }
        private void btnDigitalizar_Click(object sender, EventArgs e)
        {
            if (imagenesCapturadas.Count > 0)
            {
                if (MessageBox.Show("Esto borra las imagenes actuales en memoria,\n\rDesea continuar", "Precaución", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
            }

            //Borrar el arbol actual e imagenes actuales
            tvTiposDocumentos.Nodes.Clear();
            tblImagenes.Clear();
            imagenesCapturadas.Clear();
            iImagenActual        = 0;
            iActualTipoDocumento = -1;

            foreach (ListViewItem elemento in lvDocumentos.Items)
            {
                if (elemento.Checked)
                {
                    iActualTipoDocumento = elemento.Index;
                    break;
                }
            }

            if (iActualTipoDocumento == -1)
            {
                MessageBox.Show("Debe de seleccionar al menos un tipo de documento para digitalizar");
                return;
            }

            //Generar el nuevo arbol y inicializar el objeto de imagenes Capturadas
            foreach (ListViewItem elemento in lvDocumentos.Items)
            {
                TreeNode nn = new TreeNode(elemento.Text);
                nn.Tag = elemento.Tag;
                tvTiposDocumentos.Nodes.Add(nn);
                imagenesCapturadas.Add(new ScannedImageList());
            }

            //Iniciar Proceso de Digitalización
            if (_twain.State == 4)
            {
                //_twain.CurrentSource.CapXferCount.Set(4);

                _stopScan  = false;
                frmPreview = new ScanPreview();
                frmPreview.StartPosition = FormStartPosition.CenterScreen;
                frmPreview.tblPreview.changeSizeThumb(new Size(96, 96));
                frmPreview.Show();

                if (_twain.CurrentSource.Capabilities.CapUIControllable.IsSupported)//.SupportedCaps.Contains(CapabilityId.CapUIControllable))
                {
                    // hide scanner ui if possible
                    if (_twain.CurrentSource.Enable(SourceEnableMode.NoUI, false, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                    }
                }
                else
                {
                    if (_twain.CurrentSource.Enable(SourceEnableMode.ShowUI, true, this.Handle) == ReturnCode.Success)
                    {
                        btnDigitalizar.Enabled = false;
                    }
                }
            }
        }