Esempio n. 1
0
        /// <summary>
        /// Creates an instance of the PDF viewer.
        /// </summary>
        /// <returns>
        /// The PDF viewer.
        /// </returns>
        /// <param name='sFilename'>
        /// Name of the PDF to open.
        /// </param>
        /// <param name='iInitialPage'>
        /// The initial pae number to go to.
        /// </param>
        /// <param name='bAllowsPrinting'>
        /// True to enable the print menu.
        /// </param>
        /// <param name='bAllowsExport'>
        /// True to allow exporting the document to other apps.
        /// </param>
        public static PSPDFViewController CreatePDFViewer(string sFilename, uint iInitialPage, bool bAllowsPrinting, bool bAllowsExport)
        {
            // Use PSPDFKit to view PDFs.
            var document = new PSPDFKitDocument(NSUrl.FromFilename(sFilename), bAllowsExport && bAllowsPrinting, bAllowsExport && bAllowsPrinting);

            var oClassDic = new NSMutableDictionary();

            //oClassDic [new NSString("PSPDFFileAnnotationProvider")] = new NSString("CustomFileAnnnotationsProvider");
            oClassDic.LowlevelSetObject(new Class(typeof(CustomFileAnnnotationsProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle);
            document.OverrideClassNames = oClassDic;

            // Read PDF properties from config.
            PSPDFPageTransition  ePageTransition  = PSPDFPageTransition.Curl;
            PSPDFPageMode        ePageMode        = PSPDFPageMode.Automatic;
            PSPDFScrollDirection eScrollDirection = PSPDFScrollDirection.Horizontal;

            var oPdfViewer = new PSPDFViewController(document)
            {
                ModalPresentationStyle = MonoTouch.UIKit.UIModalPresentationStyle.FullScreen,
                ModalTransitionStyle   = MonoTouch.UIKit.UIModalTransitionStyle.CoverVertical,
                LinkAction             = PSPDFLinkAction.OpenSafari,
                PageTransition         = ePageTransition,
                PageMode              = ePageMode,
                ScrollDirection       = eScrollDirection,
                RenderAnnotationTypes = PSPDFAnnotationType.Highlight | PSPDFAnnotationType.Ink | PSPDFAnnotationType.Note | PSPDFAnnotationType.Text | PSPDFAnnotationType.Link,
                Delegate              = new PSPDFKitViewControllerDelegate()
            };

            var oControllerClassDic = new NSMutableDictionary();

            oControllerClassDic.LowlevelSetObject(new Class(typeof(CustomNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle);
            oControllerClassDic.LowlevelSetObject(new Class(typeof(CustomLinkAnnotationView)).Handle, new Class(typeof(PSPDFLinkAnnotationView)).Handle);
            oPdfViewer.OverrideClassNames = oControllerClassDic;

            List <PSPDFBarButtonItem> aButtons = new List <PSPDFBarButtonItem>()
            {
                oPdfViewer.AnnotationButtonItem,
                oPdfViewer.BookmarkButtonItem,
                oPdfViewer.SearchButtonItem,
                oPdfViewer.OutlineButtonItem
            };

            if (bAllowsPrinting && bAllowsExport)
            {
                //aButtons.Add(this.oPdfViewer.EmailButtonItem);
                aButtons.Add(oPdfViewer.PrintButtonItem);
                aButtons.Add(oPdfViewer.OpenInButtonItem);
            }

            aButtons.Add(oPdfViewer.ViewModeButtonItem);

            oPdfViewer.RightBarButtonItems = aButtons.ToArray();
            aButtons = null;

            oPdfViewer.SetPageAnimated(iInitialPage, false);

            return(oPdfViewer);
        }
Esempio n. 2
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 KSCatalogViewController () : base (UITableViewStyle.Grouped, null)
		{
			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 controller = new KSKioskViewController(doc);

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

				new Section("Customizing")
				{
					new StringElement("Combine search, TOC and bookmarks", () =>
					{
						var doc = new PSPDFDocument(hackerMagURL);
						var controller = new PSPDFViewController(doc);
						var tabBarController = new KSCombinedTabBarController(controller, doc);

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

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

						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;
					}),

					// Remove annotation toolbar item by setting EditableAnnotationTypes
					new StringElement ("Remove Ink from the annotation toolbar", () =>
					{
						var doc = new PSPDFDocument(hackerMagURL);
						var controller = new PSPDFViewController(doc);
						// TODO: We need NSMutableOrderedSet bound and NSOrderedSet!
						/*
						NSMutableOrderedSet annotTypes = UIDocument.EditableAnnotationTypes;
						annotTypes.RemoveObject(PSPDFAnnotationTypeStringInk);
						controller.AnnotationButtonItem.AnnotationToolbar.EditableAnnotationTypes = annotTypes;
						*/
						this.NavigationController.PushViewController(controller, true);
					})
				}
			};
		}
        /// <summary>
        /// Creates an instance of the PDF viewer.
        /// </summary>
        /// <returns>
        /// The PDF viewer.
        /// </returns>
        /// <param name='sFilename'>
        /// Name of the PDF to open.
        /// </param>
        /// <param name='iInitialPage'>
        /// The initial pae number to go to.
        /// </param>
        /// <param name='bAllowsPrinting'>
        /// True to enable the print menu.
        /// </param>
        /// <param name='bAllowsExport'>
        /// True to allow exporting the document to other apps.
        /// </param>
        public static PSPDFViewController CreatePDFViewer(string sFilename, uint iInitialPage, bool bAllowsPrinting, bool bAllowsExport)
        {
            // Use PSPDFKit to view PDFs.
            var document = new PSPDFKitDocument(NSUrl.FromFilename(sFilename), bAllowsExport && bAllowsPrinting, bAllowsExport && bAllowsPrinting);

            var oClassDic = new NSMutableDictionary();
            //oClassDic [new NSString("PSPDFFileAnnotationProvider")] = new NSString("CustomFileAnnnotationsProvider");
            oClassDic.LowlevelSetObject(new Class(typeof(CustomFileAnnnotationsProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle);
            document.OverrideClassNames = oClassDic;

            // Read PDF properties from config.
            PSPDFPageTransition ePageTransition = PSPDFPageTransition.Curl;
            PSPDFPageMode ePageMode = PSPDFPageMode.Automatic;
            PSPDFScrollDirection eScrollDirection = PSPDFScrollDirection.Horizontal;

            var oPdfViewer = new PSPDFViewController(document)
            {
                ModalPresentationStyle = MonoTouch.UIKit.UIModalPresentationStyle.FullScreen,
                ModalTransitionStyle = MonoTouch.UIKit.UIModalTransitionStyle.CoverVertical,
                LinkAction = PSPDFLinkAction.OpenSafari,
                PageTransition = ePageTransition,
                PageMode = ePageMode,
                ScrollDirection = eScrollDirection,
                RenderAnnotationTypes = PSPDFAnnotationType.Highlight | PSPDFAnnotationType.Ink | PSPDFAnnotationType.Note | PSPDFAnnotationType.Text | PSPDFAnnotationType.Link,
                Delegate = new PSPDFKitViewControllerDelegate()
            };

            var oControllerClassDic = new NSMutableDictionary();
            oControllerClassDic.LowlevelSetObject(new Class(typeof(CustomNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle);
            oControllerClassDic.LowlevelSetObject(new Class(typeof(CustomLinkAnnotationView)).Handle, new Class(typeof(PSPDFLinkAnnotationView)).Handle);
            oPdfViewer.OverrideClassNames = oControllerClassDic;

            List<PSPDFBarButtonItem> aButtons = new List<PSPDFBarButtonItem>()
            {
                oPdfViewer.AnnotationButtonItem,
                oPdfViewer.BookmarkButtonItem,
                oPdfViewer.SearchButtonItem,
                oPdfViewer.OutlineButtonItem
            };

            if(bAllowsPrinting && bAllowsExport)
            {
                //aButtons.Add(this.oPdfViewer.EmailButtonItem);
                aButtons.Add(oPdfViewer.PrintButtonItem);
                aButtons.Add(oPdfViewer.OpenInButtonItem);
            }

            aButtons.Add(oPdfViewer.ViewModeButtonItem);

            oPdfViewer.RightBarButtonItems = aButtons.ToArray();
            aButtons = null;

            oPdfViewer.SetPageAnimated(iInitialPage, false);

            return oPdfViewer;
        }