Пример #1
0
        private void ShowAnnotationCollections()
        {
            try
            {
                List <Page> pageList = new List <Page>();

                for (int i = 0; i < (int)this.Document.PageCount; i++)
                {
                    Page page = BooksOnDeviceAccessor.GetPage(book.ID, (nint)i + 1);
                    if (page != null)
                    {
                        Annotation annotation = AnnotationsDataAccessor.GetAnnotation(book.ID, page.ID);
                        if (annotation != null)
                        {
                            pageList.Add(page);
                        }
                    }
                }

                ShowCollectionView(new NSString("AnnotationCell"), pageList);
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("PageViewController - ShowAnnotationCollections: {0}", ex.ToString());
            }
        }
Пример #2
0
 public void AddAnnotations()
 {
     try
     {
         for (nint i = 0; i < (nint)this.Document.PageCount; i++)
         {
             Page page = BooksOnDeviceAccessor.GetPage(book.ID, i + 1);
             if (page != null)
             {
                 Annotation annotation = BooksOnDeviceAccessor.GetAnnotation(book.ID, page.ID);
                 if (annotation != null)
                 {
                     Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)i, annotation);
                     if (dictionary != null)
                     {
                         List <PSPDFAnnotation> annList = new List <PSPDFAnnotation>();
                         foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                         {
                             annList.Add(item.Value);
                         }
                         this.Document.AddAnnotations(annList.ToArray());
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.WriteLineDebugging("CustomPSPDFViewController - AddAnnotations: {0}", ex.ToString());
     }
 }
Пример #3
0
        public static UIImage DrawPSPDFAnnotation(String pointStr, PSPDFInkAnnotation annotation)
        {
            try
            {
                CGSize pdfSize = AnnotationsDataAccessor.GetPDFSize(pointStr);

                if (!pdfSize.IsEmpty)
                {
                    // Begin a graphics context of sufficient size
                    UIGraphics.BeginImageContext(pdfSize);

                    // Get the context for CoreGraphics
                    CGContext ctx = UIGraphics.GetCurrentContext();

                    // Set stroking color
                    annotation.Color.SetStroke();

                    // Set line width
                    ctx.SetLineWidth(annotation.LineWidth);

                    // Set alpha
                    ctx.SetAlpha(annotation.Alpha);

                    // Set path
                    CGPath         path      = new CGPath();
                    List <CGPoint> pointList = AnnotationsDataAccessor.GenerateViewPointLines(pointStr);
                    if (pointList != null)
                    {
                        path.MoveToPoint(pointList[0].X, pointList[0].Y);
                        for (int i = 1; i < pointList.Count; i++)
                        {
                            if (i + 1 < pointList.Count)
                            {
                                path.AddLineToPoint(pointList[i].X, pointList[i].Y);
                            }
                        }
                        ctx.AddPath(path);
                    }

                    // Draw
                    ctx.StrokePath();

                    // Make image out of bitmap context
                    UIImage newImg = UIGraphics.GetImageFromCurrentImageContext();

                    UIGraphics.EndImageContext();

                    return(newImg);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ImageHelper - DrawPSPDFAnnotation: {0}", ex.ToString());
            }

            return(null);
        }
        public static void MarkAsRemovedAnnotation(String bookID, String pageID)
        {
            Annotation annotation = GetAnnotation(bookID, pageID);

            if (annotation != null)
            {
                annotation.Removed     = true;
                annotation.ModifiedUtc = DateTime.UtcNow;
                AnnotationsDataAccessor.UpdateAnnotation(annotation);
            }
        }
Пример #5
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);
            }
        }
Пример #6
0
        private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // activityIndicator
                UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView();
                activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.White;
                activityIndicator.StartAnimating();
                activityIndicator.HidesWhenStopped = true;
                activityIndicator.Frame            = new RectangleF((this.Frame.Width / 2) - 10, (this.Frame.Height / 2) - 10, 20, 20);
                this.AddSubview(activityIndicator);

                // Generate pdf thumbnail
                Page             page       = null;
                Annotation       annotation = null;
                BackgroundWorker worker     = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    page = BooksOnDeviceAccessor.GetPage(bookID, pageID);

                    if (String.IsNullOrEmpty(text))
                    {
                        annotation = BooksOnDeviceAccessor.GetAnnotation(bookID, pageID);
                    }
                };
                worker.RunWorkerCompleted += delegate
                {
                    this.InvokeOnMainThread(delegate
                    {
                        activityIndicator.StopAnimating();

                        if (page != null)
                        {
                            String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                            if (!String.IsNullOrEmpty(localPath))
                            {
                                CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                                if (pdfDoc != null)
                                {
                                    CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                    if (pdfPage != null)
                                    {
                                        UIImage pdfImg = PDFConverter.Transform2Image(pdfPage, this.Frame.Width);

                                        // pageView
                                        UIImageView pageView = new UIImageView();
                                        pageView.Frame       = new RectangleF(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                        // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (dictionary != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = DrawAnnotation(item.Key, item.Value);

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

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = Overlap(pdfImg, annImg);
                                                    }
                                                }
                                            }
                                        }

                                        pageView.Image = pdfImg;
                                        this.AddSubview(pageView);

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

                                        // Add ribbon if this is bookmark thumbnail
                                        if (bookmark)
                                        {
                                            UIImageView ribbon = new UIImageView();
                                            ribbon.Image       = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                            ribbon.Frame       = new RectangleF(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                            this.AddSubview(ribbon);
                                        }

                                        // Do not add text if this is annotation thumbnail
                                        if (!String.IsNullOrEmpty(text))
                                        {
                                            // titleLabel
                                            UILabel titleLabel         = new UILabel();
                                            titleLabel.Frame           = new RectangleF(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                            titleLabel.Font            = UIFont.SystemFontOfSize(16f);
                                            titleLabel.BackgroundColor = UIColor.Clear;
                                            titleLabel.TextColor       = eBriefingAppearance.DarkGrayColor;
                                            titleLabel.Lines           = 2;
                                            titleLabel.LineBreakMode   = UILineBreakMode.TailTruncation;
                                            titleLabel.TextAlignment   = UITextAlignment.Center;
                                            titleLabel.Text            = text;
                                            this.AddSubview(titleLabel);
                                        }
                                    }
                                }
                            }
                        }
                    });
                };
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
 public static String GetNumAnnotationsInChapter(String bookID, String chapterID)
 {
     return(AnnotationsDataAccessor.GetNumAnnotationsInChapter(bookID, chapterID).ToString());
 }
 public static String GetNumAnnotationsInBook(String bookID)
 {
     return(AnnotationsDataAccessor.GetNumAnnotationsInBook(bookID).ToString());
 }
 public static Annotation GetAnnotation(String bookID, String pageID)
 {
     return(AnnotationsDataAccessor.GetAnnotation(bookID, pageID));
 }
 public static List <Annotation> GetRemovedAnnotations(String bookID)
 {
     return(AnnotationsDataAccessor.GetRemovedAnnotations(bookID));
 }
 public static void UpdateAnnotation(Annotation annotation)
 {
     AnnotationsDataAccessor.UpdateAnnotation(annotation);
 }
 public static void UpdateAnnotations(String bookID, List <Page> pageList)
 {
     AnnotationsDataAccessor.UpdateAnnotations(bookID, pageList);
 }
 public static void RemoveAnnotation(String bookID, String pageID)
 {
     AnnotationsDataAccessor.RemoveAnnotation(bookID, pageID);
 }
 public static void AddAnnotation(Annotation annotation)
 {
     AnnotationsDataAccessor.AddAnnotation(annotation);
 }
Пример #15
0
        async private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // spinner
                RTSpinKitView spinner = eBriefingAppearance.GenerateBounceSpinner();
                spinner.Center = this.Center;
                this.AddSubview(spinner);

                // Generate pdf thumbnail
                Page page = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetPage(bookID, pageID));

                Annotation annotation = null;
                if (String.IsNullOrEmpty(text))
                {
                    annotation = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetAnnotation(bookID, pageID));
                }

                spinner.StopAnimating();

                if (page != null)
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    if (!String.IsNullOrEmpty(localPath))
                    {
                        CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                        if (pdfDoc != null)
                        {
                            CGPDFPage pdfPage = pdfDoc.GetPage(1);
                            if (pdfPage != null)
                            {
                                UIImage pdfImg = ImageHelper.PDF2Image(pdfPage, this.Frame.Width, UIScreen.MainScreen.Scale);

                                // pageView
                                UIImageView pageView = new UIImageView();
                                pageView.Frame = new CGRect(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                if (annotation != null)
                                {
                                    Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)page.PageNumber - 1, annotation);
                                    if (dictionary != null)
                                    {
                                        foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                        {
                                            // 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, UIScreen.MainScreen.Scale);
                                            }
                                        }
                                    }
                                }

                                pageView.Image = pdfImg;
                                this.AddSubview(pageView);

                                if (pdfImg.Size.Height < this.Frame.Height)
                                {
                                    this.BackgroundColor = UIColor.Clear;
                                }

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

                                // Add ribbon if this is bookmark thumbnail
                                if (bookmark)
                                {
                                    UIImageView ribbon = new UIImageView();
                                    ribbon.Image = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                    ribbon.Frame = new CGRect(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                    this.AddSubview(ribbon);
                                }

                                // Do not add text if this is annotation thumbnail
                                if (!String.IsNullOrEmpty(text))
                                {
                                    // titleLabel
                                    UILabel titleLabel = eBriefingAppearance.GenerateLabel(16);
                                    titleLabel.Frame         = new CGRect(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                    titleLabel.Lines         = 2;
                                    titleLabel.LineBreakMode = UILineBreakMode.TailTruncation;
                                    titleLabel.TextAlignment = UITextAlignment.Center;
                                    titleLabel.Text          = text;
                                    this.AddSubview(titleLabel);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
Пример #16
0
        public List <AnnotationItem> GenerateParseItem(nuint page, PSPDFAnnotationType type)
        {
            List <AnnotationItem> items = null;

            PSPDFAnnotation[] anns = this.Document.AnnotationsForPage(page, type);
            if (anns != null)
            {
                if (anns.Length > 0)
                {
                    items = new List <AnnotationItem>();

                    PSPDFPageView pageView = this.PageViewForPage(page);
                    if (pageView != null)
                    {
                        for (int i = 0; i < anns.Length; i++)
                        {
                            if (!anns[i].Deleted)
                            {
                                String             dictionaryKey = StringRef.Pen;
                                PSPDFInkAnnotation ann           = (PSPDFInkAnnotation)anns[i];
                                if (ann.LineWidth > 10)
                                {
                                    dictionaryKey = StringRef.Highlighter;
                                }
                                dictionaryKey += " " + i.ToString();

                                // boundingBox
                                String description = String.Empty;
                                String boundingBox = ann.DictionaryValue["boundingBox"].ToString();
                                description += "[BoundingBox]" + boundingBox;

                                // color
                                String color = ann.DictionaryValue["color"].ToString();
                                description += "[Color]" + color;

                                // lineWidth
                                String lineWidth = ann.DictionaryValue["lineWidth"].ToString();
                                description += "[LineWidth]" + lineWidth;

                                // Add description to the dictionary
                                items.Add(new AnnotationItem(dictionaryKey, description));

                                // Lines
                                String points  = String.Empty;
                                String pdfSize = StringRef.pdfSize + pageView.Frame.Width + "x" + pageView.Frame.Height;
                                for (int j = 0; j < ann.Lines.Count; j++)
                                {
                                    if (j != 0)
                                    {
                                        points += StringRef.annDivider;
                                    }

                                    String pointStr = String.Empty;
                                    if (ann.Lines[j] != null && ann.Lines[j].Length > 0)
                                    {
                                        for (int k = 0; k < ann.Lines[j].Length; k++)
                                        {
                                            pointStr += ann.Lines[j][k].ToString();
                                        }
                                    }

                                    List <CGPoint> pointList = AnnotationsDataAccessor.GeneratePointF(pointStr);
                                    if (pointList != null && pointList.Count > 0)
                                    {
                                        points += pdfSize + StringRef.viewPoints;
                                        foreach (CGPoint point in pointList)
                                        {
                                            points += pageView.ConvertPdfPointToViewPoint(point);
                                        }

                                        points += StringRef.pdfPoints;
                                        foreach (CGPoint point in pointList)
                                        {
                                            points += point;
                                        }
                                    }
                                }

                                // Add line points to the dictionary
                                items.Add(new AnnotationItem(dictionaryKey, points));
                            }
                        }
                    }
                }
            }

            return(items);
        }