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;
}
}
WPF读取PDF WORD EXCEL文件并展示 pdfreader
最新推荐文章于 2024-08-24 09:45:52 发布