public override void CommonInit(PSPDFDocument document, PSPDFConfiguration configuration)
        {
            base.CommonInit(document, configuration);

            // Use our custom method when tapping the bookmark button
            this.BookmarkButtonItem.Clicked += (sender, args) => {
                NameBookmark();
            };

            this.NavigationItem.SetRightBarButtonItems(new[] { this.ThumbnailsButtonItem, this.OutlineButtonItem, this.SearchButtonItem, this.BookmarkButtonItem }, PSPDFViewMode.Document, false);
        }
        async private void LoadPageViewController(String pageID)
        {
            try
            {
                LoadingView.Show("Loading", "Please wait while we're loading " + book.Title + "...", false);

                int           pageNumber = BooksOnDeviceAccessor.GetPage(book.ID, pageID).PageNumber;
                PSPDFDocument document   = await eBriefingService.Run(() => GenerateDocument());

                if (document == null)
                {
                    LoadingView.Hide();

                    AlertView.Show(StringRef.alert, "We're sorry, but we could not open the document.", StringRef.ok);
                }
                else
                {
                    PSPDFConfiguration configuration = PSPDFConfiguration.FromConfigurationBuilder(delegate(PSPDFConfigurationBuilder builder)
                    {
                        builder.CreateAnnotationMenuEnabled = builder.ShouldHideStatusBar = builder.ShouldCacheThumbnails = false;
                        builder.ShouldHideStatusBarWithHUD  = builder.AlwaysBouncePages = builder.SmartZoomEnabled = builder.DoublePageModeOnFirstPage
                                                                                                                         = builder.ShouldHideHUDOnPageChange = builder.ShouldHideNavigationBarWithHUD = true;
                        builder.HUDViewMode      = PSPDFHUDViewMode.Automatic;
                        builder.HUDViewAnimation = PSPDFHUDViewAnimation.Fade;
                        builder.ThumbnailBarMode = PSPDFThumbnailBarMode.None;
                        builder.RenderingMode    = PSPDFPageRenderingMode.Render;
                        builder.PageTransition   = PSPDFPageTransition.Curl;
                        builder.ShouldAskForAnnotationUsername = false;
                        builder.AllowBackgroundSaving          = false;
                        builder.OverrideClass(new Class(typeof(PSPDFHUDView)), new Class(typeof(CustomPSPDFHUDView)));
                        builder.OverrideClass(new Class(typeof(PSPDFViewControllerDelegate)), new Class(typeof(CustomPSPDFViewControllerDelegate)));
                        builder.OverrideClass(new Class(typeof(PSPDFBarButtonItem)), new Class(typeof(CustomPSPDFBarButtonItem)));
                    });

                    PageViewController pvc = new PageViewController(book, document, configuration);
                    pvc.Delegate = new CustomPSPDFViewControllerDelegate();
                    pvc.Page     = (nuint)pageNumber - 1;

                    pvc.AddAnnotations();

                    LoadingView.Hide();
                    this.NavigationController.PushViewController(pvc, true);
                }
            }
            catch (Exception ex)
            {
                LoadingView.Hide();

                Logger.WriteLineDebugging("DashboardViewController - LoadPageViewController: {0}", ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public CustomPSPDFViewController(Book book, PSPDFDocument document, PSPDFConfiguration configuration) : base(document, configuration)
        {
            this.book = book;

            this.ExtendedLayoutIncludesOpaqueBars            = true;
            this.ThumbnailController.FilterSegment.TintColor = UIColor.White;

            this.Document.AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled;
            this.Document.AllowsCopying      = false;
            this.Document.DiskCacheStrategy  = PSPDFDiskCacheStrategy.Nothing;

//            this.ThumbnailController.StickyHeaderEnabled = true;
//            this.ThumbnailController.CollectionView.ContentInset = new UIEdgeInsets(80, 0, 0, 0);
//            this.ThumbnailController.ExtendedLayoutIncludesOpaqueBars = false;
        }
Ejemplo n.º 4
0
        public override void DidMoveToParentViewController(UIViewController parent)
        {
            if (pdfController == null)
            {
                var containerController = parent;
                var document            = new PSPDFDocument(NSUrl.FromFilename(PdfFilePath));
                pdfController = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                    builder.UseParentNavigationBar = true;
                    builder.ShouldHideStatusBarWithUserInterface = true;
                }));

                containerController.AddChildViewController(pdfController);
                pdfController.View.Frame            = containerController.View.Bounds;                                      // make the controller fullscreen in your container controller
                pdfController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; // ensure the controller resizes along with your container controller
                containerController.View.AddSubview(pdfController.View);
                return;
            }

            base.DidMoveToParentViewController(parent);
        }
Ejemplo n.º 5
0
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            var containerController = ViewController;
            var document            = new PSPDFDocument(NSUrl.FromFilename(PdfFilePath));
            var pdfController       = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                builder.UseParentNavigationBar = true;
                builder.ShouldHideStatusBarWithUserInterface = true;
            }));

            var navController = new UINavigationController(pdfController);

            // just style the controller a little
            SetNiceColors(navController);

            // Since we are using Xamarin Forms navigation we need to pop out using it, so we are using `Element` to tell X.F that we are done and pop us out.
            var menuItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, ev) => {
                // You can add some logic here before the controller is closed
                Console.WriteLine("Done with the document.");

                // Let PDFViewer object know that we want to pop
                Element.Navigation.PopModalAsync();
            });

            pdfController.NavigationItem.LeftBarButtonItem = menuItem;

            containerController.AddChildViewController(navController);
            navController.View.Frame            = containerController.View.Bounds;                                      // make the controller fullscreen in your container controller
            navController.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; // ensure the controller resizes along with your container controller
            containerController.View.AddSubview(navController.View);

            pdfController.DidMoveToParentViewController(navController);
        }
Ejemplo n.º 6
0
 public PageViewController(Book book, PSPDFDocument document, PSPDFConfiguration configuration) : base(book, document, configuration)
 {
     this.book = book;
 }
Ejemplo n.º 7
0
        public DVCMenu() : base(UITableViewStyle.Grouped, null)
        {
            Root = new RootElement(PSPDFKitGlobal.VersionString)
            {
                new Section("Start here")
                {
                    new StringElement("PSPDFViewController Playground", () => {
                        var pdfViewer = new PlayGroundViewController(NSUrl.FromFilename(PSPDFKitFile));
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
                new Section("Annotations")
                {
                    new StringElement("Annotations From Code", () => {
                        // we use a NSData document here but it'll work even better with a file-based variant.
                        NSError err;
                        var documentData = NSData.FromUrl(NSUrl.FromFilename(HackerMonthlyFile), NSDataReadingOptions.Mapped, out err);
                        var pdfViewer    = new AnnotationsFromCodeViewController(documentData);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                },
                new Section("Password / Security", "Password is: test123")
                {
                    new StringElement("Password Preset", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(ProtectedFile));
                        document.Unlock("test123");
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Password Not Preset", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(ProtectedFile));
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Create Password Protected PDF", async() => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var status   = PSPDFStatusHUDItem.GetProgressHud("Preparing");
                        status.Push(true, null);
                        // Create temp file and password
                        var tempPdf  = NSUrl.FromFilename(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf"));
                        var password = "******";

                        // We start a new task so this executes on a separated thread since it is a hevy task and we don't want to block the UI
                        await Task.Factory.StartNew(() => {
                            NSError err;
                            PSPDFProcessor.GeneratePdf(configuration: new PSPDFProcessorConfiguration(document),
                                                       saveOptions: new PSPDFProcessorSaveOptions(password, password, PSPDFProcessorSaveOptions.KeyLengthAutomatic),
                                                       fileUrl: tempPdf,
                                                       progressHandler: (currentPage, totalPages) => InvokeOnMainThread(() => status.Progress = (nfloat)currentPage / totalPages),
                                                       error: out err);
                        });
                        InvokeOnMainThread(() => {
                            status.Pop(true, null);
                            var docToShow = new PSPDFDocument(tempPdf);
                            var pdfViewer = new PSPDFViewController(docToShow);
                            NavigationController.PushViewController(pdfViewer, true);
                        });
                    }),
                },
                new Section("Subclassing", "Examples how to subclass PSPDFKit.")
                {
                    new StringElement("Annotation Link Editor", () => {
                        var document      = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var editableTypes = new NSSet <NSString> (
                            PSPDFAnnotationString.Link,                             // Important!!
                            PSPDFAnnotationString.Highlight,
                            PSPDFAnnotationString.Underline,
                            PSPDFAnnotationString.Squiggly,
                            PSPDFAnnotationString.StrikeOut,
                            PSPDFAnnotationString.Note,
                            PSPDFAnnotationString.FreeText,
                            PSPDFAnnotationString.Ink,
                            PSPDFAnnotationString.Square,
                            PSPDFAnnotationString.Circle,
                            PSPDFAnnotationString.Stamp);

                        var pdfViewer = new LinkEditorViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.EditableAnnotationTypes = editableTypes;
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Capture Bookmarks", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        document.BookmarkManager.Provider = new IPSPDFBookmarkProvider [] { new CustomBookmarkProvider() };
                        var pdfViewer = new PSPDFViewController(document);
                        pdfViewer.NavigationItem.RightBarButtonItems = new [] { pdfViewer.SearchButtonItem, pdfViewer.OutlineButtonItem, pdfViewer.BookmarkButtonItem };
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Change link background color to red", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var pdfViewer = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.OverrideClass(typeof(PSPDFLinkAnnotationView), typeof(CustomLinkAnnotationView));
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Custom AnnotationProvider", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        document.DidCreateDocumentProviderHandler = (documentProvider => {
                            documentProvider.AnnotationManager.AnnotationProviders = new IPSPDFAnnotationProvider[] { new CustomAnnotationProvider(document), documentProvider.AnnotationManager.FileAnnotationProvider };
                        });
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Custom Document", () => {
                        var pdfViewer      = new PSPDFViewController();
                        var document       = new CustomPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        pdfViewer.Document = document;
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
                new Section("PSPDFViewController Customization")
                {
                    new StringElement("Custom Google Text Selection Menu", () => {
                        var pdfViewer = new PSCustomTextSelectionMenuController {
                            Document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile))
                        };
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Simple Drawing Button", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile))
                        {
                            AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled
                        };
                        var pdfViewer = new PSCSimpleDrawingPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Stylus Support", () => {
                        // TODO: Stylus Support
                        // Uncomment all the needed driver lines once you added the corresponding Dll's.
                        //
                        // Please visit PSPDFKit support page for more information
                        // https://pspdfkit.com/guides/ios/current/other-languages/xamarin-stylus-support/
                        //
                        PSPDFKitGlobal.SharedInstance.StylusManager.AvailableDriverClasses = new NSOrderedSet <Class> (
                            //new Class (typeof (PSPDFKit.iOS.StylusSupport.PSPDFFiftyThreeStylusDriver)),
                            //new Class (typeof (PSPDFKit.iOS.StylusSupport.PSPDFJotTouchStylusDriver)),
                            //new Class (typeof (PSPDFKit.iOS.StylusSupport.PSPDFWacomStylusDriver)),
                            //new Class (typeof (PSPDFKit.iOS.StylusSupport.PSPDFPogoStylusDriver))
                            );

                        var document  = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var pdfViewer = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.OverrideClass(typeof(PSPDFAnnotationToolbar), typeof(PSCStylusEnabledAnnotationToolbar));
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
            };
        }
Ejemplo n.º 8
0
        public DVCMenu() : base(UITableViewStyle.Grouped, null)
        {
            Root = new RootElement(PSPDFKitGlobal.SharedInstance.Version)
            {
                new Section("Different cell size")
                {
                    new StringElement("Hager document", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(PdfHagerFile));
                        var pdfViewer = new DifferentCellSizeViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("PsPdfKit document", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(PSPDFKitFile));
                        var pdfViewer = new DifferentCellSizeViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },

                new Section("Page selection from Thumbnail View Controller")
                {
                    new StringElement("Custom delegate", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(PdfHagerFile));
                        var pdfViewer = new ThumbnailSelectionIssueViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },

                new Section("Start here")
                {
                    new StringElement("PSPDFViewController Playground", () => {
                        var pdfViewer = new PlayGroundViewController(NSUrl.FromFilename(PSPDFKitFile));
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
                new Section("Annotations")
                {
                    new StringElement("Annotations From Code", () => {
                        // we use a NSData document here but it'll work even better with a file-based variant.
                        NSError err;
                        var documentData = NSData.FromUrl(NSUrl.FromFilename(HackerMonthlyFile), NSDataReadingOptions.Mapped, out err);
                        var pdfViewer    = new AnnotationsFromCodeViewController(documentData);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                },
                new Section("Password / Security", "Password is: test123")
                {
                    new StringElement("Password Preset", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(ProtectedFile));
                        document.Unlock("test123");
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Password Not Preset", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(ProtectedFile));
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Create Password Protected PDF", async() => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var status   = PSPDFStatusHUDItem.GetProgressHud("Preparing");
                        status.Push(true, null);
                        // Create temp file and password
                        var tempPdf  = NSUrl.FromFilename(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf"));
                        var password = "******";

                        // We start a new task so this executes on a separated thread since it is a hevy task and we don't want to block the UI
                        await Task.Factory.StartNew(() => {
                            NSError err;
                            PSPDFProcessor.GeneratePdf(configuration: new PSPDFProcessorConfiguration(document),
                                                       saveOptions: new PSPDFProcessorSaveOptions(password, password, NSNumber.FromInt32(128)),
                                                       fileUrl: tempPdf,
                                                       progressHandler: (currentPage, totalPages) => InvokeOnMainThread(() => status.Progress = (nfloat)currentPage / totalPages),
                                                       error: out err);
                        });
                        InvokeOnMainThread(() => {
                            status.Pop(true, null);
                            var docToShow = new PSPDFDocument(tempPdf);
                            var pdfViewer = new PSPDFViewController(docToShow);
                            NavigationController.PushViewController(pdfViewer, true);
                        });
                    }),
                },
                new Section("Subclassing", "Examples how to subclass PSPDFKit.")
                {
                    new StringElement("Annotation Link Editor", () => {
                        var document      = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var editableTypes = new NSSet <NSString> (
                            PSPDFAnnotationString.Link,                             // Important!!
                            PSPDFAnnotationString.Highlight,
                            PSPDFAnnotationString.Underline,
                            PSPDFAnnotationString.Squiggly,
                            PSPDFAnnotationString.StrikeOut,
                            PSPDFAnnotationString.Note,
                            PSPDFAnnotationString.FreeText,
                            PSPDFAnnotationString.Ink,
                            PSPDFAnnotationString.Square,
                            PSPDFAnnotationString.Circle,
                            PSPDFAnnotationString.Stamp);

                        var pdfViewer = new LinkEditorViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.EditableAnnotationTypes = editableTypes;
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Capture Bookmarks", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        document.OverrideClass(new Class(typeof(PSPDFBookmarkParser)), new Class(typeof(CustomBookmarkParser)));
                        var pdfViewer = new PSPDFViewController(document);
                        pdfViewer.NavigationItem.RightBarButtonItems = new [] { pdfViewer.SearchButtonItem, pdfViewer.OutlineButtonItem, pdfViewer.BookmarkButtonItem };
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Change link background color to red", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        // Note: You can also globally change the color using:
                        // PSPDFLinkAnnotationView.SetGlobalBorderColor = UIColor.Green;
                        // We don't use this in the example here since it would change the color globally for all examples.
                        var pdfViewer = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.OverrideClass(new Class(typeof(PSPDFLinkAnnotationView)), new Class(typeof(CustomLinkAnnotationView)));
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Custom AnnotationProvider", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        document.DidCreateDocumentProviderHandler = (documentProvider => {
                            documentProvider.AnnotationManager.AnnotationProviders = new IPSPDFAnnotationProvider[] { new CustomAnnotationProvider(document), documentProvider.AnnotationManager.FileAnnotationProvider };
                        });
                        var pdfViewer = new PSPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Custom Document", () => {
                        var pdfViewer      = new PSPDFViewController();
                        var document       = new CustomPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        pdfViewer.Document = document;
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
                new Section("PSPDFViewController Customization")
                {
                    new StringElement("Custom Google Text Selection Menu", () => {
                        var pdfViewer = new PSCustomTextSelectionMenuController {
                            Document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile))
                        };
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Simple Drawing Button", () => {
                        var document = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile))
                        {
                            AnnotationSaveMode = PSPDFAnnotationSaveMode.Disabled
                        };
                        var pdfViewer = new PSCSimpleDrawingPDFViewController(document);
                        NavigationController.PushViewController(pdfViewer, true);
                    }),
                    new StringElement("Stylus Support", () => {
                        var document  = new PSPDFDocument(NSUrl.FromFilename(HackerMonthlyFile));
                        var pdfViewer = new PSPDFViewController(document, PSPDFConfiguration.FromConfigurationBuilder((builder) => {
                            builder.OverrideClass(new Class(typeof(PSPDFAnnotationToolbar)), new Class(typeof(PSCStylusEnabledAnnotationToolbar)));
                        }));
                        NavigationController.PushViewController(pdfViewer, true);
                    })
                },
            };
        }
 public LinkEditorViewController(PSPDFDocument document, PSPDFConfiguration config) : base(document, config)
 {
 }