diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs index e73ea16..1658f82 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml.cs @@ -249,6 +249,21 @@ namespace QuickLook.Plugin.PDFViewer listThumbnails.Visibility = Visibility.Collapsed; } + public void LoadPdf(MemoryStream stream) + { + _pdfStream = new MemoryStream(); + stream.WriteTo(_pdfStream); + _pdfStream.Position = 0; + + _pdfHandle = PdfDocument.Load(_pdfStream); + _pdfLoaded = true; + + BeginLoadThumbnails(stream); + + if (_pdfHandle.PageCount < 2) + listThumbnails.Visibility = Visibility.Collapsed; + } + private void BeginLoadThumbnails(string path, string password = null) { new Task(() => @@ -270,6 +285,28 @@ namespace QuickLook.Plugin.PDFViewer }).Start(); } + private void BeginLoadThumbnails(MemoryStream stream, string password = null) + { + var localStream = new MemoryStream(); + stream.WriteTo(localStream); + localStream.Position = 0; + + new Task(() => + { + using (var handle = PdfDocument.Load(localStream, password)) + { + for (var p = 0; p < handle.PageCount; p++) + { + var bs = handle.RenderThumbnail(p); + + Dispatcher.BeginInvoke(new Action(() => PageThumbnails.Add(bs))); + } + + handle.Dispose(); + } + }).Start(); + } + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs index 2bb29e1..28d56d3 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PDFViewer/Plugin.cs @@ -73,9 +73,9 @@ namespace QuickLook.Plugin.PDFViewer { _pdfControl.LoadPdf(path); - context.Title = $"{Path.GetFileName(path)} (1 / {_pdfControl.TotalPages})"; + context.Title = $"1 / {_pdfControl.TotalPages}: {Path.GetFileName(path)}"; - _pdfControl.CurrentPageChanged += UpdateVindowCaption; + _pdfControl.CurrentPageChanged += UpdateWindowCaption; context.IsBusy = false; } catch (Exception e) @@ -91,18 +91,16 @@ namespace QuickLook.Plugin.PDFViewer public void Cleanup() { GC.SuppressFinalize(this); - - if (_pdfControl != null) - _pdfControl.CurrentPageChanged -= UpdateVindowCaption; + _pdfControl?.Dispose(); _pdfControl = null; _context = null; } - private void UpdateVindowCaption(object sender, EventArgs e2) + private void UpdateWindowCaption(object sender, EventArgs e2) { - _context.Title = $"{Path.GetFileName(_path)} ({_pdfControl.CurrentPage + 1} / {_pdfControl.TotalPages})"; + _context.Title = $"{_pdfControl.CurrentPage + 1} / {_pdfControl.TotalPages}: {Path.GetFileName(_path)}"; } } } \ No newline at end of file