123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using compdfkit_tools.Common;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.PDFControl
- {
- /// <summary>
- /// PDFScallingControl.xaml 的交互逻辑
- /// </summary>
- 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 == "Actual size")
- {
- pdfViewer.ChangeFitMode(FitMode.FitSize);
- }
- else if (e == "Suitable width")
- {
- pdfViewer.ChangeFitMode(FitMode.FitWidth);
- }
- else if (e == "Single page size")
- {
- 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);
- }
- }
- }
|