Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            page = Pdf.GetPage(PageNumber);
            ScrollView.SetPDFPage(page);
        }
Beispiel #2
0
		public PdfViewController (NSUrl url) : base()
		{
			Url = url;
			View = new UIView ();
			View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleRightMargin;
			View.AutosizesSubviews = true;
			
			PdfDocument = CGPDFDocument.FromUrl (Url.ToString ());
			
			// For demo purposes, show first page only.
			PdfPage = PdfDocument.GetPage (1);
			PdfPageRect = PdfPage.GetBoxRect (CGPDFBox.Crop);
			
			// Setup tiled layer.
			TiledLayer = new CATiledLayer ();
			TiledLayer.Delegate = new TiledLayerDelegate (this);
			TiledLayer.TileSize = new SizeF (1024f, 1024f);
			TiledLayer.LevelsOfDetail = 5;
			TiledLayer.LevelsOfDetailBias = 5;
			TiledLayer.Frame = PdfPageRect;
			
			ContentView = new UIView (PdfPageRect);
			ContentView.Layer.AddSublayer (TiledLayer);
			
			// Prepare scroll view.
			ScrollView = new UIScrollView (View.Frame);
			ScrollView.AutoresizingMask = View.AutoresizingMask;
			ScrollView.Delegate = new ScrollViewDelegate (this);
			ScrollView.ContentSize = PdfPageRect.Size;
			ScrollView.MaximumZoomScale = 10f;
			ScrollView.MinimumZoomScale = 1f;
			ScrollView.ScrollEnabled = true;
			ScrollView.AddSubview (ContentView);
			View.AddSubview (ScrollView);
		}
Beispiel #3
0
        static UIImage imageWithPDFPage(CGPDFPage page, float scale ,CGAffineTransform t )
        {
            if (page == null)
            {
                return null ;
            }

            RectangleF box = page.GetBoxRect(CGPDFBox.Crop);

            t.Scale(scale,scale);
            box = new RectangleF(box.Location,new SizeF(box.Size.Width * scale, box.Size.Height * scale));

            var pixelWidth = box.Size.Width ;
            CGColorSpace cs = CGColorSpace.CreateDeviceRGB() ;
            //DebugAssert( cs ) ;
            var _buffer = Marshal.AllocHGlobal((int)(box.Width * box.Height));
            UIGraphics.BeginImageContext(box.Size);
            CGContext c = UIGraphics.GetCurrentContext();
            cs.Dispose();
            c.ConcatCTM(t);
            c.DrawPDFPage(page);

            var image = UIGraphics.GetImageFromCurrentImageContext();
            return image ;
        }
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = (PageCell)collectionView.DequeueReusableCell(cellID, indexPath);

            var page = list[indexPath.Row];
            if (page != null)
            {
                cell.PageID = page.ID;

                if (page.ID != StringRef.Empty || page.ChapterID != StringRef.Empty)
                {
                    String url = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    if (!String.IsNullOrEmpty(url))
                    {
                        CGPDFDocument pdfDoc = CGPDFDocument.FromFile(url);
                        if (pdfDoc != null)
                        {
                            CGPDFPage pdfPage = pdfDoc.GetPage(1);

							UIImage image = ImageHelper.PDF2Image(pdfPage, 150, UIScreen.MainScreen.Scale);

                            // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                            SkipBackup2iCloud.SetAttribute(url);

                            if (image != null)
                            {
                                cell.Image = image;
                            }
                        }
                    }
                }
            }

            return cell;
        }
Beispiel #5
0
        static UIImage imageWithPDFPage(CGPDFPage page, float scale, CGAffineTransform t)
        {
            if (page == null)
            {
                return(null);
            }

            RectangleF box = page.GetBoxRect(CGPDFBox.Crop);

            t.Scale(scale, scale);
            box = new RectangleF(box.Location, new SizeF(box.Size.Width * scale, box.Size.Height * scale));

            var          pixelWidth = box.Size.Width;
            CGColorSpace cs         = CGColorSpace.CreateDeviceRGB();
            //DebugAssert( cs ) ;
            var _buffer = Marshal.AllocHGlobal((int)(box.Width * box.Height));

            UIGraphics.BeginImageContext(box.Size);
            CGContext c = UIGraphics.GetCurrentContext();

            c.SaveState();
            c.TranslateCTM(0f, box.Height);
            c.ScaleCTM(1f, -1f);
            cs.Dispose();
            c.ConcatCTM(t);
            c.DrawPDFPage(page);

            c.RestoreState();
            var image = UIGraphics.GetImageFromCurrentImageContext();

            return(image);
        }
Beispiel #6
0
        private static UIImage RenderImage(CGPDFPage page)
        {
            var rect         = page.GetBoxRect(CGPDFBox.Crop);
            var pageRotation = page.RotationAngle;
            var size         = rect.Size;

            UIGraphics.BeginImageContextWithOptions(size, false, (nfloat)(1));

            var context = UIGraphics.GetCurrentContext();

            context.SaveState();
            context.TranslateCTM((nfloat)0.0, size.Height);
            context.ScaleCTM(One, (nfloat)(-1.0));

            context.SetFillColor(One, One);
            context.FillRect(rect);

            var transform = page.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true);

            context.ConcatCTM(transform);
            context.DrawPDFPage(page);

            var image = UIGraphics.GetImageFromCurrentImageContext();

            context.RestoreState();
            UIGraphics.EndImageContext();

            return(image);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			page = Pdf.GetPage (PageNumber);
			ScrollView.SetPDFPage (page);
		}
Beispiel #8
0
 public CGPDFContentStream(CGPDFPage page)
 {
     if (page == null)
     {
         throw new ArgumentNullException("page");
     }
     handle = CGPDFContentStreamCreateWithPage(page.Handle);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Do any additional setup after loading the view, typically from a nib.
            page = Pdf.GetPage(PageNumber);
            ScrollView.SetPDFPage(page);

            // Disable zooming if our pages are currently shown in landscape, for new views
            ScrollView.UserInteractionEnabled = UIApplication.SharedApplication.StatusBarOrientation.IsPortrait();
        }
Beispiel #10
0
        /// <summary>
        /// Gets the view size for the opened PDF page.
        /// </summary>
        /// <param name="pageNumber">The page number,</param>
        /// <returns>The page view rect.</returns>
        public static RectangleF GetPageViewSize(int pageNumber)
        {
            RectangleF pageRect = RectangleF.Empty;

            if (PDFDocument.DocumentHasLoaded)
            {
                // Check the lower page bounds
                if (pageNumber < 1)
                {
                    pageNumber = 1;
                }
                // Check the upper page bounds
                if (pageNumber > PDFDocument.PageCount)
                {
                    pageNumber = PDFDocument.PageCount;
                }
                using (CGPDFPage pdfPage = PDFDocument.GetPage(pageNumber)) {
                    if (pdfPage != null)
                    {
                        // Calc effective rect
                        RectangleF cropBoxRect   = pdfPage.GetBoxRect(CGPDFBox.Crop);
                        RectangleF mediaBoxRect  = pdfPage.GetBoxRect(CGPDFBox.Media);
                        RectangleF effectiveRect = RectangleF.Intersect(cropBoxRect, mediaBoxRect);

                        // Calc page width and height, accoring by rotation
                        switch (pdfPage.RotationAngle)
                        {
                        default:
                        case 0:
                        case 180:
                            pageRect.Width  = effectiveRect.Size.Width;
                            pageRect.Height = effectiveRect.Size.Height;
                            break;

                        case 90:
                        case 270:
                            pageRect.Height = effectiveRect.Size.Width;
                            pageRect.Width  = effectiveRect.Size.Height;
                            break;
                        }
                        if (pageRect.Width % 2 > 0)
                        {
                            pageRect.Width--;
                        }
                        if (pageRect.Height % 2 > 0)
                        {
                            pageRect.Height--;
                        }
                    }
                }
            }
            return(pageRect);
        }
Beispiel #11
0
        public static CGRect GetPageViewSize(nint pageNumber)
        {
            CGRect pageRect = CGRect.Empty;

            if (PDFDocument.DocumentHasLoaded)
            {
                if (pageNumber < 1)
                {
                    pageNumber = 1;
                }

                if (pageNumber > PDFDocument.PageCount)
                {
                    pageNumber = PDFDocument.PageCount;
                }

                using (CGPDFPage pdfPage = PDFDocument.GetPage(pageNumber)) {
                    if (pdfPage != null)
                    {
                        CGRect cropBoxRect   = pdfPage.GetBoxRect(CGPDFBox.Crop);
                        CGRect mediaBoxRect  = pdfPage.GetBoxRect(CGPDFBox.Media);
                        CGRect effectiveRect = CGRect.Intersect(cropBoxRect, mediaBoxRect);

                        switch (pdfPage.RotationAngle)
                        {
                        default:
                        case 0:
                        case 180:
                            pageRect.Width  = effectiveRect.Size.Width;
                            pageRect.Height = effectiveRect.Size.Height;
                            break;

                        case 90:
                        case 270:
                            pageRect.Height = effectiveRect.Size.Width;
                            pageRect.Width  = effectiveRect.Size.Height;
                            break;
                        }
                        if (pageRect.Width % 2 > 0)
                        {
                            pageRect.Width--;
                        }
                        if (pageRect.Height % 2 > 0)
                        {
                            pageRect.Height--;
                        }
                    }
                }
            }
            return(pageRect);
        }
		public void SetPDFPage (CGPDFPage pdfPage)
		{
			page = pdfPage;

			if (page == null) {
				pageRect = Bounds;
			} else {
				pageRect = page.GetBoxRect (CGPDFBox.Media);
				PdfScale = Frame.Size.Width / pageRect.Size.Width;
				pageRect = new CGRect (pageRect.X, pageRect.Y, pageRect.Width * PdfScale, pageRect.Height * PdfScale);
			}

			ReplaceTiledPDFView (pageRect);
		}
Beispiel #13
0
        static UIImage imageWithPDFNamed(string name, float scale, CGAffineTransform t)
        {
            CGPDFDocument doc = CreatePDFDocumentWithName(name);

            if (doc == null)
            {
                return(null);
            }

            // PDF pages are numbered starting at page 1
            CGPDFPage page = doc.GetPage(1);

            var result = imageWithPDFPage(page, scale, t);

            return(result);
        }
Beispiel #14
0
        // Init method. Call this before adding the instance of the PDF_Manager to the View.
        public void Init(CGPDFDocument oPdfDoc, int page, PageTurnViewController mother_controller)
        {
            Console.WriteLine ("Rendering PDF Page Number: " + page);
            this.page_number = page;
            this.currentPDFdocument = oPdfDoc;

            currentPDFPage = this.currentPDFdocument.GetPage (page_number);

            RectangleF oPdfPageRect = this.currentPDFPage.GetBoxRect (CGPDFBox.Bleed);

            Console.WriteLine ("PDFRect : " + oPdfPageRect.ToString ());

            // Setup tiled layer.
            oTiledLayer = new CATiledLayer ();
            tiled_layer_delegate = new TiledLayerDelegate (this);
            oTiledLayer.Delegate = tiled_layer_delegate;
            oTiledLayer.TileSize = new SizeF (1024f, 1024f);
            oTiledLayer.LevelsOfDetail = 5;
            oTiledLayer.LevelsOfDetailBias = 5;
            oTiledLayer.Frame = oPdfPageRect;
            Console.WriteLine ("oTiledLayer.Frame : " + oTiledLayer.Frame.ToString ());

            this.oContentView = new UIView (oPdfPageRect);
            this.oContentView.Layer.AddSublayer (oTiledLayer);

            this.View.AutoresizingMask = mother_controller.View.AutoresizingMask;
            this.View.AutosizesSubviews = true;

            #if DEBUG
            this.View.Layer.BorderColor = UIColor.Red.CGColor;
            this.View.Layer.BorderWidth = 2f;
            #endif

            // Prepare scroll view.

            this.scroll_area.AutoresizingMask = mother_controller.View.AutoresizingMask;

            scroll_area_delegate = new ScrollViewDelegate (this);
            scroll_area.Delegate = scroll_area_delegate;

            scroll_area.ContentSize = oPdfPageRect.Size;
            scroll_area.MaximumZoomScale = 1000f;
            scroll_area.MinimumZoomScale = 0.1f;

            scroll_area.AddSubview (this.oContentView);
            scroll_area.SetZoomScale (this.View.Frame.Width / oContentView.Frame.Width, false);
        }
Beispiel #15
0
        private void draw(CGContext context)
        {
            if (!PDFDocument.DocumentHasLoaded)
            {
                return;
            }

            context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            using (CGPDFPage pdfPage = PDFDocument.GetPage(_pageNumber)) {
                context.TranslateCTM(0, Bounds.Height);
                context.ScaleCTM(1.0f, -1.0f);
                context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, Bounds, 0, true));
                context.SetRenderingIntent(CGColorRenderingIntent.Default);
                context.InterpolationQuality = CGInterpolationQuality.Default;
                context.DrawPDFPage(pdfPage);
            }
        }
Beispiel #16
0
        public void SetPDFPage(CGPDFPage pdfPage)
        {
            page = pdfPage;

            if (page == null)
            {
                pageRect = Bounds;
            }
            else
            {
                pageRect = page.GetBoxRect(CGPDFBox.Media);
                PdfScale = Frame.Size.Width / pageRect.Size.Width;
                pageRect = new CGRect(pageRect.X, pageRect.Y, pageRect.Width * PdfScale, pageRect.Height * PdfScale);
            }

            ReplaceTiledPDFView(pageRect);
        }
Beispiel #17
0
        public static UIImage PDF2Image(CGPDFPage page, nfloat width, nfloat scale)
        {
            UIImage img = new UIImage();

            try
            {
                CGRect pageRect = page.GetBoxRect(CGPDFBox.Media);
                nfloat pdfScale = width / pageRect.Size.Width;
                pageRect.Size = new CGSize(pageRect.Size.Width * pdfScale, pageRect.Size.Height * pdfScale);

                UIGraphics.BeginImageContextWithOptions(pageRect.Size, true, scale);
                CGContext context = UIGraphics.GetCurrentContext();

                // White BG
                context.SetFillColor(1.0f, 1.0f, 1.0f, 1f);
                context.FillRect(pageRect);
                context.SaveState();

                //border
                context.SetStrokeColor(0f, 0f, 0f, 0.5f);
                context.StrokeRect(pageRect);

                // Next 3 lines makes the rotations so that the page look in the right direction
                context.TranslateCTM(0.0f, pageRect.Size.Height);
                context.ScaleCTM(1.0f, -1.0f);
                CGAffineTransform transform = page.GetDrawingTransform(CGPDFBox.Media, pageRect, 0, true);
                context.ConcatCTM(transform);

                context.DrawPDFPage(page);
                context.RestoreState();

                img = UIGraphics.GetImageFromCurrentImageContext();

                UIGraphics.EndImageContext();

                context.Dispose();
            }
            catch (Exception ex)
            {
            }
            return(img);
        }
Beispiel #18
0
        public void SetPDFPage(CGPDFPage pdfPage)
        {
            page = pdfPage;

            // PDFPage is null if we're requested to draw a padded blank page by the parent UIPageViewController
            if (page == null)
            {
                pageRect = Bounds;
            }
            else
            {
                pageRect = page.GetBoxRect(CGPDFBox.Media);

                PdfScale = Frame.Size.Width / pageRect.Size.Width;
                pageRect = new CGRect(pageRect.X, pageRect.Y, pageRect.Width * PdfScale, pageRect.Height * PdfScale);
            }

            // Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
            ReplaceTiledPdfViewWithFrame(pageRect);
        }
Beispiel #19
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            //flip the CTM so the PDF will be drawn upright
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                g.TranslateCTM(0, Bounds.Height);
                g.ScaleCTM(1, -1);

                // render the first page of the PDF
                using (CGPDFPage pdfPage = pdfDoc.GetPage(1)) {
                    //get the affine transform that defines where the PDF is drawn
                    CGAffineTransform t = pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true);
                    //concatenate the pdf transform with the CTM for display in the view
                    g.ConcatCTM(t);
                    //draw the pdf page
                    g.DrawPDFPage(pdfPage);
                }
            }
        }
Beispiel #20
0
        public UIImage GetPDFImageForPage()
        {
            CGPDFPage pdfPg = _pdf.GetPage(PageNumber);
            nfloat    scale;

            PDFpageRect = pdfPg.GetBoxRect(CGPDFBox.Media);
            if (PDFpageRect.Height > PDFpageRect.Width)
            {
                scale = (this.View.Frame.Width - 80.0f) / PDFpageRect.Width;
            }
            else
            {
                scale = this.View.Frame.Height / PDFpageRect.Height;
            }

            PDFpageRect.Size = new CGSize(PDFpageRect.Width * scale, PDFpageRect.Height * scale);

            UIGraphics.BeginImageContext(PDFpageRect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetFillColor((nfloat)1.0, (nfloat)1.0, (nfloat)1.0, (nfloat)1.0);
            context.FillRect(PDFpageRect);

            context.SaveState();

            context.TranslateCTM(0, PDFpageRect.Size.Height);
            context.ScaleCTM(1, -1);

            context.ConcatCTM(CGAffineTransform.MakeScale(scale, scale));


            context.DrawPDFPage(pdfPg);
            context.RestoreState();

            UIImage thm = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(thm);
        }
Beispiel #21
0
        public static UIImage FromPdf(string name, float width, float height)
        {
            CGPDFDocument doc = CreatePDFDocumentWithName(name);

            if (doc == null)
            {
                return(null);
            }

            // PDF pages are numbered starting at page 1
            CGPDFPage page = doc.GetPage(1);

            RectangleF box = page.GetBoxRect(CGPDFBox.Crop);

            var xScale = (width * UIScreen.MainScreen.Scale) / box.Width;
            var yScale = (height * UIScreen.MainScreen.Scale) / box.Height;


            var result = imageWithPDFPage(page, Math.Max(xScale, yScale), CGAffineTransform.MakeIdentity());

            return(result);
        }
Beispiel #22
0
        internal void ConvertPagetoImage(int index)
        {
            if (this.PdfDocument == null || this.Element.ImageStreams.ContainsKey(index))
            {
                return;
            }

            float   scaleFactor = 1;
            UIImage image       = null;

            using (CGPDFPage pdfPage = this.PdfDocument.GetPage(index + 1))
            {
                if (pdfPage != null)
                {
                    CGRect rect   = pdfPage.GetBoxRect(CGPDFBox.Media);
                    nfloat factor = (nfloat)scaleFactor;
                    CGRect bounds = new CGRect(rect.X * factor, rect.Y * factor, rect.Width * factor, rect.Height * factor);
                    UIGraphics.BeginImageContext(bounds.Size);
                    CGContext context = UIGraphics.GetCurrentContext();
                    context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
                    context.FillRect(bounds);
                    context.TranslateCTM(0, bounds.Height);
                    context.ScaleCTM(factor, -factor);
                    context.ConcatCTM(pdfPage.GetDrawingTransform(CGPDFBox.Crop, rect, 0, true));
                    context.SetRenderingIntent(CGColorRenderingIntent.Default);
                    context.InterpolationQuality = CGInterpolationQuality.Default;
                    context.DrawPDFPage(pdfPage);
                    image = UIGraphics.GetImageFromCurrentImageContext();
                    UIGraphics.EndImageContext();
                }
            }

            if (image != null)
            {
                this.Element.ImageStreams.Add(index, image);
                this.Element.PDFViewModel.Items[index].PageData = image;
            }
        }
Beispiel #23
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            CGContext gctx = UIGraphics.GetCurrentContext();

            gctx.TranslateCTM(0, Bounds.Height);
            gctx.ScaleCTM(1, -1);

            using (CGPDFPage pdfPg = _pdf.GetPage(PageNumber)) {
                gctx.SaveState();

                RectangleF        r  = new RectangleF(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height + 44f);
                CGAffineTransform tf = pdfPg.GetDrawingTransform(CGPDFBox.Crop, r, 0, true);
                gctx.ConcatCTM(tf);
                gctx.DrawPDFPage(pdfPg);

                gctx.RestoreState();
                gctx.TranslateCTM(0, Bounds.Height - 25);
                gctx.SelectFont("Helvetica", 25f, CGTextEncoding.MacRoman);
                gctx.ShowText(AnnotatedText);
            }
        }
Beispiel #24
0
		public override void ViewDidDisappear (bool animated)
		{
			base.ViewDidDisappear (animated);
			var page = PdfPage;
			var document = PdfDocument;
			var contentView = ContentView;
			var tiledLayer = TiledLayer;
			var scrollView = ScrollView;
			
			PdfPage = null;
			PdfDocument = null;
			ContentView = null;
			TiledLayer = null;
			ScrollView = null;
			
			scrollView.RemoveFromSuperview ();
			tiledLayer.RemoveFromSuperLayer ();
			page.Dispose ();
			document.Dispose ();
			contentView.Dispose ();
			scrollView.Dispose ();
			tiledLayer.Dispose ();
		}
Beispiel #25
0
    public override void DrawInContext(CGContext context)
    {
        // PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system
        // before we start drawing.
        context.TranslateCTM(0, Bounds.Height);
        context.ScaleCTM(1, -1);

        // Grab the first PDF page
        using (CGPDFPage page = doc.GetPage(1)) {
            // We're about to modify the context CTM to draw the PDF page where we want it, so save the graphics state in case we want to do more drawing
            context.SaveState();

            // CGPDFPageGetDrawingTransform provides an easy way to get the transform for a PDF page. It will scale down to fit, including any
            // base rotations necessary to display the PDF page correctly.

            CGAffineTransform pdfTransform = page.GetDrawingTransform(CGPDFBox.Crop, Bounds, 0, true);

            // And apply the transform.
            context.ConcatCTM(pdfTransform);
            // Finally, we draw the page and restore the graphics state for further manipulations!
            context.DrawPDFPage(page);
            context.RestoreState();
        }
    }
 PSPDFPageInfo PageInfoForPage(uint page, CGPDFPage pageRef)
 {
     return PageInfoForPage_ (page, pageRef.Handle);
 }
Beispiel #27
0
        public PdfScrollView(CGRect frame)
            : base(frame)
        {
            ShowsVerticalScrollIndicator   = false;
            ShowsHorizontalScrollIndicator = false;
            BouncesZoom      = true;
            DecelerationRate = UIScrollView.DecelerationRateFast;
            BackgroundColor  = UIColor.White;
            MaximumZoomScale = 5.0f;
            MinimumZoomScale = 0.25f;

            // open the PDF file (default directory is the bundle path)
            pdf = CGPDFDocument.FromFile("Tamarin.pdf");
            // select the first page (the only one we'll use)
            page = pdf.GetPage(1);

            // make the initial view 'fit to width'
            CGRect pageRect = page.GetBoxRect(CGPDFBox.Media);

            scale         = Frame.Width / pageRect.Width;
            pageRect.Size = new CGSize(pageRect.Width * scale, pageRect.Height * scale);

            // create bitmap version of the PDF page, to be used (scaled)
            // when no other (tiled) view are visible
            UIGraphics.BeginImageContext(pageRect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            // fill with white background
            context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            context.FillRect(pageRect);
            context.SaveState();

            // flip page so we render it as it's meant to be read
            context.TranslateCTM(0.0f, pageRect.Height);
            context.ScaleCTM(1.0f, -1.0f);

            // scale page at the view-zoom level
            context.ScaleCTM(scale, scale);
            context.DrawPDFPage(page);
            context.RestoreState();

            UIImage backgroundImage = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            backgroundImageView             = new UIImageView(backgroundImage);
            backgroundImageView.Frame       = pageRect;
            backgroundImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            AddSubview(backgroundImageView);
            SendSubviewToBack(backgroundImageView);

            // Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
            pdfView      = new TiledPdfView(pageRect, (float)scale);
            pdfView.Page = page;
            AddSubview(pdfView);

            // no need to have (or set) a UIScrollViewDelegate with MonoTouch

            this.ViewForZoomingInScrollView = delegate {
                // return the view we'll be using while zooming
                return(pdfView);
            };

            // when zooming starts we remove (from view) and dispose any
            // oldPdfView and set pdfView as our 'new' oldPdfView, it will
            // stay there until a new view is available (when zooming ends)
            this.ZoomingStarted += delegate {
                if (oldPdfView != null)
                {
                    oldPdfView.RemoveFromSuperview();
                    oldPdfView.Dispose();
                }
                oldPdfView = pdfView;
                AddSubview(oldPdfView);
            };

            // when zooming ends a new TiledPdfView is created (and shown)
            // based on the updated 'scale' and 'frame'
            ZoomingEnded += delegate(object sender, ZoomingEndedEventArgs e) {
                scale *= e.AtScale;

                CGRect rect = page.GetBoxRect(CGPDFBox.Media);
                rect.Size = new CGSize(rect.Width * scale, rect.Height * scale);

                pdfView      = new TiledPdfView(rect, (float)scale);
                pdfView.Page = page;
                AddSubview(pdfView);
            };
        }
Beispiel #28
0
 public virtual SizeF SetupGraphicsContext(CGPDFPage page, CGContext context, PointF point, double zoom, PSPDFPageInfo pageInfo, PSPDFAnnotation[] annotations, NSDictionary options)
 {
     return SetupGraphicsContext_ (page.Handle, context.Handle, point, zoom, pageInfo, annotations, options);
 }
 public PSPDFTextParser(CGPDFPage pageRef, uint page, PSPDFDocument document, NSMutableDictionary fontCache, bool hideGlyphsOutsidePageRect, CGPDFBox PDFBox)
     : this(pageRef.Handle, page, document, fontCache, hideGlyphsOutsidePageRect, PDFBox)
 {
 }
 public virtual PSPDFAnnotation[] AnnotationsForPage(nuint page, PSPDFAnnotationType type, CGPDFPage pageRef)
 {
     if (pageRef == null)
         return AnnotationsForPage (page, type, IntPtr.Zero);
     else
         return AnnotationsForPage (page, type, pageRef.Handle);
 }
Beispiel #31
0
 public virtual void DrawPdfPage(CGPDFPage page, CGContext context, PSPDFPageInfo pageInfo)
 {
     DrawPDFPage_ (page.Handle, context, pageInfo);
 }
 public virtual PSPDFAnnotation [] ParseAnnotationsForPage(uint page, CGPDFPage pageRef)
 {
     return(ParseAnnotationsForPage_(page, pageRef.Handle));
 }
Beispiel #33
0
        public NoteCellView(String bookID, Note note)
        {
            this.BackgroundColor = UIColor.Clear;
            this.pageID          = pageID;
            this.note            = note;

            nfloat height = 300;

            Page page = BooksOnDeviceAccessor.GetPage(bookID, note.PageID);

            if (note.Text == "Header: " + note.PageID)
            {
                this.Frame = new CGRect(0, 0, 200, height);

                // pageView
                UIImageView pageView = new UIImageView();
                pageView.Frame = new CGRect(15, 20, 170, height - 80);
                this.AddSubview(pageView);

                bool notFound = true;
                if (page != null)
                {
                    String        localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    CGPDFDocument pdfDoc    = CGPDFDocument.FromFile(localPath);
                    if (pdfDoc != null)
                    {
                        notFound = false;

                        CGPDFPage pdfPage   = pdfDoc.GetPage(1);
                        UIImage   pageImage = ImageHelper.PDF2Image(pdfPage, pageView.Frame.Width, UIScreen.MainScreen.Scale);
                        pageView.Image = pageImage;
                    }
                }

                if (notFound)
                {
                    pageView.Image = UIImage.FromBundle("Assets/Icons/empty_page.png");

                    // emptyLabel
                    UILabel emptyLabel = eBriefingAppearance.GenerateLabel(17);
                    emptyLabel.Frame         = pageView.Frame;
                    emptyLabel.Text          = "Empty";
                    emptyLabel.TextAlignment = UITextAlignment.Center;
                    emptyLabel.SizeToFit();
                    emptyLabel.Center = pageView.Center;
                    this.AddSubview(emptyLabel);
                }

                // pageView
                NotePageView circleView = new NotePageView(page, pageView.Frame.Width / 2);
                circleView.Center = new CGPoint(pageView.Center.X, pageView.Frame.Bottom);
                this.AddSubview(circleView);
            }
            else if (note.Text == "Footer: " + note.PageID)
            {
                this.Frame = new CGRect(0, 0, 50, height);

                // footerView
//				UIImageView footerView = new UIImageView(UIImage.FromBundle("Assets/Icons/endPageNote.png"));
//				footerView.Frame = new CGRect(15, ((height - 40) / 2 - 10), 20, 20);
//                this.AddSubview(footerView);
            }
            else
            {
                this.Frame = new CGRect(0, 0, 250, height);

                // noteView
                NoteCellNoteView noteView = new NoteCellNoteView(note, height - 80);
                noteView.Frame          = new CGRect(15, 20, noteView.Frame.Width, noteView.Frame.Height);
                noteView.TouchUpInside += delegate
                {
                    if (ItemPressedEvent != null)
                    {
                        ItemPressedEvent(page.ID, note);
                    }
                };
                this.AddSubview(noteView);
            }
        }
 public void FreeWithPDFPageRef(CGPDFPage pdfPage)
 {
     _FreeWithPDFPageRef(pdfPage.Handle, true);
 }
Beispiel #35
0
 public CGPDFContentStream(CGPDFPage page)
 {
     if (page == null)
         throw new ArgumentNullException ("page");
     handle = CGPDFContentStreamCreateWithPage (page.Handle);
 }
 public PSPDFTextParser(CGPDFPage pageRef, uint page, PSPDFDocument document, NSMutableDictionary fontCache, bool hideGlyphsOutsidePageRect, CGPDFBox PDFBox) : this(pageRef.Handle, page, document, fontCache, hideGlyphsOutsidePageRect, PDFBox)
 {
 }
 public void ReleasePageRef(CGPDFPage pageRef)
 {
     ReleasePageRef_(pageRef.Handle);
 }
 PSPDFPageInfo PageInfoForPage(uint page, CGPDFPage pageRef)
 {
     return(PageInfoForPage_(page, pageRef.Handle));
 }
		public PdfScrollView (CGRect frame)
			: base (frame)
		{
			ShowsVerticalScrollIndicator = false;
			ShowsHorizontalScrollIndicator = false;
			BouncesZoom = true;
			DecelerationRate = UIScrollView.DecelerationRateFast;
			BackgroundColor = UIColor.Gray;
			MaximumZoomScale = 5.0f;
			MinimumZoomScale = 0.25f;

			// open the PDF file (default directory is the bundle path)
			pdf = CGPDFDocument.FromFile ("Tamarin.pdf");
			// select the first page (the only one we'll use)
			page = pdf.GetPage (1);

			// make the initial view 'fit to width'
			CGRect pageRect = page.GetBoxRect (CGPDFBox.Media);
			scale = Frame.Width / pageRect.Width;
			pageRect.Size = new CGSize (pageRect.Width * scale, pageRect.Height * scale);

			// create bitmap version of the PDF page, to be used (scaled)
			// when no other (tiled) view are visible
			UIGraphics.BeginImageContext (pageRect.Size);
			CGContext context = UIGraphics.GetCurrentContext ();

			// fill with white background
			context.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
			context.FillRect (pageRect);
			context.SaveState ();

			// flip page so we render it as it's meant to be read
			context.TranslateCTM (0.0f, pageRect.Height);
			context.ScaleCTM (1.0f, -1.0f);

			// scale page at the view-zoom level
			context.ScaleCTM (scale, scale);
			context.DrawPDFPage (page);
			context.RestoreState ();

			UIImage backgroundImage = UIGraphics.GetImageFromCurrentImageContext ();
			UIGraphics.EndImageContext ();

			backgroundImageView = new UIImageView (backgroundImage);
			backgroundImageView.Frame = pageRect;
			backgroundImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
			AddSubview (backgroundImageView);
			SendSubviewToBack (backgroundImageView);

			// Create the TiledPDFView based on the size of the PDF page and scale it to fit the view.
			pdfView = new TiledPdfView (pageRect, (float)scale);
			pdfView.Page = page;
			AddSubview (pdfView);

			// no need to have (or set) a UIScrollViewDelegate with MonoTouch

			this.ViewForZoomingInScrollView = delegate {
				// return the view we'll be using while zooming
				return pdfView;
			};

			// when zooming starts we remove (from view) and dispose any
			// oldPdfView and set pdfView as our 'new' oldPdfView, it will
			// stay there until a new view is available (when zooming ends)
			this.ZoomingStarted += delegate {
				if (oldPdfView != null) {
					oldPdfView.RemoveFromSuperview ();
					oldPdfView.Dispose ();
				}
				oldPdfView = pdfView;
				AddSubview (oldPdfView);
			};

			// when zooming ends a new TiledPdfView is created (and shown)
			// based on the updated 'scale' and 'frame'
			ZoomingEnded += delegate (object sender, ZoomingEndedEventArgs e) {
				scale *= e.AtScale;

				CGRect rect = page.GetBoxRect (CGPDFBox.Media);
				rect.Size = new CGSize (rect.Width * scale, rect.Height * scale);

				pdfView = new TiledPdfView (rect, (float)scale);
				pdfView.Page = page;
				AddSubview (pdfView);
			};
		}
 public static SizeF RenderPage(CGPDFPage page, CGContext context, PointF point, float zoom, PSPDFPageInfo pageInfo, PSPDFAnnotation[] annotations, NSDictionary options)
 {
     return(RenderPage_(page.Handle, context.Handle, point, zoom, pageInfo, annotations, options));
 }
 public virtual PSPDFAnnotation[] ParseAnnotations(uint page, CGPDFPage pageRef)
 {
     if (pageRef == null)
         return ParseAnnotations (page, IntPtr.Zero);
     else
         return ParseAnnotations (page, pageRef.Handle);
 }
Beispiel #42
0
        private List <UIImage> ConvertToImages( )
        {
            Images = new List <UIImage>();

            if (Doc == null)
            {
                throw new Exception("Could not load document");
            }

            for (Int32 i = 1; i <= Count; i++)
            {
                using (CGPDFPage Page = Doc.GetPage(i))
                {
                    CGRect PageRect = Page.GetBoxRect(CGPDFBox.Media);
                    //nfloat Scale = 1;//View.Frame.Height / PageRect.Height;
                    //PageRect.Size = new CGSize(PageRect.Height * Scale, PageRect.Width * Scale);

                    if (PageRect.Height > PageRect.Width)
                    {
                        PageRect.Size = new CGSize(PageRect.Height, PageRect.Width);
                    }

                    CGRect MediaBox = Page.GetBoxRect(CGPDFBox.Media);
                    CGRect CropBox  = Page.GetBoxRect(CGPDFBox.Crop);

                    nfloat TopMargin    = CropBox.GetMinY() - MediaBox.GetMinY();
                    nfloat BottomMargin = MediaBox.GetMaxY() - CropBox.GetMaxY();
                    nfloat LeftMargin   = CropBox.GetMinX() - MediaBox.GetMinX();
                    nfloat RightMargin  = MediaBox.GetMaxX() - CropBox.GetMaxX();

                    if (TopMargin + BottomMargin + LeftMargin + RightMargin > 0)
                    {
                        PageRect = new CGRect(
                            PageRect.Location,
                            new CGSize(
                                PageRect.Size.Width - (LeftMargin + RightMargin),
                                PageRect.Size.Height - (TopMargin + BottomMargin)
                                )
                            );
                    }

                    UIGraphics.BeginImageContext(PageRect.Size);

                    using (CGContext context = UIGraphics.GetCurrentContext())
                    {
                        context.SaveState();

                        context.TranslateCTM(0, PageRect.Size.Height);
                        context.ScaleCTM(1, -1);

                        context.ConcatCTM(
                            Page.GetDrawingTransform(CGPDFBox.Crop, PageRect, 0, true)
                            );

                        context.DrawPDFPage(Page);
                        context.RestoreState();

                        Images.Add(UIGraphics.GetImageFromCurrentImageContext());
                    }

                    UIGraphics.EndImageContext();
                }
            }
            return(Images);
        }
 public virtual PSPDFPageInfo PageInfoForPage(nuint page, CGPDFPage pageRef)
 {
     if (pageRef == null)
         return PageInfoForPage (page, IntPtr.Zero);
     else
         return PageInfoForPage (page, pageRef.Handle);
 }
 public static SizeF RenderPage(CGPDFPage page, CGContext context, PointF point, float zoom, PSPDFPageInfo pageInfo, PSPDFAnnotation[] annotations, NSDictionary options)
 {
     return RenderPage_ (page.Handle, context.Handle, point, zoom, pageInfo, annotations, options);
 }
Beispiel #45
0
        protected override void Dispose(bool disposing)
        {
            if (oTiledLayer != null)
                oTiledLayer.RemoveFromSuperLayer ();

            if (oContentView != null)
                oContentView.RemoveFromSuperview ();

            if (scroll_area != null)
                scroll_area.RemoveFromSuperview();

            if (tiled_layer_delegate != null)
                tiled_layer_delegate.Dispose ();

            if (scroll_area_delegate != null)
                scroll_area_delegate.Dispose ();

            if (scroll_area != null)
                scroll_area.Delegate = null;

            if (oTiledLayer != null)
                oTiledLayer.Delegate = null;

            scroll_area_delegate = null;

            tiled_layer_delegate = null;

            if (currentPDFPage != null)
                currentPDFPage.Dispose ();

            currentPDFPage = null;

            if (oTiledLayer != null)
                oTiledLayer.Dispose ();

            oTiledLayer = null;

            base.Dispose (disposing);
        }
 public MonoTouch.UIKit.UIImage CachedImageForDocument(PSPDFDocument document, uint page, PSPDFSize size, CGPDFPage /*CGPDFPageRef*/ pdfPage)
 {
     return CachedImageForDocument_ (document, page, size, pdfPage.Handle);
 }
Beispiel #47
0
 public virtual RectangleF RenderPageRef(CGPDFPage page, CGContext context, RectangleF rectangle, PSPDFPageInfo pageInfo, PSPDFAnnotation[] annotations, NSDictionary options)
 {
     return RenderPageRef_ (page.Handle, context, rectangle, pageInfo, annotations, options);
 }
 public void FreeWithPDFPageRef(CGPDFPage pdfPage)
 {
     _FreeWithPDFPageRef(pdfPage.Handle, true);
 }
Beispiel #49
0
 public virtual PSPDFAnnotation[] AnnotationsForPage(uint page, PSPDFAnnotationType type, CGPDFPage pageRef)
 {
     return AnnotationsForPage_ (page, type, pageRef.Handle);
 }
Beispiel #50
0
        bool GenerateImage(Dictionary <Page, eBriefingMobile.Annotation> dict1, Dictionary <Page, List <eBriefingMobile.Note> > dict2)
        {
            try
            {
                if (pageList != null)
                {
                    nuint       totalImageSize = 0;
                    List <Note> notes          = new List <eBriefingMobile.Note> ();

                    foreach (var page in pageList)
                    {
                        String localPath     = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                        var    printItemDict = new Dictionary <UIImage, List <Note> >();

                        if (!String.IsNullOrEmpty(localPath))
                        {
                            CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                            if (pdfDoc != null)
                            {
                                CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                if (pdfPage != null)
                                {
                                    CGRect  pageRect = pdfPage.GetBoxRect(CGPDFBox.Media);
                                    UIImage pdfImg   = ImageHelper.PDF2Image(pdfPage, pageRect.Width, scale);

                                    // Add annotation if option selected
                                    if (dict1.ContainsKey(page))
                                    {
                                        Annotation annotation = dict1 [page];
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> coordinateDict = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (coordinateDict != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in coordinateDict)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value);

                                                    if (annImg != null)
                                                    {
                                                        // Scale down the annotation image
                                                        annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height));

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, scale);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Create image from text
                                    bool    printNote = false;
                                    UIImage noteImg   = null;
                                    if (dict2.ContainsKey(page) && dict2 [page] != null)
                                    {
                                        printNote = true;
                                        notes     = dict2 [page];

                                        // Create image from text
                                        //noteImg = ImageHelper.Text2Image(_notesText, pdfImg.Size);
                                    }
                                    else
                                    {
                                        notes = null;
                                    }

                                    // Scale down and add to canvas
                                    // Used 900 and 1200 because couldn't control the paper margin
//								if (Orientation == ORIENTATION.PORTRAIT)
//								{
//									//if (printNote)
//									{
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0, (1024 / 2) - (pdfImg.Size.Height / 2)), scale);
//
//										// Overlap pdfImg and noteImg
//										//pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(500, 0), scale);
//									}
//									//else
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 900);
//										//pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((768 / 2) - (pdfImg.Size.Width / 2), (1024 / 2) - (pdfImg.Size.Height / 2)), scale);
//									}
//								}
//								else
//								{
//									//if (printNote)
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,500,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//									//		pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0,0), scale*2, UIInterfaceOrientation.LandscapeLeft);
//										// Overlap pdfImg and noteImg
//										//pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(756, 0), scale);
//									}
//									//else
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//										///pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((1024 / 2) - (pdfImg.Size.Width / 2), (768 / 2) - (pdfImg.Size.Height / 2)), scale*2, UIInterfaceOrientation.LandscapeLeft);
//									}
//
//									// Rotate canvas
//									//pdfImg = ImageHelper.Rotate(pdfImg);
//								}

                                    // Save
//								if (printItems == null)
//								{
//									printItems = new List<UIImage>();
//								}
//								printItems.Add(pdfImg);

                                    if (dict == null)
                                    {
                                        dict = new Dictionary <int, Dictionary <UIImage, List <Note> > > ();
                                    }

                                    if (pdfImg != null)
                                    {
                                        printItemDict.Add(pdfImg, notes);
                                        dict.Add(page.PageNumber, printItemDict);

                                        var pngImage = pdfImg.AsPNG();
                                        totalImageSize = pngImage.Length + totalImageSize;
                                        Console.WriteLine("Img : " + totalImageSize.ToString());

                                        //image dispose
                                        pdfImg = null;

                                        if (CheckReachMemoryLimit(totalImageSize))
                                        {
                                            PagesNum = dict.Count - 1;

                                            dict.Clear();
                                            dict = null;

                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    PagesNum = dict.Count;

                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public void ReleasePageRef(CGPDFPage pageRef)
 {
     ReleasePageRef_ (pageRef.Handle);
 }
		private static UIImage RenderImage (CGPDFPage page)
		{

			var rect = page.GetBoxRect (CGPDFBox.Crop);
			var pageRotation = page.RotationAngle;
			var size = rect.Size;

			UIGraphics.BeginImageContextWithOptions (size, false, (nfloat)(1));

			var context = UIGraphics.GetCurrentContext ();
			context.SaveState ();
			context.TranslateCTM ((nfloat)0.0, size.Height);
			context.ScaleCTM (One, (nfloat)(-1.0));

			context.SetFillColor (One, One);
			context.FillRect (rect);

			var transform = page.GetDrawingTransform (CGPDFBox.Crop, rect, 0, true);
			context.ConcatCTM (transform);
			context.DrawPDFPage (page);

			var image = UIGraphics.GetImageFromCurrentImageContext ();
			context.RestoreState ();
			UIGraphics.EndImageContext ();

			return image;
		}
 public virtual PSPDFAnnotation[] ParseAnnotationsForPage(uint page, CGPDFPage pageRef)
 {
     return ParseAnnotationsForPage_ (page, pageRef.Handle);
 }
 public PSPDFAnnotation [] AnnotationsForPage(uint page, PSPDFAnnotationType type, CGPDFPage /*CGPDFPageRef*/ pageRef)
 {
     return(AnnotationsForPage_(page, type, pageRef.Handle));
 }