forked from ArtifexSoftware/Ghostscript.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFMain.cs
More file actions
188 lines (158 loc) · 6.07 KB
/
Copy pathFMain.cs
File metadata and controls
188 lines (158 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// FMain.cs
// This file is part of Ghostscript.NET.Viewer project
//
// Author: Josip Habjan (habjan@gmail.com, http://www.linkedin.com/in/habjan)
// Copyright (c) 2013-2014 by Josip Habjan. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using Ghostscript.NET.Viewer;
namespace Ghostscript.NET.Viewer
{
public partial class FMain : Form
{
private GhostscriptViewer _viewer;
private GhostscriptVersionInfo _gsVersion = GhostscriptVersionInfo.GetLastInstalledVersion();
public FMain()
{
InitializeComponent();
this.Text = Program.NAME;
pbPage.Width = 100;
pbPage.Height = 100;
_viewer = new GhostscriptViewer();
_viewer.DisplaySize += new GhostscriptViewerViewEventHandler(_viewer_DisplaySize);
_viewer.DisplayUpdate += new GhostscriptViewerViewEventHandler(_viewer_DisplayUpdate);
_viewer.DisplayPage += new GhostscriptViewerViewEventHandler(_viewer_DisplayPage);
}
void _viewer_DisplaySize(object sender, GhostscriptViewerViewEventArgs e)
{
pbPage.Image = e.Image;
}
void _viewer_DisplayUpdate(object sender, GhostscriptViewerViewEventArgs e)
{
pbPage.Invalidate();
pbPage.Update();
}
void _viewer_DisplayPage(object sender, GhostscriptViewerViewEventArgs e)
{
pbPage.Invalidate();
pbPage.Update();
tbPageNumber.Text = _viewer.CurrentPageNumber.ToString();
tbTotalPages.Text = " / " + _viewer.LastPageNumber.ToString();
}
private void FMain_Load(object sender, EventArgs e)
{
lblSystemInformation.Text = "Operating system: " + (Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit") + " " +
"Process: " + (Environment.Is64BitProcess ? "64-bit" : "32-bit");
lblGsVersion.Text = "Rasterizer: " + _gsVersion.LicenseType.ToString() + " Ghostscript " +
_gsVersion.Version.ToString() + " (" + Path.GetFileName(_gsVersion.DllPath) + ")";
}
private void mnuFileOpen_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Open PDF file";
ofd.Filter = "PDF, PS, EPS files|*.pdf;*.ps;*.eps";
if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
mnuFileClose_Click(this, null);
_viewer.Open(ofd.FileName, _gsVersion, false);
this.Text = System.IO.Path.GetFileName(ofd.FileName) + " - " + Program.NAME;
}
}
private void mnuFileClose_Click(object sender, EventArgs e)
{
_viewer.Close();
pbPage.Image = null;
this.Text = Program.NAME;
tbPageNumber.Text = string.Empty;
tbTotalPages.Text = string.Empty;
}
private void mnuFileExit_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void tbPageFirst_Click(object sender, EventArgs e)
{
_viewer.ShowFirstPage();
}
private void tbPagePrevious_Click(object sender, EventArgs e)
{
_viewer.ShowPreviousPage();
}
private void tbPageNext_Click(object sender, EventArgs e)
{
_viewer.ShowNextPage();
}
private void tbPageLast_Click(object sender, EventArgs e)
{
_viewer.ShowLastPage();
}
private void tbPageNumber_TextChanged(object sender, EventArgs e)
{
try
{
if (tbPageNumber.Text.Length > 0)
{
_viewer.ShowPage(int.Parse(tbPageNumber.Text));
}
}
catch { }
}
private void mnuAbout_Click(object sender, EventArgs e)
{
MessageBox.Show(this, "Powered by Ghostscript.NET & Josip Habjan (habjan@gmail.com)", "About " + Program.NAME, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void mnuNext_Click(object sender, EventArgs e)
{
_viewer.ShowNextPage();
}
private void mnuPrev_Click(object sender, EventArgs e)
{
_viewer.ShowPreviousPage();
}
private void mnuFirst_Click(object sender, EventArgs e)
{
_viewer.ShowFirstPage();
}
private void mnuLast_Click(object sender, EventArgs e)
{
_viewer.ShowLastPage();
}
private void tpZoomIn_Click(object sender, EventArgs e)
{
_viewer.ZoomIn();
}
private void tpZoomOut_Click(object sender, EventArgs e)
{
_viewer.ZoomOut();
}
}
}