Ejemplo n.º 1
0
        private void BtnOpen6_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = "PDF File (Pdf Files|*.pdf|All files (*.*)|*.*";
            ofd.Multiselect = true;
            ofd.Title       = "My Image Browser";
            if (bc.iniC.labOutOpenFileDialog.Length > 0)
            {
                ofd.InitialDirectory = bc.iniC.labOutOpenFileDialog;
            }
            DialogResult dr = ofd.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                String[] file1 = ofd.FileNames;
                filename6    = file1[0];
                lbName6.Text = filename6;
                if (!bc.iniC.windows.ToLower().Equals("windowsxp"))
                {
                    C1PdfDocumentSource pds = new C1PdfDocumentSource();
                    pds.LoadFromFile(filename6);
                    fvLabOut6.DocumentSource = pds;
                }
                tC.SelectedTab = tabLabOut6;
            }
        }
        private void FlexViewer_OpenAction(object sender, EventArgs e)
        {
            fv.FocusPane();

            if (!openFileDialog.ShowDialog().Value)
            {
                return;
            }

            // load document
            while (true)
            {
                try
                {
                    pdfDocumentSource.LoadFromFile(openFileDialog.FileName);
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(openFileDialog.FileName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            fv.CloseActionEnabled = true;
        }
Ejemplo n.º 3
0
        private void LoadSourcePlainText(bool startUp)
        {
            if (textBox3.Text.Substring(textBox3.Text.Length - 4) == ".pdf")
            {
                using (var pdfSource = new C1PdfDocumentSource())
                {
                    pdfSource.LoadFromFile(textBox3.Text);

                    using (var ctx = new C1DXTextMeasurementContext())
                    {
                        textBox4.Text = pdfSource.GetWholeDocumentRange(ctx).GetText();
                    }
                }
                if (!startUp)
                {
                    MessageBox.Show("Plain text from specified .pdf file loaded sucessfully!", "C1TextParser Winforms Edition", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (textBox3.Text.Substring(textBox3.Text.Length - 5) == ".docx")
                {
                    using (var plainTextStream = new MemoryStream())
                    {
                        using (C1.C1Word.C1WordDocument doc = new C1.C1Word.C1WordDocument())
                        {
                            doc.Load(textBox3.Text);
                            doc.Save(plainTextStream, C1.C1Word.FileFormat.Text);
                            var plainTextStream1 = new MemoryStream((plainTextStream as MemoryStream).ToArray());
                            plainTextStream1.Position = 0;
                            var reader = new StreamReader(plainTextStream1);
                            textBox4.Text = reader.ReadToEnd();

                            reader.Dispose();
                            plainTextStream.Dispose();
                            plainTextStream1.Dispose();
                        }
                    }
                    if (!startUp)
                    {
                        MessageBox.Show("Plain text from specified .docx file loaded sucessfully!", "C1TextParser Winforms Edition", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    var fileStream = File.OpenRead(textBox3.Text);
                    var reader     = new StreamReader(fileStream);
                    textBox4.Text = reader.ReadToEnd();

                    fileStream.Dispose();
                    reader.Dispose();

                    if (!startUp)
                    {
                        MessageBox.Show("Text from specified file loaded sucessfully!", "C1TextParser Winforms Edition", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            fv.OpenAction  += FlexViewer_OpenAction;
            fv.CloseAction += FlexViewer_CloseAction;
            this.Loaded    += MainWindow_Loaded;

            fv.DocumentSource = pdfDocumentSource;
            if (File.Exists(@"..\..\DefaultDocument.pdf"))
            {
                pdfDocumentSource.LoadFromFile(@"..\..\DefaultDocument.pdf");
            }
            else
            {
                fv.CloseActionEnabled = false;
            }
        }
Ejemplo n.º 5
0
        private void btnExecute_Click(object sender, RoutedEventArgs e)
        {
            if (fpFile.SelectedFile == null)
            {
                MessageBox.Show(this, "Please select a PDF file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // load document
            while (true)
            {
                try
                {
                    pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            // execute action
            if (cbAction.SelectedIndex == 0)
            {
                DoPrint(pdfDocumentSource);
            }
            else
            {
                DoExport(pdfDocumentSource, (ExportProvider)((C1ComboBoxItem)cbAction.SelectedItem).Tag);
            }
        }
Ejemplo n.º 6
0
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            // load document
            while (true)
            {
                try
                {
                    if (fpFile.SelectedFile == null)
                    {
                        using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(@"PdfDocumentSourceSamples.Resources.DefaultDocument.pdf"))
                            pdfDocumentSource.LoadFromStream(stream);
                    }
                    else
                    {
                        pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    }
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            //
            OutputRange outputRange;

            if (rbtnPagesAll.IsChecked.Value)
            {
                outputRange = OutputRange.All;
            }
            else
            {
                if (!OutputRange.TryParse(tbPagesRange.Text, out outputRange))
                {
                    MessageBox.Show("Invalid range of pages.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            // execute action
            ExportProvider ep = (ExportProvider)((C1ComboBoxItem)cbExportFilter.SelectedItem).Tag;

            saveFileDialog.DefaultExt = "." + ep.DefaultExtension;
            saveFileDialog.FileName   = (fpFile.SelectedFile == null ? "DefaultDocument" : System.IO.Path.GetFileName(fpFile.SelectedFile.FullName)) + "." + ep.DefaultExtension;
            saveFileDialog.Filter     = String.Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*", ep.FormatName, ep.DefaultExtension);
            bool?dr = saveFileDialog.ShowDialog();

            if (!dr.HasValue || !dr.Value)
            {
                return;
            }

            try
            {
                var exporter = ep.NewExporter();
                exporter.ShowOptions = false;
                exporter.Preview     = true;
                exporter.FileName    = saveFileDialog.FileName;
                exporter.Range       = outputRange;
                pdfDocumentSource.Export(exporter);
                MessageBox.Show("Document was successfully exported.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            if (cbPrinter.SelectedItem == null)
            {
                MessageBox.Show("Please select a printer.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // load document
            while (true)
            {
                try
                {
                    if (fpFile.SelectedFile == null)
                    {
                        using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(@"PdfDocumentSourceSamples.Resources.DefaultDocument.pdf"))
                            pdfDocumentSource.LoadFromStream(stream);
                    }
                    else
                    {
                        pdfDocumentSource.LoadFromFile(fpFile.SelectedFile.FullName);
                    }
                    break;
                }
                catch (PdfPasswordException)
                {
                    var password = PasswordWindow.DoEnterPassword(fpFile.SelectedFile.FullName);
                    if (password == null)
                    {
                        return;
                    }
                    pdfDocumentSource.Credential.Password = password;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            //
            OutputRange outputRange;

            if (rbtnPagesAll.IsChecked.Value)
            {
                outputRange = OutputRange.All;
            }
            else
            {
                if (!OutputRange.TryParse(tbPagesRange.Text, out outputRange))
                {
                    MessageBox.Show("Invalid range of pages.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            try
            {
                C1PrintOptions po = new C1PrintOptions();
                po.PrintQueue  = (PrintQueue)((C1ComboBoxItem)cbPrinter.SelectedItem).Tag;
                po.OutputRange = outputRange;
                pdfDocumentSource.Print(po);
                MessageBox.Show("Document was successfully printed.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }