Example #1
0
        protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == requestOpenDocument && resultCode == Result.Ok && data != null)
            {
                Android.Net.Uri uri = null;

                // Some URIs can be opened directly, including local filesystem, app assets, and content provider URIs.
                if (!PSPDFKitGlobal.IsOpenableUri(this, data.Data))
                {
                    // The Uri cannot be directly opened. Download the PDF document from the uri, for local access.
                    AndHUD.Shared.Show(this, "Downloading file", 0);

                    var docPath          = Path.Combine(ApplicationContext.CacheDir.ToString(), DateTime.Now.Ticks.ToString() + ".pdf");
                    var progressReporter = new Progress <DownloadBytesProgress> ();
                    progressReporter.ProgressChanged += (s, args) => AndHUD.Shared.Show(this, "Downloading file", (int)(100 * args.PercentComplete));
                    uri = await Utils.DownloadDocument(this, data.Data, docPath, progressReporter);

                    AndHUD.Shared.Dismiss(this);
                }
                else
                {
                    uri = data.Data;
                }

                var intent = PdfActivityIntentBuilder
                             .FromUri(this, uri)
                             .Configuration(configuration)
                             .Build();

                StartActivity(intent);
                Finish();
            }
        }
        protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == RequestOpenDocument && resultCode == Result.Ok && data != null)
            {
                // Only document accessible as files are openable directly with PSPDFKit so we have to
                // transfer other documents to application cache
                if (!PSPDFKitGlobal.IsOpenableUri(this, data.Data))
                {
                    AndHUD.Shared.Show(this, "Downloading file", 0);

                    var docPath          = Path.Combine(ApplicationContext.CacheDir.ToString(), DateTime.Now.Ticks.ToString() + ".pdf");
                    var progressReporter = new Progress <DownloadBytesProgress> ();
                    progressReporter.ProgressChanged += (s, args) => AndHUD.Shared.Show(this, "Downloading file", (int)(100 * args.PercentComplete));
                    var docUri = await Utils.DownloadDocument(this, data.Data, docPath, progressReporter);

                    AndHUD.Shared.Dismiss(this);
                    ShowPdfDocument(docUri);
                }
                else
                {
                    ShowPdfDocument(data.Data);
                }
            }
        }
Example #3
0
        public override void LaunchExample(Context ctx, PdfActivityConfiguration.Builder configuration)
        {
            Task.Factory.StartNew(async() => {
                AndHUD.Shared.Show(ctx, $"Downloading file....", cancelCallback: client.CancelPendingRequests);
                PrepareConfiguration(configuration);
                var docUrl  = "https://pspdfkit.com/downloads/case-study-box.pdf";
                var docPath = Path.Combine(ctx.CacheDir.ToString(), AssetPath);

                using (var file = new FileStream(docPath, FileMode.Create, FileAccess.Write, FileShare.None))
                    await client.DownloadDataAsync(docUrl, file);

                AndHUD.Shared.Dismiss(ctx);

                var jfile  = new Java.IO.File(docPath);
                var docUri = Android.Net.Uri.FromFile(jfile);

                // Start the PSPDFKitAppCompat activity by passing it the Uri of the file.
                if (PSPDFKitGlobal.IsOpenableUri(ctx, docUri))
                {
                    PdfActivity.ShowDocument(ctx, docUri, configuration.Build());
                }
                else
                {
                    AndHUD.Shared.ShowError(ctx, $"This document uri cannot be opened:\n{docUri}", MaskType.Black, TimeSpan.FromSeconds(2));
                }
            });
        }
Example #4
0
 public override void DidFinishLaunching(NSNotification notification)
 {
     // Set your license key here. PSPDFKit is commercial software.
     // Each PSPDFKit license is bound to a specific app bundle id.
     // Visit https://customers.pspdfkit.com to get your license key.
     PSPDFKitGlobal.SetLicenseKey("YOUR_LICENSE_KEY_GOES_HERE");
 }
Example #5
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            PSPDFKitGlobal.SetLicenseKey("YOUR_LICENSE_KEY_GOES_HERE");
            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
        public virtual void LaunchExample(Context ctx, PdfActivityConfiguration.Builder configuration)
        {
            // Extract the pdf from assets if not already extracted
            var docUri = Utils.ExtractAsset(ctx, AssetPath);

            PrepareConfiguration(configuration);

            // Start the PSPDFKitAppCompat activity by passing it the Uri of the file.
            if (PSPDFKitGlobal.IsOpenableUri(ctx, docUri))
            {
                PdfActivity.ShowDocument(ctx, docUri, configuration.Build());
            }
            else
            {
                AndHUD.Shared.ShowError(ctx, $"This document uri cannot be opened:\n{docUri}", MaskType.Black, TimeSpan.FromSeconds(2));
            }
        }
Example #7
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            // Restore state as it was before.
            this.NavigationController.SetNavigationBarHidden(false, animated);
            UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.Default, animated);
            UIApplication.SharedApplication.SetStatusBarHidden(false, animated ? UIStatusBarAnimation.Fade : UIStatusBarAnimation.None);
            PSPDFKitGlobal.PSPDFFixNavigationBarForNavigationControllerAnimated(this.NavigationController, false);
            this.NavigationController.NavigationBar.BarStyle = UIBarStyle.Default;

            // clear cache (for night mode)
            if (this.clearCacheNeeded)
            {
                this.clearCacheNeeded = false;
                PSPDFCache.SharedCache.ClearCache();
            }
        }
        void ShowPdfDocument(Android.Net.Uri docUri)
        {
            // Show Document using PSPDFKit activity
            var pspdfkitConfiguration = new PdfActivityConfiguration.Builder(ApplicationContext)
                                        .ScrollDirection(PageScrollDirection.Horizontal)
                                        .ShowPageNumberOverlay()
                                        .ShowThumbnailGrid()
                                        .FitMode(PageFitMode.FitToWidth)
                                        .Build();

            if (!PSPDFKitGlobal.IsOpenableUri(this, docUri))
            {
                ShowError("This document uri cannot be opened \n " + docUri.ToString());
            }
            else
            {
                PdfActivity.ShowDocument(this, docUri, pspdfkitConfiguration);
            }
        }
Example #9
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Set your license key here. PSPDFKit is commercial software.
            // Each PSPDFKit license is bound to a specific app bundle id.
            // Visit https://customers.pspdfkit.com to get your license key.
            PSPDFKitGlobal.SetLicenseKey("YOUR_LICENSE_KEY_GOES_HERE");

            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            // Apply the PSPDFKit blue
            Window.TintColor = UIColor.FromRGBA(0.110f, 0.529f, 0.757f, 1f);

            viewController            = new DVCMenu();
            navController             = new UINavigationController(viewController);
            Window.RootViewController = navController;

            Window.MakeKeyAndVisible();
            return(true);
        }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == requestOpenDocument && resultCode == Result.Ok && data != null)
            {
                var uri = data.Data;

                // Some URIs can be opened directly, including local filesystem, app assets, and content provider URIs.
                if (PSPDFKitGlobal.IsOpenableUri(this, uri))
                {
                    var intent = PdfActivityIntentBuilder.FromUri(this, uri)
                                 .Configuration(configuration)
                                 .Build();
                    StartActivity(intent);
                    Finish();
                }
                else
                {
                    // The Uri cannot be directly opened. Download the PDF document from the uri, for local access.
                    // Find the DownloadProgressFragment for showing download progress, or create a new one.
                    var downloadFragment = SupportFragmentManager?.FindFragmentByTag(downloadProgressFragment)?.JavaCast <DownloadProgressFragment> ();
                    if (downloadFragment == null)
                    {
                        var job = DownloadJob.StartDownload(new DownloadRequest.Builder(this).Uri(uri).Build());
                        downloadFragment = new DownloadProgressFragment();
                        downloadFragment.Show(SupportFragmentManager, downloadProgressFragment);
                        downloadFragment.Job = job;
                    }

                    // Once the download is complete we launch the PdfActivity from the downloaded file.
                    downloadFragment.Job.Complete += (sender, e) => {
                        var intent = PdfActivityIntentBuilder.FromUri(this, Android.Net.Uri.FromFile(e.P0))
                                     .Configuration(configuration)
                                     .Build();
                        StartActivity(intent);
                        Finish();
                    };
                }
            }
        }
        // Opens a demo document from assets directory, called from Xamarin.Forms's DependencyService, see 'ShowPDF ()' method in XFSamplePage.xaml.cs
        public void ShowPdfActivity()
        {
            // Extract the pdf from assets if not already extracted
            var docUri = Utils.ExtractAsset(CrossCurrentActivity.Current.Activity, sampleDoc);

            // Show Document using PSPDFKit activity
            var pspdfkitConfiguration = new PdfActivityConfiguration.Builder(CrossCurrentActivity.Current.Activity)
                                        .ScrollDirection(PageScrollDirection.Horizontal)
                                        .ShowPageNumberOverlay()
                                        .ShowThumbnailGrid()
                                        .FitMode(PageFitMode.FitToWidth)
                                        .Build();

            if (!PSPDFKitGlobal.IsOpenableUri(this, docUri))
            {
                ShowError("This document uri cannot be opened \n " + docUri.ToString());
            }
            else
            {
                PdfActivity.ShowDocument(CrossCurrentActivity.Current.Activity, docUri, pspdfkitConfiguration);
            }
        }
Example #12
0
        /// <summary>
        /// Gets called if an element from the annotations toolbar has been selected.
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="index">Index.</param>
        private void HandleAnnotationToolbarItemSelected(string id, int index)
        {
            this.ThumbnailBarMode = PSPDFThumbnailBarMode.PSPDFThumbnailBarModeNone;
            // Show annotations toolbar.
            UIView.Animate(0.3f, () => { this.verticalToolbar.Alpha = 0f; });

            var toolbar = this.AnnotationButtonItem.AnnotationToolbar;

            switch (id)
            {
            case "NOTE":
            {
                toolbar.NoteButtonPressed(this);
            }
            break;

            case "FREETEXT":
            {
                toolbar.FreeTextButtonPressed(this);
            }
            break;

            case "HIGHLIGHT":
            {
                switch (index)
                {
                case 0:
                    defaultHighlightColor = UIColor.Red;
                    break;

                case 1:
                    defaultHighlightColor = UIColor.Green;
                    break;

                case 2:
                    defaultHighlightColor = UIColor.Blue;
                    break;
                }
                toolbar.HighlightButtonPressed(this);
            }
            break;

            case "INK":
            {
                switch (index)
                {
                case 0:
                    toolbar.DrawColor = UIColor.Red;
                    break;

                case 1:
                    toolbar.DrawColor = UIColor.Green;
                    break;

                case 2:
                    toolbar.DrawColor = UIColor.Blue;
                    break;
                }
                if (toolbar.ToolbarMode != PSPDFAnnotationToolbarMode.Draw)
                {
                    this.HUDViewMode = PSPDFHUDViewMode.Always;
                    if (toolbar.Window == null)
                    {
                        // match style
                        toolbar.BarStyle    = this.NavigationBarStyle;
                        toolbar.Translucent = this.TransparentHUD;
                        toolbar.TintColor   = this.TintColor;


                        // add the toolbar to the view hierarchy for color picking etc
                        if (this.NavigationController != null)
                        {
                            RectangleF targetRect = this.NavigationController.NavigationBar.Frame;
                            this.NavigationController.View.InsertSubviewAbove(toolbar, this.NavigationController.NavigationBar);
                            toolbar.ShowToolbarInRect(targetRect, true);
                        }
                        else
                        {
                            RectangleF contentRect   = this.ContentRect();
                            var        toolbarHeight = PSPDFKitGlobal.ToolbarHeightForOrientation(this.InterfaceOrientation);
                            RectangleF targetRect    = new RectangleF(contentRect.X, contentRect.Y, this.View.Bounds.Size.Width, toolbarHeight);
                            this.View.AddSubview(toolbar);
                            toolbar.ShowToolbarInRect(targetRect, true);
                        }
                    }

                    // call draw mode of the toolbar
                    toolbar.DrawButtonPressed(this);
                }
            }
            break;
            }
        }
Example #13
0
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear(animated);
     PSPDFKitGlobal.PSPDFFixNavigationBarForNavigationControllerAnimated(this.NavigationController, animated);
 }
Example #14
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);
                    })
                }
            };
        }