mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
let pdfviewer accepts streams
This commit is contained in:
@@ -249,6 +249,21 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
listThumbnails.Visibility = Visibility.Collapsed;
|
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)
|
private void BeginLoadThumbnails(string path, string password = null)
|
||||||
{
|
{
|
||||||
new Task(() =>
|
new Task(() =>
|
||||||
@@ -270,6 +285,28 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
}).Start();
|
}).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)
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
@@ -73,9 +73,9 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
{
|
{
|
||||||
_pdfControl.LoadPdf(path);
|
_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;
|
context.IsBusy = false;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -92,17 +92,15 @@ namespace QuickLook.Plugin.PDFViewer
|
|||||||
{
|
{
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
|
||||||
if (_pdfControl != null)
|
|
||||||
_pdfControl.CurrentPageChanged -= UpdateVindowCaption;
|
|
||||||
_pdfControl?.Dispose();
|
_pdfControl?.Dispose();
|
||||||
_pdfControl = null;
|
_pdfControl = null;
|
||||||
|
|
||||||
_context = 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)}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user