public static void SimplifyAnnotations()
        {
            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return;
            }

            Location location = previewControl.ActiveLocation;

            if (location == null)
            {
                return;
            }

            Reference reference = location.Reference;

            if (reference == null)
            {
                return;
            }

            List <Annotation> annotations = previewControl.GetPdfViewControl().GetSelectedAnnotations().ToList();

            foreach (Annotation annotation in annotations)
            {
                List <Quad> newQuads = new List <Quad>();
                foreach (int i in annotation.Quads.Select(q => q.PageIndex).Distinct())
                {
                    List <Quad> quadsOnPage = annotation.Quads.Where(q => q.PageIndex == i).ToList();

                    newQuads.AddRange(quadsOnPage.SimpleQuads());
                }
                annotation.Quads = newQuads;
            }
        }
Exemple #2
0
        public GoToPageForm(MainForm owner, PdfViewControl pdfViewControl)
        {
            InitializeComponent();

            _labels         = new List <PageLabelWrapper>();
            Owner           = _mainForm = owner;
            _pdfViewControl = pdfViewControl;
            Icon            = owner.Icon;
        }
Exemple #3
0
        internal static TabControl GetSideBar(this PdfViewControl pdfViewControl)
        {
            if (pdfViewControl == null)
            {
                return(null);
            }

            return(WPFHelper.FindChild <TabControl>(pdfViewControl));
        }
Exemple #4
0
 public static IEnumerable <Annotation> GetSelectedAnnotations(this PdfViewControl pdfViewControl)
 {
     return(pdfViewControl?
            .Tool
            .GetSelectedHighlights()?
            .Select(adornmentCanvas => adornmentCanvas.Annotation)
            .Where(annotation => annotation != null)
            .Distinct()
            .ToList());
 }
Exemple #5
0
 public static IEnumerable <ICitaviEntity> GetSelectedCitaviEntities(this PdfViewControl pdfViewControl)
 {
     return(pdfViewControl?
            .Tool
            .GetSelectedHighlights()?
            .Where(adornmentCanvas => adornmentCanvas.CitaviEntity != null)
            .Select(adornmentCanvas => adornmentCanvas.CitaviEntity)
            .Where(entity => entity != null)
            .Distinct()
            .ToList());
 }
        public static List <Annotation> EquivalentAnnotations(this Highlight highlight)
        {
            List <Annotation> equivalentAnnotations = new List <Annotation>();

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

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

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

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

            Document document = pdfViewControl.Document;

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

            Project project = Program.ActiveProjectShell.Project;

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

            Location location = previewControl.ActiveLocation;

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

            List <Annotation> annotationsAtThisLocation = location.Annotations.ToList();

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

            equivalentAnnotations.AddRange(annotationsAtThisLocation.Where(a => !highlight.AsAnnotationQuads().RoundedQuads().Except(a.Quads.ToList().RoundedQuads()).Any()));
            equivalentAnnotations.AddRange(annotationsAtThisLocation.Where(a => !highlight.AsAnnotationQuads().SimpleQuads().RoundedQuads().Except(a.Quads.ToList().RoundedQuads()).Any()));

            return(equivalentAnnotations);
        }
Exemple #7
0
        void KnowledgeItemPreviewSmartRepeater_ActiveListItemChanged(object o, EventArgs a)
        {
            if (Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().Count == 0)
            {
                return;
            }

            KnowledgeItem activeQuotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().FirstOrDefault();

            if (activeQuotation.EntityLinks == null)
            {
                return;
            }
            if (activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0)
            {
                return;
            }

            Annotation annotation = activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation;

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            if (previewControl.ActiveLocation != annotation.Location)
            {
                Program.ActiveProjectShell.ShowPreviewFullScreenForm(annotation.Location, previewControl, null);
            }
            pdfViewControl.GoToAnnotation(annotation);

            Program.ActiveProjectShell.PrimaryMainForm.Activate();
        }
        public static Annotation TemporaryAnnotation(this Highlight highlight)
        {
            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

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

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

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

            Document document = pdfViewControl.Document;

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

            Location location = previewControl.ActiveLocation;

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

            Annotation temporaryAnnotation = new Annotation(location);

            temporaryAnnotation.Quads         = highlight.AsAnnotationQuads().TemporaryQuads();
            temporaryAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
            temporaryAnnotation.Visible       = true;

            return(temporaryAnnotation);
        }
Exemple #9
0
        public static void CreateCommentAnnotation(List <KnowledgeItem> quotations)
        {
            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Annotation lastAnnotation = null;

            foreach (KnowledgeItem quotation in quotations)
            {
                if (quotation.EntityLinks.Any() && quotation.EntityLinks.Where(link => link.Target is KnowledgeItem).FirstOrDefault() != null)
                {
                    Reference reference = quotation.Reference;
                    if (reference == null)
                    {
                        return;
                    }

                    Project project = reference.Project;
                    if (project == null)
                    {
                        return;
                    }

                    KnowledgeItem mainQuotation = quotation.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Target as KnowledgeItem;

                    Annotation mainQuotationAnnotation = mainQuotation.EntityLinks.Where(link => link.Target is Annotation && link.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation;
                    if (mainQuotationAnnotation == null)
                    {
                        return;
                    }

                    Location location = mainQuotationAnnotation.Location;
                    if (location == null)
                    {
                        return;
                    }

                    List <Annotation> oldAnnotations = quotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Select(e => (Annotation)e.Target).ToList();

                    foreach (Annotation oldAnnotation in oldAnnotations)
                    {
                        location.Annotations.Remove(oldAnnotation);
                    }

                    Annotation newAnnotation = new Annotation(location);

                    newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
                    newAnnotation.Quads         = mainQuotationAnnotation.Quads;
                    newAnnotation.Visible       = false;
                    location.Annotations.Add(newAnnotation);


                    EntityLink newEntityLink = new EntityLink(project);
                    newEntityLink.Source     = quotation;
                    newEntityLink.Target     = newAnnotation;
                    newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication;
                    project.EntityLinks.Add(newEntityLink);

                    lastAnnotation = newAnnotation;
                }
                pdfViewControl.GoToAnnotation(lastAnnotation);
            }
        }
Exemple #10
0
        public static KnowledgeItem CombineQuotations(List <KnowledgeItem> quotations)
        {
            if (quotations.Count() == 1)
            {
                return(quotations.FirstOrDefault());
            }
            if (quotations.Count == 0)
            {
                return(null);
            }

            // Static Variables

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

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

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

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

            Document document = pdfViewControl.Document;

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

            Reference reference = quotations.FirstOrDefault().Reference;

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

            Project project = Program.ActiveProjectShell.Project;

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

            List <Location> locations = quotations.GetPDFLocations().Distinct().ToList();

            if (locations.Count != 1)
            {
                return(null);
            }
            Location location = locations.FirstOrDefault();

            List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList();
            var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight);

            quotationTypes.Remove(itemToRemove);

            QuotationType quotationType = quotationTypes.FirstOrDefault();

            if (quotationTypes.Count == 0)
            {
                quotationType = QuotationType.Highlight;
            }

            // Dynamic Variables

            KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType);

            string text = string.Empty;

            List <Quad>      quads          = new List <Quad>();
            List <PageRange> pageRangesList = new List <PageRange>();
            string           pageRangeText  = string.Empty;

            List <PageWidth> store = new List <PageWidth>();

            // The Magic

            if (document != null)
            {
                for (int i = 1; i <= document.GetPageCount(); i++)
                {
                    pdftron.PDF.Page page = document.GetPage(i);
                    if (page.IsValid())
                    {
                        var re = page.GetCropBox();
                        store.Add(new PageWidth(location, i, re.Width()));
                    }
                    else
                    {
                        store.Add(new PageWidth(location, i, 0.00));
                    }
                }
            }

            quotations.Sort(new KnowledgeItemComparer(store));

            foreach (KnowledgeItem quotation in quotations)
            {
                if (!string.IsNullOrEmpty(quotation.Text))
                {
                    text = MergeRTF(text, quotation.TextRtf);
                }
                if (!string.IsNullOrEmpty(quotation.PageRange.OriginalString))
                {
                    pageRangesList.Add(quotation.PageRange);
                }
            }

            pageRangesList = PageRangeMerger.MergeAdjacent(pageRangesList);
            pageRangeText  = PageRangeMerger.PageRangeListToString(pageRangesList);

            newQuotation.TextRtf   = text;
            newQuotation.PageRange = pageRangeText;
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumberingType);
            newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumeralSystem);

            reference.Quotations.Add(newQuotation);
            project.AllKnowledgeItems.Add(newQuotation);

            return(newQuotation);
        }
Exemple #11
0
        public static void MergeAnnotations()
        {
            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return;
            }

            Location location = previewControl.ActiveLocation;

            if (location == null)
            {
                return;
            }

            Reference reference = location.Reference;

            if (reference == null)
            {
                return;
            }

            List <Annotation> annotations = pdfViewControl.GetSelectedAnnotations().ToList();

            List <KnowledgeItem> quotations = annotations
                                              .Where
                                              (
                a =>
                a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0
                                              )
                                              .Select
                                              (
                a =>
                (KnowledgeItem)a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source
                                              )
                                              .ToList();

            List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList();
            var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight);

            quotationTypes.Remove(itemToRemove);

            if (quotations.Count() > 0)
            {
                if (quotationTypes.Count > 1)
                {
                    MessageBox.Show("Can't merge quotations, more than one type of quotation is selected.");
                    return;
                }
            }

            // Dynamic Variables

            // The Magic

            KnowledgeItem newQuotation  = CombineQuotations(quotations);
            Annotation    newAnnotation = CombineAnnotations(annotations);

            if (quotations.Count() > 1)
            {
                EntityLink newEntityLink = new EntityLink(project);
                newEntityLink.Source     = newQuotation;
                newEntityLink.Target     = newAnnotation;
                newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication;
                project.EntityLinks.Add(newEntityLink);
                newAnnotation.Visible = false;
                reference.Quotations.RemoveRange(quotations);
            }
            else if (quotations.Count == 1)
            {
                EntityLink newEntityLink = new EntityLink(project);
                newEntityLink.Source     = quotations.FirstOrDefault();
                newEntityLink.Target     = newAnnotation;
                newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication;
                project.EntityLinks.Add(newEntityLink);
                newAnnotation.Visible = false;
            }

            if (quotations.Count > 1 && quotationTypes.Count > 0)
            {
                Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, newQuotation);
            }
        }
        public static bool CreateNewQuotationAndAnnotationFromHighlight(this Highlight highlight, QuotationType quotationType, bool ImportEmptyAnnotations, bool RedrawAnnotations, List <Annotation> temporaryAnnotations)
        {
            string highlightContents = highlight.GetContents();

            if (string.IsNullOrEmpty(highlightContents) && !ImportEmptyAnnotations)
            {
                return(false);
            }

            Project project = Program.ActiveProjectShell.Project;

            if (project == null)
            {
                return(false);
            }

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return(false);
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return(false);
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return(false);
            }

            Location location = previewControl.ActiveLocation;

            if (location == null)
            {
                return(false);
            }

            Reference reference = location.Reference;

            if (reference == null)
            {
                return(false);
            }


            // Dynamic variables

            KnowledgeItem newQuotation       = null;
            KnowledgeItem newDirectQuotation = null;

            TextContent textContent = null;

            // Does any other annotation with the same quads already exist?

            Annotation existingAnnotation = highlight.EquivalentAnnotations().FirstOrDefault();

            if ((string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) || quotationType == QuotationType.Comment)

            {
                Annotation temporaryAnnotation = temporaryAnnotations.Where(a => !highlight.AsAnnotationQuads().TemporaryQuads().Except(a.Quads.ToList()).Any()).FirstOrDefault();
                if (temporaryAnnotation != null)
                {
                    pdfViewControl.GoToAnnotation(temporaryAnnotation);
                    textContent = (TextContent)pdfViewControl.GetSelectedContentFromType(pdfViewControl.GetSelectedContentType(), -1, false, true);
                    location.Annotations.Remove(temporaryAnnotation);
                }
                else
                {
                    return(false);
                }
            }

            int startPage = 1;

            if (reference.PageRange.StartPage.Number != null)
            {
                startPage = reference.PageRange.StartPage.Number.Value;
            }

            string pageRangeString = (startPage + highlight.GetPage().GetIndex() - 1).ToString();

            Annotation knowledgeItemIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations);

            switch (quotationType)
            {
            case QuotationType.Comment:
                if (!string.IsNullOrEmpty(highlightContents))
                {
                    newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType);
                    reference.Quotations.Add(newQuotation);
                    project.AllKnowledgeItems.Add(newQuotation);
                    newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);

                    if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected)
                    {
                        Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations);
                        newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation);
                        reference.Quotations.Add(newDirectQuotation);
                        project.AllKnowledgeItems.Add(newDirectQuotation);
                        newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation);

                        EntityLink commentDirectQuotationLink = new EntityLink(project);
                        commentDirectQuotationLink.Source     = newQuotation;
                        commentDirectQuotationLink.Target     = newDirectQuotation;
                        commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication;
                        project.EntityLinks.Add(commentDirectQuotationLink);

                        newQuotation.CoreStatement           = newDirectQuotation.CoreStatement + " (Comment)";
                        newQuotation.CoreStatementUpdateType = UpdateType.Manual;
                    }
                }
                else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations)
                {
                    newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType);
                    reference.Quotations.Add(newQuotation);
                    project.AllKnowledgeItems.Add(newQuotation);
                    newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);

                    if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected)
                    {
                        Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations);
                        newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation);
                        reference.Quotations.Add(newDirectQuotation);
                        project.AllKnowledgeItems.Add(newDirectQuotation);
                        newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation);

                        EntityLink commentDirectQuotationLink = new EntityLink(project);
                        commentDirectQuotationLink.Source     = newQuotation;
                        commentDirectQuotationLink.Target     = newDirectQuotation;
                        commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication;
                        project.EntityLinks.Add(commentDirectQuotationLink);

                        newQuotation.CoreStatement           = newDirectQuotation.CoreStatement + " (Comment)";
                        newQuotation.CoreStatementUpdateType = UpdateType.Manual;
                    }
                }
                break;

            case QuotationType.QuickReference:
                if (!string.IsNullOrEmpty(highlightContents))
                {
                    newQuotation = highlightContents.CreateNewQuickReferenceFromHighlightContents(pageRangeString, reference, quotationType);
                }
                else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations)
                {
                    newQuotation = textContent.CreateNewQuickReferenceFromAnnotationContent(pageRangeString, reference, quotationType);
                }
                reference.Quotations.Add(newQuotation);
                project.AllKnowledgeItems.Add(newQuotation);
                newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);
                break;

            default:
                if (!string.IsNullOrEmpty(highlightContents))
                {
                    newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType);
                    reference.Quotations.Add(newQuotation);
                    project.AllKnowledgeItems.Add(newQuotation);
                    newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);
                }
                else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations)
                {
                    newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType);
                    reference.Quotations.Add(newQuotation);
                    project.AllKnowledgeItems.Add(newQuotation);
                    newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);
                }
                break;
            }

            if (existingAnnotation != null)
            {
                existingAnnotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation);
                existingAnnotation.Visible = false;
            }

            return(true);
        }
        public static void AnnotationsImport(QuotationType quotationType)
        {
            // Static Variables

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            Location location = previewControl.ActiveLocation;

            if (location == null)
            {
                return;
            }

            List <Reference> references = Program.ActiveProjectShell.Project.References.Where(r => r.Locations.Contains(location)).ToList();

            if (references == null)
            {
                return;
            }
            if (references.Count != 1)
            {
                MessageBox.Show("The document is not linked with exactly one reference. Import aborted.");
            }

            Reference reference = references.FirstOrDefault();

            if (references == null)
            {
                return;
            }

            LinkedResource linkedResource = location.Address;

            string pathToFile = linkedResource.Resolve().LocalPath;

            PreviewBehaviour previewBehaviour = location.PreviewBehaviour;

            // Dynamic Variables

            string colorPickerCaption = string.Empty;

            List <ColorPt> selectedColorPts = new List <ColorPt>();

            int annotationsImportedCount = 0;

            bool ImportEmptyAnnotations = false;
            bool RedrawAnnotations      = true;

            // The Magic

            Form commentAnnotationsColorPicker = new AnnotationsImporterColorPicker(quotationType, document.ExistingColors(), out selectedColorPts);

            DialogResult dialogResult = commentAnnotationsColorPicker.ShowDialog();

            RedrawAnnotations      = AnnotationsImporterColorPicker.RedrawAnnotationsSelected;
            ImportEmptyAnnotations = AnnotationsImporterColorPicker.ImportEmptyAnnotationsSelected;

            if (dialogResult == DialogResult.Cancel)
            {
                MessageBox.Show("Import of external highlights cancelled.");
                return;
            }

            List <Annotation> temporaryAnnotations = new List <Annotation>();

            if (ImportEmptyAnnotations || quotationType == QuotationType.Comment)
            {
                for (int pageIndex = 1; pageIndex <= document.GetPageCount(); pageIndex++)
                {
                    pdftron.PDF.Page page = document.GetPage(pageIndex);
                    if (page.IsValid())
                    {
                        List <Annot> annotsToDelete = new List <Annot>();
                        for (int j = 0; j < page.GetNumAnnots(); j++)
                        {
                            Annot annot = page.GetAnnot(j);

                            if (annot.GetSDFObj() != null && (annot.GetType() == Annot.Type.e_Highlight || annot.GetType() == Annot.Type.e_Unknown))
                            {
                                Highlight highlight = new Highlight(annot);
                                if (highlight == null)
                                {
                                    continue;
                                }

                                ColorPt annotColorPt = annot.GetColorAsRGB();

                                if (selectedColorPts.Where(e =>
                                                           e.Get(0) == annotColorPt.Get(0) &&
                                                           e.Get(1) == annotColorPt.Get(1) &&
                                                           e.Get(2) == annotColorPt.Get(2) &&
                                                           e.Get(3) == annotColorPt.Get(3)
                                                           ).Count() == 0)
                                {
                                    continue;
                                }
                                Annotation temporaryAnnotation = highlight.TemporaryAnnotation();
                                location.Annotations.Add(temporaryAnnotation);
                                temporaryAnnotations.Add(temporaryAnnotation);
                            }
                        } // end for (int j = 1; j <= page.GetNumAnnots(); j++)
                    }     // end if (page.IsValid())
                }         // end for (int i = 1; i <= document.GetPageCount(); i++)

                previewControl.ShowNoPreview();
                location.PreviewBehaviour = PreviewBehaviour.SkipEntryPage;
                previewControl.ShowLocationPreview(location);
                document = new Document(pathToFile);
            }

            //Uncomment here to get an overview of all annotations
            //int x = 0;
            //foreach (Annotation a in location.Annotations)
            //{
            //    System.Diagnostics.Debug.WriteLine("Annotation " + x.ToString());
            //    int y = 0;
            //    foreach (Quad q in a.Quads)
            //    {
            //        System.Diagnostics.Debug.WriteLine("Quad " + y.ToString());
            //        System.Diagnostics.Debug.WriteLine("IsContainer: " + q.IsContainer.ToString());
            //        System.Diagnostics.Debug.WriteLine("MinX: " + q.MinX.ToString());
            //        System.Diagnostics.Debug.WriteLine("MinY: " + q.MinY.ToString());
            //        System.Diagnostics.Debug.WriteLine("MaxX: " + q.MaxX.ToString());
            //        System.Diagnostics.Debug.WriteLine("MaxY: " + q.MaxY.ToString());
            //        y = y + 1;
            //    }
            //    x = x + 1;
            //}

            int v = 0;

            for (int pageIndex = 1; pageIndex <= document.GetPageCount(); pageIndex++)
            {
                pdftron.PDF.Page page = document.GetPage(pageIndex);
                if (page.IsValid())
                {
                    List <Annot> annotsToDelete = new List <Annot>();
                    for (int j = 0; j < page.GetNumAnnots(); j++)
                    {
                        Annot annot = page.GetAnnot(j);

                        if (annot.GetSDFObj() != null && (annot.GetType() == Annot.Type.e_Highlight || annot.GetType() == Annot.Type.e_Unknown))
                        {
                            Highlight highlight = new Highlight(annot);
                            if (highlight == null)
                            {
                                continue;
                            }

                            ColorPt annotColorPt = annot.GetColorAsRGB();

                            if (selectedColorPts.Where(e =>
                                                       e.Get(0) == annotColorPt.Get(0) &&
                                                       e.Get(1) == annotColorPt.Get(1) &&
                                                       e.Get(2) == annotColorPt.Get(2) &&
                                                       e.Get(3) == annotColorPt.Get(3)
                                                       ).Count() == 0)
                            {
                                continue;
                            }

                            // Uncomment here to get an overview of all highlights
                            //System.Diagnostics.Debug.WriteLine("Highlight " + v.ToString());
                            //int w = 0;
                            //foreach (Quad q in highlight.AsAnnotationQuads())
                            //{
                            //    System.Diagnostics.Debug.WriteLine("Quad " + w.ToString());
                            //    System.Diagnostics.Debug.WriteLine("IsContainer: " + q.IsContainer.ToString());
                            //    System.Diagnostics.Debug.WriteLine("MinX: " + q.MinX.ToString());
                            //    System.Diagnostics.Debug.WriteLine("MinY: " + q.MinY.ToString());
                            //    System.Diagnostics.Debug.WriteLine("MaxX: " + q.MaxX.ToString());
                            //    System.Diagnostics.Debug.WriteLine("MaxY: " + q.MaxY.ToString());
                            //    w = w + 1;
                            //}
                            //v = v + 1;

                            if (highlight.UpdateExistingQuotation(quotationType, location))
                            {
                                annotationsImportedCount++;
                                continue;
                            }
                            if (highlight.CreateNewQuotationAndAnnotationFromHighlight(quotationType, ImportEmptyAnnotations, RedrawAnnotations, temporaryAnnotations))
                            {
                                annotationsImportedCount++;
                                continue;
                            }
                        }
                    } // end for (int j = 1; j <= page.GetNumAnnots(); j++)
                    foreach (Annot annot in annotsToDelete)
                    {
                        page.AnnotRemove(annot);
                    }
                } // end if (page.IsValid())
            }     // end for (int i = 1; i <= document.GetPageCount(); i++)

            foreach (Annotation annotation in temporaryAnnotations)
            {
                location.Annotations.Remove(annotation);
            }

            location.PreviewBehaviour = previewBehaviour;

            MessageBox.Show(annotationsImportedCount.ToString() + " highlights have been imported.");
        }
Exemple #14
0
        public static void CreatesummaryOnQuotations(List <KnowledgeItem> quotations)
        {
            Reference reference = Program.ActiveProjectShell.PrimaryMainForm.ActiveReference;

            if (reference == null)
            {
                return;
            }

            Project project = reference.Project;

            if (project == null)
            {
                return;
            }

            PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl;

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Document document = pdfViewControl.Document;

            if (document == null)
            {
                return;
            }

            Location location = reference.Locations.Where
                                (
                l =>
                l.LocationType == LocationType.ElectronicAddress &&
                l.Address.Resolve().LocalPath.EndsWith(".pdf") &&
                l.Address.Resolve().LocalPath == document.GetFileName()
                                )
                                .FirstOrDefault();

            if (location == null)
            {
                return;
            }

            Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault();

            SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater;

            List <PageRange> pageRanges = new List <PageRange>();
            List <Quad>      quads      = new List <Quad>();

            Annotation newAnnotation = new Annotation(location);

            KnowledgeItem summary = new KnowledgeItem(reference, QuotationType.Summary);

            reference.Quotations.Add(summary);

            foreach (KnowledgeItem quotation in quotations)
            {
                pageRanges.Add(quotation.PageRange);

                EntityLink summaryQuotationLink = new EntityLink(project);
                summaryQuotationLink.Source     = summary;
                summaryQuotationLink.Target     = quotation;
                summaryQuotationLink.Indication = EntityLink.CommentOnQuotationIndication;
                project.EntityLinks.Add(summaryQuotationLink);

                Annotation quotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation;
                if (quotationAnnotation == null)
                {
                    continue;
                }

                quads.AddRange(quotationAnnotation.Quads);
            }

            newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
            newAnnotation.Quads         = quads;
            newAnnotation.Visible       = false;

            location.Annotations.Add(newAnnotation);

            summary.PageRange = PageRangeMerger.PageRangeListToString(pageRanges);
            summary.CoreStatementUpdateType = UpdateType.Automatic;

            EntityLink summaryAnnotationLink = new EntityLink(project);

            summaryAnnotationLink.Source     = summary;
            summaryAnnotationLink.Target     = newAnnotation;
            summaryAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication;
            project.EntityLinks.Add(summaryAnnotationLink);

            quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(summary, true);
            pdfViewControl.GoToAnnotation(newAnnotation);
        }
        public static void CreateCommentOnQuotation(List <KnowledgeItem> quotations)
        {
            Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault();

            SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater;

            PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl;

            if (previewControl == null)
            {
                return;
            }

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            Annotation    lastAnnotation = null;
            KnowledgeItem lastComment    = null;

            foreach (KnowledgeItem quotation in quotations)
            {
                Reference reference = quotation.Reference;
                if (reference == null)
                {
                    return;
                }

                Project project = reference.Project;
                if (project == null)
                {
                    return;
                }

                Annotation mainQuotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation;
                if (mainQuotationAnnotation == null)
                {
                    return;
                }

                Location location = mainQuotationAnnotation.Location;
                if (location == null)
                {
                    return;
                }

                KnowledgeItem comment = new KnowledgeItem(reference, QuotationType.Comment);
                comment.PageRange = quotation.PageRange;
                comment.PageRange.Update(quotation.PageRange.NumberingType);
                comment.PageRange.Update(quotation.PageRange.NumeralSystem);
                comment.CoreStatement           = quotation.CoreStatement + " (Comment)";
                comment.CoreStatementUpdateType = UpdateType.Manual;
                reference.Quotations.Add(comment);

                EntityLink commentQuotationLink = new EntityLink(project);
                commentQuotationLink.Source     = comment;
                commentQuotationLink.Target     = quotation;
                commentQuotationLink.Indication = EntityLink.CommentOnQuotationIndication;
                project.EntityLinks.Add(commentQuotationLink);

                Annotation newAnnotation = new Annotation(location);

                newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
                newAnnotation.Quads         = mainQuotationAnnotation.Quads;
                newAnnotation.Visible       = false;

                location.Annotations.Add(newAnnotation);

                EntityLink commentAnnotationLink = new EntityLink(project);
                commentAnnotationLink.Source     = comment;
                commentAnnotationLink.Target     = newAnnotation;
                commentAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication;
                project.EntityLinks.Add(commentAnnotationLink);

                lastComment    = comment;
                lastAnnotation = newAnnotation;
            }
            quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(lastComment, true);
            pdfViewControl.GoToAnnotation(lastAnnotation);


            Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, lastComment);
        }
        public static Annotation CreateKnowledgeItemIndicationAnnotation(this Highlight highlight, bool RedrawAnnotations)
        {
            Project project = Program.ActiveProjectShell.Project;

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

            PreviewControl previewControl = PreviewMethods.GetPreviewControl();

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

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

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

            Document document = pdfViewControl.Document;

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

            Location location = previewControl.ActiveLocation;

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

            Reference reference = location.Reference;

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

            Annotation newAnnotation = new Annotation(location);

            List <Quad> quads = new List <Quad>();

            if (RedrawAnnotations)
            {
                quads = highlight.AsAnnotationQuads().SimpleQuads();
            }
            else
            {
                quads = highlight.AsAnnotationQuads();
            }


            newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0);
            newAnnotation.Quads         = quads;
            newAnnotation.Visible       = false;

            location.Annotations.Add(newAnnotation);

            return(newAnnotation);
        }
        public static void AssignPageRangeManuallyAfterShowingAnnotation()
        {
            KnowledgeItem quotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().FirstOrDefault();

            if (quotation.EntityLinks.FirstOrDefault() == null)
            {
                return;
            }

            Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault();

            SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater;

            Reference reference = quotation.Reference;

            if (reference == null)
            {
                return;
            }

            List <KnowledgeItem> quotations = reference.Quotations.ToList();

            int index = quotations.FindIndex(q => q == quotation);

            Annotation annotation = quotation.EntityLinks.FirstOrDefault().Target as Annotation;

            if (annotation == null)
            {
                return;
            }

            PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl;

            PdfViewControl pdfViewControl = previewControl.GetPdfViewControl();

            if (pdfViewControl == null)
            {
                return;
            }

            pdfViewControl.GoToAnnotation(annotation);

            KnowledgeItemsForms.NewPageRangeForm("Please enter the new page range:", out string data);

            if (!String.IsNullOrEmpty(data))
            {
                quotation.PageRange = quotation.PageRange.Update(data);
            }

            if (quotations[index - 1] == null)
            {
                return;
            }

            Program.ActiveProjectShell.PrimaryMainForm.ActiveControl = quotationSmartRepeater;
            quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(quotations[index - 1]);

            annotation = quotations[index - 1].EntityLinks.FirstOrDefault().Target as Annotation;
            if (annotation == null)
            {
                return;
            }

            pdfViewControl.GoToAnnotation(annotation);
        }