public void OpenFile() { SyncContext.Post( _ => { if (OpenFileSemaphore.Wait(0) == false) { return; } if (PdfWindow == null) { CreatePdfWindow(null); } string filePath = PdfWindow.OpenFileDialog(); if (filePath != null) { PDFElement.Create(filePath); } OpenFileSemaphore.Release(); }, null ); }
public void OpenDocument(PDFElement pdfElement) { //if (WindowEx.IsWindowOpen<PDFWindow>() == false) if (Visibility != Visibility.Visible) { Show(); } IPDFViewer.LoadDocument(pdfElement); }
private void OpenElement(PDFElement pdfElem) { if (pdfElem == null) { return; } LastElement = pdfElem; EnsurePdfWindow(); PdfWindow.OpenDocument(pdfElem); PdfWindow.ForceActivate(); }
public void OnElementChanged(IElement newElem, IControlHtml ctrlHtml) { PdfWindow?.CancelSave(); if (newElem == null) { return; } if (LastElement?.ElementId == newElem.Id) { return; } var html = ctrlHtml?.Text ?? string.Empty; var pdfEl = newElem.Type == ElementType.Topic ? PDFElement.TryReadElement(html, newElem.Id) : null; bool noNewElem = pdfEl == null; bool noLastElem = LastElement == null || (Svc.SM.Registry.Element[LastElement.ElementId]?.Deleted ?? true); if (noNewElem && noLastElem) { return; } SyncContext.Send( delegate { bool close = LastElement != null && pdfEl == null; CloseElement(); OpenElement(pdfEl); if (close) { PdfWindow?.Close(); } }, null); }
public void OpenFile() { SyncContext.Post( _ => { if (PdfWindow == null) { CreatePdfWindow(null); } string filePath = PdfWindow.OpenFileDialog(); if (filePath != null) { PDFElement.Create(filePath); } }, null ); }
public static CreationResult Create( IBinary binMem, int startPage = -1, int endPage = -1, int startIdx = -1, int endIdx = -1, int parentElementId = -1, int readPage = 0, Point readPoint = default, ViewModes viewMode = PDFConst.DefaultViewMode, int pageMargin = PDFConst.DefaultPageMargin, float zoom = PDFConst.DefaultZoom, bool shouldDisplay = true, string subtitle = null) { PDFElement pdfEl; string title; string author; string creationDate; string filePath; try { filePath = binMem.GetFilePath("pdf"); if (File.Exists(filePath) == false) { return(CreationResult.FailBinaryMemberFileMissing); } pdfEl = new PDFElement { BinaryMemberId = binMem.Id, FilePath = filePath, StartPage = startPage, EndPage = endPage, StartIndex = startIdx, EndIndex = endIdx, ReadPage = readPage, ReadPoint = readPoint, ViewMode = viewMode, PageMargin = pageMargin, Zoom = zoom, }; pdfEl.GetInfos(out string pdfTitle, out author, out creationDate); title = pdfEl.ConfigureTitle(pdfTitle, subtitle); } catch (Exception ex) { LogTo.Error(ex, "Exception thrown while creating new PDF element"); return(CreationResult.FailUnknown); } string elementHtml = string.Format(CultureInfo.InvariantCulture, PDFConst.ElementFormat, title, binMem.Name, pdfEl.GetJsonB64()); IElement parentElement = parentElementId > 0 ? Svc.SM.Registry.Element[parentElementId] : null; var elemBuilder = new ElementBuilder(ElementType.Topic, elementHtml) .WithParent(parentElement) .WithTitle(subtitle ?? title) .WithPriority(PDFState.Instance.Config.PDFExtractPriority) .WithReference( r => r.WithTitle(title) .WithAuthor(author) .WithDate(creationDate) .WithSource("PDF") .WithLink("..\\" + Svc.SM.Collection.MakeRelative(filePath)) ); if (shouldDisplay == false) { elemBuilder = elemBuilder.DoNotDisplay(); } return(Svc.SM.Registry.Element.Add(out _, ElemCreationFlags.CreateSubfolders, elemBuilder) ? CreationResult.Ok : CreationResult.FailCannotCreateElement); }