faster PDF file type determination and loading

This commit is contained in:
Paddy Xu
2017-05-22 21:16:21 +03:00
parent 0504dd9b97
commit de8554d2dc
2 changed files with 7 additions and 8 deletions

View File

@@ -185,7 +185,7 @@ namespace QuickLook.Plugin.PDFViewer
ReRenderCurrentPage(); ReRenderCurrentPage();
} }
public Size GetDesiredControlSizeByFirstPage(string path) public static Size GetDesiredControlSizeByFirstPage(string path)
{ {
var tempHandle = new PdfFile(path); var tempHandle = new PdfFile(path);

View File

@@ -19,17 +19,16 @@ namespace QuickLook.Plugin.PDFViewer
if (File.Exists(path) && Path.GetExtension(path).ToLower() == ".pdf") if (File.Exists(path) && Path.GetExtension(path).ToLower() == ".pdf")
return true; return true;
using (var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) //using (var br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{ //{
return Encoding.ASCII.GetString(br.ReadBytes(4)) == "%PDF"; // return Encoding.ASCII.GetString(br.ReadBytes(4)) == "%PDF";
} //}
return false;
} }
public void Prepare(string path, ContextObject context) public void Prepare(string path, ContextObject context)
{ {
_pdfControl = new PdfViewerControl(); var desiredSize = PdfViewerControl.GetDesiredControlSizeByFirstPage(path);
var desiredSize = _pdfControl.GetDesiredControlSizeByFirstPage(path);
context.SetPreferredSizeFit(desiredSize, 0.8); context.SetPreferredSizeFit(desiredSize, 0.8);
} }