Exemple #1
0
 public DifferentCellSizeViewController(PSPDFDocument doc) : base(doc)
 {
     UpdateConfigurationWithoutReloading((builder) =>
     {
         builder.OverrideClass(new Class(typeof(PSPDFThumbnailGridViewCell)), new Class(typeof(HagerThumbnailGridViewCell)));
     });
 }
Exemple #2
0
 public CustomAnnotationProvider(PSPDFDocument doc)
 {
     document = doc;
     // add timer in a way so it works while we're dragging pages
     timer = NSTimer.CreateTimer(1, this, new Selector("timerFired:"), null, true);
     NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
 }
Exemple #3
0
 public CustomAnnotationProvider(PSPDFDocument doc)
 {
     document       = doc;
     timer          = new Timer(1000);
     timer.Elapsed += PickColor;
     timer.Start();
 }
Exemple #4
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 StringElement("PSPDFKit Instant", () => {
                        var instantExample = new InstantExampleViewController();
                        NavigationController.PushViewController(instantExample, true);
                    }),
                },
                new Section("Annotations")
                {
                    new StringElement("Annotations From Code", () => {
                        var documenturl = NSUrl.FromFilename(HackerMonthlyFile);
                        var pdfViewer   = new AnnotationsFromCodeViewController(documenturl);
                        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.CreateProgress("Preparing");
                        await status.PushAsync(true);
                        // 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(() => {
                            PSPDFProcessor.GeneratePdf(configuration: new PSPDFProcessorConfiguration(document),
                                                       securityOptions: new PSPDFDocumentSecurityOptions(password, password, PSPDFDocumentSecurityOptions.KeyLengthAutomatic, out var err),
                                                       fileUrl: tempPdf,
                                                       progressHandler: (currentPage, totalPages) => InvokeOnMainThread(() => status.Progress = (nfloat)currentPage / totalPages),
                                                       error: out var error);
                        });
                        InvokeOnMainThread(() => {
                            status.Pop(true, null);
                            var docToShow = new PSPDFDocument(tempPdf);
                            var pdfViewer = new PSPDFViewController(docToShow);
                            NavigationController.PushViewController(pdfViewer, true);
                        });
                    }),
        public KSAnnotationsListController(PSPDFDocument document, PSPDFViewController controller) : base(UITableViewStyle.Plain, null)
        {
            this.Title      = "Annotations";
            this.document   = document;
            this.controller = controller;
            this.Root       = new RootElement(string.Empty);

            //First cell is "loading..." cell and then it is larger cells
            this.Root.UnevenRows = true;
        }
        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());
            }
        }
Exemple #8
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;
        }
        public KSCombinedTabBarController(PSPDFViewController controller, PSPDFDocument document) : base()
        {
            var tocController = new PSPDFOutlineViewController(document, controller.Handle);

            tocController.Title = "TOC";

            var searchController = new PSPDFSearchViewController(document, controller);

            searchController.Title = "Search";

            var bookmarksController = new PSPDFBookmarkViewController(document);

            // PSPDFViewController implements PSPDFOutlineViewControllerDelegate as a protocol.
            bookmarksController.WeakDelegate = controller;
            bookmarksController.Title        = "Bookmarks";

            this.SetViewControllers(new UIViewController[] { tocController, searchController, bookmarksController }, false);
        }
Exemple #10
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);
        }
        private PSPDFDocument GenerateDocument()
        {
            try
            {
                // Build local pdf file path array
                List <Page> pageList = BooksOnDeviceAccessor.GetPages(book.ID);
                if (pageList != null && pageList.Count > 0)
                {
                    List <String> urlList = new List <String>();
                    foreach (Page page in pageList)
                    {
                        urlList.Add(DownloadedFilesCache.BuildCachedFilePath(page.URL));
                    }

                    // Generate NSData array for each pdf file
                    List <NSData> dataList = new List <NSData>();
                    foreach (String url in urlList)
                    {
                        NSData data = NSData.FromFile(url);
                        dataList.Add(data);
                    }

                    // Generate PSPDFDocument from NSData array
                    if (dataList.Count > 0)
                    {
                        PSPDFDocument document = PSPDFDocument.FromData(dataList.ToArray());
                        if (document != null)
                        {
                            document.Title = book.Title;
                            return(document);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("DashboardViewController - GenerateDocument: {0}", ex.ToString());
            }

            return(null);
        }
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            // Create the document
            PSPDFDocument document = new PSPDFDocument(NSUrl.FromFilename(Path.Combine(NSBundle.MainBundle.BundlePath, "hackermonthly12.pdf")));

            Console.WriteLine("Using document path: " + document.FileURL.Path);

            // Create the controller and encapsulate it into a UINavigationController for easier access.
            PSPDFViewController    pdfController = new PSPDFViewController(document);
            UINavigationController navController = new UINavigationController(pdfController);

            // If you have defined a root view controller, set it here:
            window.RootViewController = navController;

            // make the window visible
            window.MakeKeyAndVisible();

            return(true);
        }
Exemple #13
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);
        }
 public KSBookmarkParser(PSPDFDocument doc) : base(doc)
 {
     Console.WriteLine("KSBookmarkParser(PSPDFDocument)");
 }
 public PSCRotatePagePDFViewController(PSPDFDocument document) : base(document)
 {
 }
Exemple #16
0
 public PageViewController(Book book, PSPDFDocument document, PSPDFConfiguration configuration) : base(book, document, configuration)
 {
     this.book = book;
 }
Exemple #17
0
 public PlayGroundViewController(PSPDFDocument document) : base(document)
 {
 }
Exemple #18
0
 public KSExampleAnnotationViewController(PSPDFDocument doc) : base(doc)
 {
 }
Exemple #19
0
 public override void DidSelectPage(PSPDFThumbnailViewController thumbnailViewController, nuint page, PSPDFDocument document)
 {
     _pdfViewer.SelectPageForThumbnail(page);
 }
 public LinkEditorViewController(PSPDFDocument document, PSPDFConfiguration config) : base(document, config)
 {
 }
Exemple #21
0
 public KSKioskViewController(PSPDFDocument doc) : base(doc)
 {
     this.RightBarButtonItems = new PSPDFBarButtonItem[] { this.AnnotationButtonItem, this.BookmarkButtonItem, this.SearchButtonItem, this.OutlineButtonItem, this.ViewModeButtonItem };
 }
Exemple #22
0
        public KSCatalogViewController() : base(UITableViewStyle.Grouped, null)
        {
            PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Verbose;

            // Add some custom localization to ensure the bindings work.
            PSPDFKitGlobal.Localize("en", new NameValueCollection
            {
                { "Outline", "File Content" },
                { "Bookmarks", "Remember" }
            });

            // Call cache method to ensure the bindings for the cache work.
            var oPdfCache = PSPDFCache.SharedCache;

            oPdfCache.ClearCache( );

            PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Info;

            NSUrl samplesURL   = NSBundle.MainBundle.ResourceUrl.Append("Samples", true);
            NSUrl hackerMagURL = samplesURL.Append(HackerMagazineExample, false);
            NSUrl annotTestURL = samplesURL.Append(AnnotTestExample, false);


            this.Root = new RootElement("KSCatalogViewController")
            {
                new Section("Full example apps", "Can be used as a template for your own apps.")
                {
                    // PDF playground.
                    new StringElement("PSPDFViewController playground", () =>
                    {
                        var doc             = new PSPDFDocument(hackerMagURL);
                        var kioskController = new KSKioskViewController(doc);

                        kioskController.StatusBarStyleSetting = PSPDFStatusBarStyleSetting.Default;
                        this.NavigationController.PushViewController(kioskController, true);
                    }),
                },

                new Section("Customizing")
                {
                    // Combines various view controllers in a tab bar controller.
                    new StringElement("Combine search, TOC and bookmarks", () =>
                    {
                        var doc = new PSPDFDocument(hackerMagURL);

                        // Don't use PSPDFVieController directly but a subclass that allows attaching to ViewDidDisappear in order to clear
                        // the RightBarButtonItems property. Otherwise the tabBarBtn would keep a reference to the PSPDFViewController and the instances
                        // would never be freed.

                        //var controller = new PSPDFViewController(doc);
                        var controller = new KSKioskViewController(doc);
                        //controller.ViewDisappeared += (sender, args) => controller.RightBarButtonItems = new PSPDFBarButtonItem[0];

                        var tabBarController = new KSCombinedTabBarController(controller, doc);

                        var tabBarBtn = new KSBarButtonItem(controller)
                        {
                            Title = "UITabBarController",
                            Style = UIBarButtonItemStyle.Bordered
                        };
                        tabBarBtn.Clicked += (object sender, EventArgs e) => controller.PresentViewControllerModalOrPopover(tabBarController, true, false, true, tabBarBtn, null);

                        controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem, controller.BookmarkButtonItem, tabBarBtn };

                        var classDic = new NSMutableDictionary();
                        classDic.LowlevelSetObject(new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle);
                        classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle);
                        classDic.LowlevelSetObject(new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle);
                        doc.OverrideClassNames = classDic;

                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Shows an alert when tapping a link annotation.
                    new StringElement("Custom reaction on annotation links", () =>
                    {
                        var doc             = new PSPDFDocument(hackerMagURL);
                        var controller      = new PSPDFViewController(doc);
                        controller.Delegate = new KSCatchTappingLinkDelegate();
                        // There are link annotations on page 2.
                        controller.SetPageAnimated(1, false);
                        this.NavigationController.PushViewController(controller, true);
                    })
                },

                new Section("Subclassing")
                {
                    // Subclassing PSPDFAnnotationToolbar
                    new StringElement("Subclass annotation toolbar and drawing toolbar", () =>
                    {
                        var doc        = new PSPDFDocument(hackerMagURL);
                        var controller = new PSPDFViewController(doc);

                        var barButtons = new List <PSPDFBarButtonItem>(controller.RightBarButtonItems);
                        barButtons.Add(controller.AnnotationButtonItem);
                        controller.RightBarButtonItems = barButtons.ToArray();

                        var classDic = new NSMutableDictionary();
                        classDic.LowlevelSetObject(new Class(typeof(KSAnnotationToolbar)).Handle, new Class(typeof(PSPDFAnnotationToolbar)).Handle);
                        controller.OverrideClassNames = classDic;

                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Demonstrates always visible vertical toolbar.
                    new StringElement("Vertical always-visible annotation bar", () =>
                    {
                        var doc        = new PSPDFDocument(hackerMagURL);
                        var controller = new KSExampleAnnotationViewController(doc);

                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Tests potential binding issue when subclassing PSPDFViewController
                    new StringElement("PSPDFViewController with NULL document", () =>
                    {
                        var doc             = new PSPDFDocument(hackerMagURL);
                        var controller      = new KSNoDocumentPDFViewController();
                        controller.Document = doc;
                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Demonstrates capturing bookmark set/remove.
                    new StringElement("Capture bookmarks", () =>
                    {
                        var doc = new PSPDFDocument(hackerMagURL);

                        // Create an entry for overriding the default bookmark parser.
                        var classDic = new NSMutableDictionary();
                        classDic.LowlevelSetObject(new Class(typeof(KSBookmarkParser)).Handle, new Class(typeof(PSPDFBookmarkParser)).Handle);
                        doc.OverrideClassNames = classDic;

                        var controller = new PSPDFViewController(doc);
                        controller.RightBarButtonItems = new PSPDFBarButtonItem[]
                        {
                            controller.BookmarkButtonItem,
                            controller.SearchButtonItem,
                            controller.OutlineButtonItem,
                            controller.ViewModeButtonItem
                        };
                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Demonstrates custom annotation provider.
                    new StringElement("Custom Annotation Provider", () =>
                    {
                        var doc = new PSPDFDocument(hackerMagURL);
                        doc.SetDidCreateDocumentProviderBlock(delegate(PSPDFDocumentProvider documentProvider)
                        {
                            documentProvider.AnnotationParser.AnnotationProviders = new NSObject[]
                            {
                                new KSCustomAnnotationProvider(),
                                documentProvider.AnnotationParser.FileAnnotationProvider
                            };
                        });

                        var controller = new PSPDFViewController(doc);
                        this.NavigationController.PushViewController(controller, true);
                    }),

                    // Subclasses PDPFFileAnnotationProvider and injects additional annotations.
                    // This example demonstrates:
                    // * Make all built in annotations (those embedded in the PDF) immutable.
                    // * All annotations added by the user can be modified.
                    // * Workaround for PSPDFKit bug where the text of a non-editable annotation can still be changed.
                    // * Immediate callback if an annotation has been changed.
                    new StringElement("Subclass PSPDFFileAnnotationProvider", () =>
                    {
                        var controller = new PSPDFViewController();
                        var barButtons = new List <PSPDFBarButtonItem>(controller.RightBarButtonItems);
                        barButtons.Add(controller.AnnotationButtonItem);
                        controller.RightBarButtonItems = barButtons.ToArray();
                        controller.SetPageAnimated(2, false);

                        controller.PageMode        = PSPDFPageMode.Automatic;
                        controller.PageTransition  = PSPDFPageTransition.ScrollContinuous;
                        controller.ScrollDirection = PSPDFScrollDirection.Horizontal;

                        var classDic = new NSMutableDictionary();
                        classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle);
                        controller.OverrideClassNames = classDic;

                        this.NavigationController.PushViewController(controller, true);

                        var doc = new KSPDFDocument(hackerMagURL);
                        //var doc = new PSPDFDocument();
                        //var doc = new PSPDFDocument(annotTestURL);

                        // Create an entry for overriding the file annotation provider.
                        classDic = new NSMutableDictionary();
                        classDic.LowlevelSetObject(new Class(typeof(KSFileAnnotationProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle);
                        classDic.LowlevelSetObject(new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle);
                        classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle);
                        classDic.LowlevelSetObject(new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle);
                        doc.OverrideClassNames = classDic;

                        controller.Document = doc;
                    }),

                    // Set editable annotation types
                    new StringElement("Set editable annotation types", () =>
                    {
                        var doc        = new PSPDFDocument(hackerMagURL);
                        var controller = new PSPDFViewController(doc);
                        controller.RightBarButtonItems = new PSPDFBarButtonItem[]
                        {
                            controller.AnnotationButtonItem
                        };

                        var set = new NSMutableSet();
                        set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringInk);
                        set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringNote);
                        set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringUnderline);

                        controller.AnnotationButtonItem.AnnotationToolbar.EditableAnnotationTypes = set.ToNSOrderedSet();
                        this.NavigationController.PushViewController(controller, true);
                    })
                }
            };
        }
 public BookmarkViewController(PSPDFDocument document) : base(document)
 {
 }
 public static void RegisterOverrideClasses(NSKeyedUnarchiver unarchiver, PSPDFDocument document)
 {
     _RegisterOverrideClasses(unarchiver.Handle, document.Handle);
 }
Exemple #25
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 ThumbnailSelectionIssueViewController(PSPDFDocument doc) : base(doc)
 {
 }
Exemple #27
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     document = new PSPDFDocument(NSUrl.FromFilename(PdfFile));
 }
 public PSCSimpleDrawingPDFViewController(PSPDFDocument document) : base(document)
 {
 }
 public KSCombinedTabBarController(PSPDFViewController controller, PSPDFDocument document) : base()
 {
     this.controller = controller;
     this.document   = document;
     Console.WriteLine("CONTROLLER AND DOCUMENT!");
 }
Exemple #30
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);
                    })
                },
            };
        }