-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathForm1.cs
More file actions
127 lines (108 loc) · 3.8 KB
/
Form1.cs
File metadata and controls
127 lines (108 loc) · 3.8 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PDF_Unlock
{
public partial class Form1 : Form
{
const string quote = "\"";
string temp = Path.GetTempPath();
public Form1()
{
InitializeComponent();
}
private void pdfDropBox_DragDrop(object sender, DragEventArgs e)
{
string[] pdfFile = (string[])e.Data.GetData(DataFormats.FileDrop, false);
string extension = Path.GetExtension(pdfFile[0]);
if (extension == ".pdf") {
pdffile.Text = pdfFile[0];
UnlockPDF();
Process.Start(temp+"temp.pdf");
}
else
{
MessageBox.Show("Please only drop PDFs in here. If its not a PDF I cant help you! :(");
}
}
private void browsePDFbtn_Click(object sender, EventArgs e)
{
//openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Select PDF File";
openFileDialog1.DefaultExt = "pdf";
openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string extension = Path.GetExtension(openFileDialog1.FileName);
if (extension == ".pdf")
{
pdffile.Text = openFileDialog1.FileName;
UnlockPDF();
Process.Start(temp+"temp.pdf");
}
else
{
MessageBox.Show("Please only select PDF files. If its not a PDF I cant help you! :(");
}
}
}
private void UnlockPDF()
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = gswin64cLocationtxt.Text;
startInfo.Arguments = @"-dPDFA -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile="+temp+"temp.pdf " + quote + pdffile.Text + quote;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
private void pdfDropBox_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void BrowsePDF_HelpRequest(object sender, EventArgs e)
{
}
private void browseGswin64cbtn_Click(object sender, EventArgs e)
{
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
gswin64cLocationtxt.Text = openFileDialog2.FileName;
Properties.Settings.Default.gswin64cLocation = gswin64cLocationtxt.Text;
Properties.Settings.Default.Save();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Save();
try
{
File.Delete(temp+"temp.pdf");
}
catch(Exception)
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
gswin64cLocationtxt.Text = Properties.Settings.Default.gswin64cLocation;
try
{
File.Delete(temp+"temp.pdf");
}
catch (Exception)
{
}
}
}
}