Ejemplo n.º 1
0
        private async void FileAddButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            if (!StorageApplicationPermissions.FutureAccessList.ContainsItem(App.RECENT_FILE_DIRECTORY_TOKEN))
            {
                fileOpenPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            }
            fileOpenPicker.FileTypeFilter.Add(".pdf");
            StorageFile selectedFile = await fileOpenPicker.PickSingleFileAsync();;

            if (selectedFile != null)
            {
                StorageFolder parentfolder = await selectedFile.GetParentAsync();

                if (parentfolder != null)
                {
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace(App.RECENT_FILE_DIRECTORY_TOKEN, parentfolder);
                }

                InternalFile internalFile = await InternalFile.LoadInternalFileAsync(selectedFile);

                if (internalFile.Decrypted)
                {
                    loadedFile           = internalFile;
                    TotalPageNumber.Text = loadedFile.PageCount.ToString();
                    selectedPageRange    = new PageRange(loadedFile.Document);

                    loadedFileList = new ObservableCollection <InternalFile>();
                    loadedFileList.Add(loadedFile);
                    loadedFilesView.ItemsSource = loadedFileList;
                    PageRangeInput.Text         = String.Empty;

                    // load the file separately for rendering
                    try
                    {
                        renderDocument = await PdfDocument.LoadFromFileAsync(loadedFile.File);

                        renderedPageNumber = 1;
                        RenderedPagePreviewFrame.Navigate(typeof(RenderedPagePreview), renderDocument);
                        renderedPagePreview = RenderedPagePreview.Current;
                        SetCurrentPageLabel();
                    }
                    catch (Exception)
                    {
                        rootPage.NotifyUser("Document is not a valid PDF.", NotifyType.ErrorMessage);
                    }
                }
                else
                {
                    ToolPage.Current.NotifyUser("The selected file cannot be loaded since it is password-protected.", NotifyType.ErrorMessage);
                }
            }

            if (loadedFileList.Count > 0)
            {
                SelectPanel.Visibility = Visibility.Visible;
            }
            else
            {
                SelectPanel.Visibility = Visibility.Collapsed;
            }
        }