Example #1
0
        //Merge PDFs
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            FormCreationProgress fcp = new FormCreationProgress();

            fcp.Command = FormCreationProgress.Commands.Split;
            if (sender == this.toolStripButtonMergePDF)
            {
                fcp.Command = FormCreationProgress.Commands.Merge;
            }

            if (fcp.Command == FormCreationProgress.Commands.Merge)
            {
                if (this.Project.AlwaysAskDestinationFile || string.IsNullOrEmpty(this.Project.Target))
                {
                    if (this.saveFileDialogTarget.ShowDialog() == DialogResult.OK)
                    {
                        this.Project.Target     = this.saveFileDialogTarget.FileName;
                        this.textBoxTarget.Text = this.Project.Target;
                        this.SomethingChanged();
                    }
                    else
                    {
                        return;
                    }
                }
                if (!this.Project.OverwriteDestinationWithoutPrompt && File.Exists(this.Project.Target))
                {
                    if (MessageBox.Show(string.Format("Overwrite {0}?", Path.GetFileName(this.Project.Target))
                                        , "Target file already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                                        , MessageBoxDefaultButton.Button2) == DialogResult.No)
                    {
                        return;
                    }
                }
            }

            if (fcp.Command == FormCreationProgress.Commands.Split)
            {
                if (MessageBox.Show("Are you sure?", "Split PDF", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return;
                }
            }

            try
            {
                fcp.Project = this.Project;
                DialogResult result = fcp.ShowDialog();
                switch (result)
                {
                case DialogResult.Cancel:
                    try
                    {
                        File.Delete(this.Project.TempTarget);
                    }
                    catch
                    { }
                    break;

                case DialogResult.OK:
                    if (fcp.Command == FormCreationProgress.Commands.Merge)
                    {
                        if (this.Project.OpenWithDefaultReaderAfterCreation)
                        {
                            Process.Start(this.Project.Target);
                        }
                    }
                    if (fcp.Command == FormCreationProgress.Commands.Split)
                    {
                        MessageBox.Show("PDF split", "Split Successfull.");
                    }
                    break;
                }
            }
            catch (Exception e2)
            {
                fcp.Close();
                MessageBox.Show(e2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            FormCreationProgress fcp = new FormCreationProgress();
            fcp.Command = FormCreationProgress.Commands.Split;
            if (sender == this.toolStripButtonMergePDF)
            {
                fcp.Command = FormCreationProgress.Commands.Merge;
            }

            if (fcp.Command == FormCreationProgress.Commands.Merge)
            {
                if (this.Project.AlwaysAskDestinationFile
                    ||
                    string.IsNullOrEmpty(this.Project.Target)
                    )
                {
                    if (this.saveFileDialogTarget.ShowDialog() == DialogResult.OK)
                    {
                        this.Project.Target = this.saveFileDialogTarget.FileName;
                        this.textBoxTarget.Text = this.Project.Target;
                        this.SomethingChanged();
                    }
                    else
                    {
                        return;
                    }
                }
                if (!this.Project.OverwriteDestinationWithoutPrompt
               &&
               File.Exists(this.Project.Target))
                {
                    if (MessageBox.Show(string.Format("Overwrite {0}?", Path.GetFileName(this.Project.Target))
                        , "Target file already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question
                        , MessageBoxDefaultButton.Button2) == DialogResult.No)
                        return;
                }
            }

            if (fcp.Command == FormCreationProgress.Commands.Split)
            {
                if (MessageBox.Show("Are you sure?", "Split PDF", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return;
                }
            }                      

            try
            {                
                fcp.Project = this.Project;
                DialogResult result= fcp.ShowDialog();
                switch (result)
                {
                    case DialogResult.Cancel:
                        try
                        {
                            File.Delete(this.Project.TempTarget);
                        }
                        catch
                        { }
                        break;
                    case DialogResult.OK:
                        if (fcp.Command == FormCreationProgress.Commands.Merge)
                        {
                            if (this.Project.OpenWithDefaultReaderAfterCreation)
                            {
                                Process.Start(this.Project.Target);
                            }
                        }
                        if (fcp.Command == FormCreationProgress.Commands.Split)
                        {
                            MessageBox.Show("Split Terminated.");
                        }
                        break;
                }               

            }
            catch (Exception e2)
            {
                fcp.Close();
                MessageBox.Show(e2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }