123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using Compdfkit_Tools.Helper;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Windows;
- using System.Windows.Controls;
- namespace Compdfkit_Tools.PDFControl
- {
- public partial class CPDFScalingControl : UserControl
- {
- public CPDFViewer pdfViewer;
- public CPDFScalingControl()
- {
- InitializeComponent();
- }
- public void InitWithPDFViewer(CPDFViewer pdfViewer)
- {
- this.pdfViewer = pdfViewer;
- }
- private void PDFScalingControl_Loaded(object sender, RoutedEventArgs e)
- {
- CPDFScalingUI.SetScaleEvent += PDFScalingControl_SetScaleEvent;
- CPDFScalingUI.ScaleIncreaseEvent += PDFScalingControl_ScaleIncreaseEvent;
- CPDFScalingUI.ScaleDecreaseEvent += PDFScalingControl_ScaleDecreaseEvent;
- CPDFScalingUI.SetPresetScaleEvent += CPDFScalingUI_SetPresetScaleEvent;
- }
- private void CPDFScalingUI_Unloaded(object sender, RoutedEventArgs e)
- {
- CPDFScalingUI.SetScaleEvent -= PDFScalingControl_SetScaleEvent;
- CPDFScalingUI.ScaleIncreaseEvent -= PDFScalingControl_ScaleIncreaseEvent;
- CPDFScalingUI.ScaleDecreaseEvent -= PDFScalingControl_ScaleDecreaseEvent;
- CPDFScalingUI.SetPresetScaleEvent -= CPDFScalingUI_SetPresetScaleEvent;
- }
- private void PDFScalingControl_ScaleDecreaseEvent(object sender, EventArgs e)
- {
- if (pdfViewer == null || pdfViewer.Document == null)
- {
- return;
- }
- if (pdfViewer.ZoomFactor < 3)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.1);
- }
- else if (pdfViewer.ZoomFactor < 6)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.2);
- }
- else if (pdfViewer.ZoomFactor <= 10)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.3);
- }
- SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
- }
- private void PDFScalingControl_ScaleIncreaseEvent(object sender, EventArgs e)
- {
- if (pdfViewer == null || pdfViewer.Document == null)
- {
- return;
- }
- if (pdfViewer.ZoomFactor < 3)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.1);
- }
- else if (pdfViewer.ZoomFactor < 6)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.2);
- }
- else if (pdfViewer.ZoomFactor <= 10)
- {
- pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.3);
- }
- SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
- }
- private void PDFScalingControl_SetScaleEvent(object sender, string e)
- {
- if (pdfViewer == null || pdfViewer.Document == null)
- {
- return;
- }
- if (!string.IsNullOrEmpty(e))
- {
- pdfViewer.Zoom(double.Parse(e) / 100);
- SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
- }
- }
- private void CPDFScalingUI_SetPresetScaleEvent(object sender, string e)
- {
- if (pdfViewer == null || pdfViewer.Document == null)
- {
- return;
- }
- if (e == LanguageHelper.CommonManager.GetString("Zoom_Real"))
- {
- pdfViewer.ChangeFitMode(FitMode.FitSize);
- }
- else if (e == LanguageHelper.CommonManager.GetString("Zoom_FitWidth"))
- {
- pdfViewer.ChangeFitMode(FitMode.FitWidth);
- }
- else if (e == LanguageHelper.CommonManager.GetString("Zoom_FitPage"))
- {
- pdfViewer.ChangeFitMode(FitMode.FitHeight);
- }
- else
- {
- pdfViewer.Zoom(double.Parse(e) / 100);
- }
- SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
- }
- public void SetZoomTextBoxText(string value)
- {
- CPDFScalingUI.SetZoomTextBoxText(value);
- }
-
- private void CPDFPageScalingControl_LostFocus(object sender, RoutedEventArgs e)
- {
- SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
- }
- }
- }
|