Ejemplo n.º 1
0
        private void DoExport(C1PdfDocumentSource pds, ExportProvider ep)
        {
            saveFileDialog.DefaultExt = "." + ep.DefaultExtension;
            saveFileDialog.FileName   = 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(this);

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

            try
            {
                var exporter = ep.NewExporter();
                exporter.ShowOptions = false;
                exporter.Preview     = true;
                exporter.FileName    = saveFileDialog.FileName;
                pds.Export(exporter);
                MessageBox.Show(this, "Document was successfully exported.", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void DoExport(C1PdfDocumentSource pds, ExportProvider ep)
        {
            saveFileDialog1.DefaultExt = "." + ep.DefaultExtension;
            saveFileDialog1.FileName   = Path.GetFileName(tbFile.Text) + "." + ep.DefaultExtension;
            saveFileDialog1.Filter     = string.Format("{0} (*.{1})|*.{1}|All files (*.*)|*.*", ep.FormatName, ep.DefaultExtension);
            if (saveFileDialog1.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try
            {
                var exporter = ep.NewExporter();
                exporter.ShowOptions = false;
                exporter.FileName    = saveFileDialog1.FileName;
                if (exporter.ShowOptionsDialog())
                {
                    pds.Export(exporter);
                    MessageBox.Show(this, "Document was successfully exported.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
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);
            }
        }