public HighlightCanvasToolbarControl() { InitializeComponent(); ButtonPointErase.Icon = Icons.GetAppIcon(Icons.InkPointErase); ButtonPointErase.Click += ButtonPointErase_Click; ButtonPointErase.ToolTip = "Erase your highlights."; // Populate our buttons array for easy operation buttons = new List <AugmentedButton>(); buttons.Add(ButtonColor1); buttons.Add(ButtonColor2); buttons.Add(ButtonColor3); buttons.Add(ButtonColor4); buttons.Add(ButtonColor5); // Set up the buttons for (int i = 0; i < buttons.Count; ++i) { var button = buttons[i]; button.Background = new SolidColorBrush(StandardHighlightColours.GetColor(i)); button.Click += ButtonColor_Click; button.ToolTip = "Select a new highlighting colour."; } }
internal static void Export(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items) { List <PDFDocumentExportItem> pdf_document_export_items_values = new List <PDFDocumentExportItem>(pdf_document_export_items.Values); for (int i = 0; i < pdf_document_export_items_values.Count; ++i) { var item = pdf_document_export_items_values[i]; try { StatusManager.Instance.UpdateStatus("ContentExport", String.Format("Exporting entry {0} of {1}", i, pdf_document_export_items_values.Count), i, pdf_document_export_items_values.Count); using (PdfDocument document = PdfReader.Open(item.filename, PdfDocumentOpenMode.Modify)) { // First the properties document.Info.Title = item.pdf_document.TitleCombined; document.Info.Author = item.pdf_document.AuthorsCombined; document.Info.ModificationDate = DateTime.Now; document.Info.Creator = "Qiqqa.com library export v1"; { StringBuilder sb = new StringBuilder(); foreach (string tag in TagTools.ConvertTagBundleToTags(item.pdf_document.Tags)) { sb.Append(tag); sb.Append(";"); } document.Info.Keywords = sb.ToString(); } // Then the main comments (if any) { string comments = item.pdf_document.Comments; if (!String.IsNullOrEmpty(comments)) { PdfPage page = document.Pages[0]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XRect rect = new XRect(5, 5, 100, 100); PdfTextAnnotation new_annotation = new PdfTextAnnotation(); new_annotation.Contents = comments; new_annotation.Icon = PdfTextAnnotationIcon.Note; new_annotation.Rectangle = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect)); page.Annotations.Add(new_annotation); } } } // Then the highlights foreach (PDFHighlight highlight in item.pdf_document.Highlights.GetAllHighlights()) { PdfPage page = document.Pages[highlight.Page - 1]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XColor color = XColor.FromArgb(StandardHighlightColours.GetColor(highlight.Color)); XPen pen = new XPen(color); XBrush brush = new XSolidBrush(color); XRect rect = new XRect(highlight.Left * gfx.PageSize.Width, highlight.Top * gfx.PageSize.Height, highlight.Width * gfx.PageSize.Width, highlight.Height * gfx.PageSize.Height); gfx.DrawRectangle(brush, rect); } } // Then the annotations foreach (PDFAnnotation annotation in item.pdf_document.GetAnnotations()) { if (annotation.Deleted) { continue; } PdfPage page = document.Pages[annotation.Page - 1]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XColor color = XColor.FromArgb(annotation.Color); XPen pen = new XPen(color); XBrush brush = new XSolidBrush(color); XRect rect = new XRect(annotation.Left * gfx.PageSize.Width, annotation.Top * gfx.PageSize.Height, annotation.Width * gfx.PageSize.Width, annotation.Height * gfx.PageSize.Height); gfx.DrawRectangle(brush, rect); PdfTextAnnotation new_annotation = new PdfTextAnnotation(); new_annotation.Contents = String.Format("Tags:{0}\n{1}", annotation.Tags, annotation.Text); new_annotation.Icon = PdfTextAnnotationIcon.Note; new_annotation.Color = color; new_annotation.Opacity = 0.5; new_annotation.Open = false; new_annotation.Rectangle = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect)); page.Annotations.Add(new_annotation); //foreach (var pair in new_annotation.Elements) //{ // Logging.Debug(" {0}={1}", pair.Key, pair.Value); //} } } // Save it Logging.Info("Saving {0}", item.filename); document.Save(item.filename); } } catch (Exception ex) { Logging.Error(ex, "Error updating PDF for " + item.filename); } StatusManager.Instance.UpdateStatus("ContentExport", String.Format("Exported your PDF content")); } }
private static void BuildAnnotationWork_FillAnnotationText(PDFDocument pdf_document, PDFAnnotation pdf_annotation, AnnotationWorkGenerator.AnnotationWork annotation_work) { int current_color = -1; Run current_run = new Run(); annotation_work.annotation_paragraph.Inlines.Add(current_run); try { // Get the text for this annotation WordList word_list = pdf_document.PDFRenderer.GetOCRText(pdf_annotation.Page); if (null != word_list) { StringBuilder current_sb = new StringBuilder(); foreach (var word in word_list) { if (word.Contains(pdf_annotation.Left, pdf_annotation.Top, pdf_annotation.Width, pdf_annotation.Height)) { // Find out what colour this word is... int new_color = -1; foreach (PDFHighlight highlight in pdf_document.Highlights.GetHighlightsForPage(pdf_annotation.Page)) { if (highlight.Page == pdf_annotation.Page && word.ContainsMajority(highlight.Left, highlight.Top, highlight.Width, highlight.Height)) { new_color = highlight.Color; break; } } // If the colour has change if (new_color != current_color) { // Emit the existing span current_run.Text = current_sb.ToString(); // Create the new span current_color = new_color; current_run = new Run(); current_sb = new StringBuilder(); annotation_work.annotation_paragraph.Inlines.Add(current_run); if (-1 != new_color) { current_run.Background = new SolidColorBrush(StandardHighlightColours.GetColor(new_color)); } } // Tidy up dashes on line-ends string current_text = word.Text; string current_spacer = " "; if (current_text.EndsWith("-")) { current_text = current_text.TrimEnd('-'); current_spacer = ""; } // Append the new text current_sb.Append(current_text); current_sb.Append(current_spacer); } } // Emit the final span current_run.Text = current_sb.ToString(); } else { Run run = new Run(); run.Background = Brushes.Orange; run.Text = String.Format("OCR is not complete for page {0}", pdf_annotation.Page); annotation_work.annotation_paragraph.Inlines.Add(run); } } catch (Exception ex) { Logging.Error(ex, "There was a problem while trying to add annotation text for document {0}", pdf_document.Fingerprint); Run run = new Run(); run.Background = Brushes.Red; run.Text = String.Format("Processing error: {0}", ex.Message); annotation_work.annotation_paragraph.Inlines.Add(run); } }