PdfPassword
-------------------------------------------------------------------------------
Shows how to create and view password-protected Pdf files.

The sample has two panes. The left pane contains a Grid element with some
arbitrary Xaml content. The "Save Pdf..." button above the left pane allows
users to save that content as a password-protected Pdf file. The code looks
like this:

<code>
    var dlg = new SaveFileDialog();
    dlg.Filter = "Pdf files (*.pdf)|*.pdf";
    if (dlg.ShowDialog().Value)
    {
        using (var stream = dlg.OpenFile())
        {
            var pdf = new C1.Silverlight.Pdf.C1PdfDocument();
            pdf.Security.UserPassword = "thePassword";
            pdf.DrawElement(_contentGrid, pdf.PageRectangle, ContentAlignment.MiddleCenter, Stretch.Uniform);
            pdf.Save(stream);
            MessageBox.Show("Protected pdf saved. Password is 'thePassword'.");
        }
    }
</code>

The interesting part of the code is the piece that sets the Security.UserPassword property
of the C1PdfDocument. In order to open the document in any Pdf viewer, users will have to 
provide the password.

The right pane contains a C1PdfViewer control. Above it, there is an "Open Pdf..." button 
that allows users to select any Pdf file. Once a file is selected, the sample tries to 
open it. If the file is protected, the C1PdfViewer will throw an exception. The sample 
catches this exception and prompts the user for a password, which is used for opening the
file. The code looks like this:

<code>
    void LoadProtectedDocument(System.IO.MemoryStream stream, string password)
    {
        try
        {
            stream.Position = 0;
            _viewer.LoadDocument(stream, password);
        }
        catch (Exception x)
        {
            if (x.Message.IndexOf("password") > -1)
            {
                var msg = "This file seems to be password-protected.\r\nPlease provide the password and try again.";
                C1.Silverlight.C1PromptBox.Show(msg, "Enter Password", (text, result) =>
                    {
                        if (result == MessageBoxResult.OK)
                        {
                            // try again using the password provided by the user
                            LoadProtectedDocument(stream, text);
                        }
                    });
            }
            else
            {
                throw;
            }
        }
    }
</code>

The method requires that you load the Pdf document into a stream. This is necessary because you may
not be able to re-open arbitrary files unless they were selected by an OpenFileDialog.

Normally, the method is called with null for a password. If the Pdf file is protected, the C1PdfViewer
will throw an exception. In this case, the exception will be caught and the user will be prompted
for a password (using the C1PromptBox control). The LoadProtectedDocument method is then called 
recursively, using the original stream and the password provided by the user.
