WPF读取PDF WORD EXCEL文件并展示 pdfreader

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using DevExpress.Spreadsheet;
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.DocumentViewer;
using DevExpress.Xpf.PdfViewer;
using DevExpress.Xpf.RichEdit;
using DevExpress.Xpf.Spreadsheet;

namespace JGSoft.Wpf.Component.Controls
{
	 
	public class PdfControl : Window, IComponentConnector
	{
		 
		public PdfControl()
		{
			this.InitializeComponent();
		}

		
		public PdfControl(string file)
		{
			this.InitializeComponent();
			this.WindowMax();
			this.Openfile(file);
		}

		
		private void WindowMax()
		{
			this.normaltop = base.Top;
			this.normalleft = base.Left;
			this.normalwidth = base.Width;
			this.normalheight = base.Height;
			double top = SystemParameters.WorkArea.Top;
			double left = SystemParameters.WorkArea.Left;
			double num = SystemParameters.PrimaryScreenWidth - SystemParameters.WorkArea.Right;
			double num2 = SystemParameters.PrimaryScreenHeight - SystemParameters.WorkArea.Bottom;
			base.Left = 0.0;
			base.Top = 0.0;
			base.Height = SystemParameters.WorkArea.Height;
			base.Width = SystemParameters.WorkArea.Width;
		}

	
		public void Openfile(string filename)
		{
			this.grid.Children.Clear();
			bool flag = ".doc.docx".ToUpper().Contains(Path.GetExtension(filename).ToUpper());
			if (flag)
			{
				RichEditControl richEditControl = new RichEditControl();
				richEditControl.LoadDocument(filename);
				this.grid.Children.Add(richEditControl);
			}
			else
			{
				bool flag2 = ".xls.xlsx.xlsm.xlt.xltx.xltm".ToUpper().Contains(Path.GetExtension(filename).ToUpper());
				if (flag2)
				{
					SpreadsheetControl spreadsheetControl = new SpreadsheetControl();
					IWorkbook document = spreadsheetControl.Document;
					document.LoadDocument(filename);
					this.grid.Children.Add(spreadsheetControl);
				}
				else
				{
					bool flag3 = ".pdf".ToUpper().Contains(Path.GetExtension(filename.ToUpper()));
					if (flag3)
					{
						this.pdf = new PdfViewerControl();
						this.pdf.ZoomMode = ZoomMode.ActualSize;
						this.pdf.OpenDocument(filename);
						this.pdf.ZoomFactor = 0.38;
						this.pdf.CommandBarStyle = DevExpress.Xpf.DocumentViewer.CommandBarStyle.Ribbon;
						UpdateAction updateAction = new UpdateAction();
						updateAction.ElementName = "bRibbon";
						updateAction.PropertyName = "Visibility";
						updateAction.Value = Visibility.Collapsed;
						this.pdf.CommandProvider = new PdfCommandProvider();
						this.pdf.CommandProvider.RibbonActions.Add(updateAction);
						this.pdf.AttachmentsViewerSettings = new PdfAttachmentsViewerSettings();
						this.pdf.AttachmentsViewerSettings.HideAttachmentsViewer = true;
						this.pdf.ThumbnailsViewerSettings = new PdfThumbnailsViewerSettings();
						this.pdf.ThumbnailsViewerSettings.HideThumbnailsViewer = true;
						this.pdf.OutlinesViewerSettings = new PdfOutlinesViewerSettings();
						this.pdf.OutlinesViewerSettings.HideOutlinesViewer = true;
						this.grid.Children.Add(this.pdf);
					}
					else
					{
						bool flag4 = ".txt".ToUpper().Contains(Path.GetExtension(filename.ToUpper()));
						if (flag4)
						{
							RichEditControl richEditControl2 = new RichEditControl();
							richEditControl2.LoadDocument(filename);
							this.grid.Children.Add(richEditControl2);
						}
						else
						{
							bool flag5 = ".png.jpg".ToUpper().Contains(Path.GetExtension(filename.ToUpper()));
							if (!flag5)
							{
								bool flag6 = ".mp4".ToUpper().Contains(Path.GetExtension(filename.ToUpper()));
								if (!flag6)
								{
									throw new Exception("未知文件格式");
								}
								MediaElement mediaElement = new MediaElement();
								mediaElement.Source = new Uri(filename);
								this.grid.Children.Add(mediaElement);
							}
						}
					}
				}
			}
		}


		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		public void InitializeComponent()
		{
			bool contentLoaded = this._contentLoaded;
			if (!contentLoaded)
			{
				this._contentLoaded = true;
				Uri resourceLocator = new Uri("/JGSoft.Wpf.Component;component/controls/pdfcontrol.xaml", UriKind.Relative);
				Application.LoadComponent(this, resourceLocator);
			}
		}

		
		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		void IComponentConnector.Connect(int connectionId, object target)
		{
			if (connectionId != 1)
			{
				this._contentLoaded = true;
			}
			else
			{
				this.grid = (Grid)target;
			}
		}

	
		private PdfViewerControl pdf;

	
		private double normaltop;


		private double normalleft;

	
		private double normalwidth;


		private double normalheight;

	
		internal Grid grid;

		
		private bool _contentLoaded;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值