mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
Auto resize PDF viewer window
This commit is contained in:
@@ -16,9 +16,11 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using PdfiumViewer;
|
using PdfiumViewer;
|
||||||
|
using QuickLook.Common.Helpers;
|
||||||
using QuickLook.Common.Plugin;
|
using QuickLook.Common.Plugin;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -98,9 +100,23 @@ public class Plugin : IViewer
|
|||||||
{
|
{
|
||||||
var desiredSize = PdfViewerControl.GetDesiredControlSizeByFirstPage(path, password);
|
var desiredSize = PdfViewerControl.GetDesiredControlSizeByFirstPage(path, password);
|
||||||
context.SetPreferredSizeFit(desiredSize, 0.9); // Actually it is no longer effective here
|
context.SetPreferredSizeFit(desiredSize, 0.9); // Actually it is no longer effective here
|
||||||
|
|
||||||
context.ViewerContent = _pdfControl;
|
context.ViewerContent = _pdfControl;
|
||||||
|
|
||||||
|
// Call the viewer window private method using reflection
|
||||||
|
// QuickLook.ViewerWindow.ResizeAndCentreExistingWindow
|
||||||
|
if (Window.GetWindow(_pdfControl) is Window window)
|
||||||
|
{
|
||||||
|
var ResizeAndCentreExistingWindow = window.GetType().GetMethod("ResizeAndCentreExistingWindow",
|
||||||
|
BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
|
||||||
|
if (ResizeAndCentreExistingWindow != null)
|
||||||
|
{
|
||||||
|
var newRect = (Rect)ResizeAndCentreExistingWindow.Invoke(window, [context.PreferredSize]);
|
||||||
|
|
||||||
|
window.MoveWindow(newRect.Left, newRect.Top, newRect.Width, newRect.Height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context.IsBusy = true;
|
context.IsBusy = true;
|
||||||
_pdfControl.LoadPdf(path, password);
|
_pdfControl.LoadPdf(path, password);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user