mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
WIP
This commit is contained in:
52
QuickLook.Plugin.PDFViewer/Class1.cs
Normal file
52
QuickLook.Plugin.PDFViewer/Class1.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using MoonPdfLib;
|
||||
|
||||
namespace QuickLook.Plugin.PDFViewer
|
||||
{
|
||||
public class Class1:IViewer
|
||||
{
|
||||
public bool CanView(string path, byte[] sample)
|
||||
{
|
||||
if (String.IsNullOrEmpty(path))
|
||||
return false;
|
||||
|
||||
if (Path.GetExtension(path).ToLower() == ".pdf")
|
||||
return true;
|
||||
|
||||
if (Encoding.ASCII.GetString(sample.Take(4).ToArray()) == "%PDF")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void View(string path, ViewContentContainer container)
|
||||
{
|
||||
MoonPdfPanel pdfPanel = new MoonPdfPanel
|
||||
{
|
||||
ViewType = ViewType.SinglePage,
|
||||
PageRowDisplay = PageRowDisplayType.ContinuousPageRows,
|
||||
PageMargin = new System.Windows.Thickness(0, 2, 4, 2),
|
||||
Background = new SolidColorBrush(Colors.LightGray)
|
||||
};
|
||||
|
||||
container.SetContent(pdfPanel);
|
||||
|
||||
Task.Delay(200).ContinueWith(t => container.Dispatcher.Invoke(() => pdfPanel.OpenFile(path)));
|
||||
|
||||
Task.Delay(400).ContinueWith(t => container.Dispatcher.Invoke(() => pdfPanel.ZoomToWidth()));
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user