1 |
391aa70f
|
gaqhf
|
using System;
|
2 |
4601d8de
|
Gyusu
|
using System.Collections.Generic;
|
3 |
|
|
using System.ComponentModel;
|
4 |
|
|
using System.Data;
|
5 |
|
|
using System.Drawing;
|
6 |
|
|
using System.Drawing.Imaging;
|
7 |
|
|
using System.IO;
|
8 |
|
|
using System.Linq;
|
9 |
|
|
using System.Text;
|
10 |
|
|
using System.Threading.Tasks;
|
11 |
|
|
using System.Windows.Forms;
|
12 |
391aa70f
|
gaqhf
|
using DevExpress.Pdf;
|
13 |
4601d8de
|
Gyusu
|
|
14 |
|
|
namespace PDF_TO_IMAGE
|
15 |
|
|
{
|
16 |
|
|
public partial class ConvertImage : Form
|
17 |
|
|
{
|
18 |
|
|
public ConvertImage()
|
19 |
|
|
{
|
20 |
|
|
InitializeComponent();
|
21 |
391aa70f
|
gaqhf
|
|
22 |
|
|
Combo_Scale.SelectedIndex = Properties.Settings.Default._Scale;
|
23 |
|
|
Combo_LengthType.SelectedIndex = Properties.Settings.Default._LengthType;
|
24 |
|
|
Txt_Length.Text = Properties.Settings.Default._Length;
|
25 |
|
|
Chk_Scale.Checked = Properties.Settings.Default._UseScale;
|
26 |
|
|
SacleCheckedChange();
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
private void ConvertImage_FormClosing(object sender, FormClosingEventArgs e)
|
30 |
|
|
{
|
31 |
|
|
Properties.Settings.Default._Scale = Combo_Scale.SelectedIndex;
|
32 |
|
|
Properties.Settings.Default._LengthType = Combo_LengthType.SelectedIndex;
|
33 |
|
|
Properties.Settings.Default._Length = Txt_Length.Text;
|
34 |
|
|
Properties.Settings.Default._UseScale = Chk_Scale.Checked;
|
35 |
|
|
Properties.Settings.Default.Save();
|
36 |
4601d8de
|
Gyusu
|
}
|
37 |
|
|
|
38 |
|
|
private void Btn_LoadPDF_Click(object sender, EventArgs e)
|
39 |
|
|
{
|
40 |
6547b5f1
|
humkyung
|
OpenFileDialog OFD = new OpenFileDialog() { Filter = "PDF Files (.PDF)|*.PDF" };
|
41 |
4601d8de
|
Gyusu
|
if (OFD.ShowDialog() == DialogResult.OK)
|
42 |
|
|
{
|
43 |
|
|
string pdfpath = OFD.FileName;
|
44 |
|
|
|
45 |
|
|
Txt_PDFPath.Text = pdfpath;
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
391aa70f
|
gaqhf
|
|
49 |
|
|
private void Chk_Scale_CheckedChanged(object sender, EventArgs e)
|
50 |
4601d8de
|
Gyusu
|
{
|
51 |
391aa70f
|
gaqhf
|
SacleCheckedChange();
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
private void SacleCheckedChange()
|
55 |
|
|
{
|
56 |
|
|
if (Chk_Scale.Checked)
|
57 |
|
|
{
|
58 |
|
|
Txt_Length.Enabled = false;
|
59 |
|
|
Combo_LengthType.Enabled = false;
|
60 |
|
|
Combo_Scale.Enabled = true;
|
61 |
|
|
}
|
62 |
|
|
else
|
63 |
4601d8de
|
Gyusu
|
{
|
64 |
391aa70f
|
gaqhf
|
Txt_Length.Enabled = true;
|
65 |
|
|
Combo_LengthType.Enabled = true;
|
66 |
|
|
Combo_Scale.Enabled = false;
|
67 |
4601d8de
|
Gyusu
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
391aa70f
|
gaqhf
|
private void Btn_Convert_Click(object sender, EventArgs e)
|
72 |
4601d8de
|
Gyusu
|
{
|
73 |
391aa70f
|
gaqhf
|
int iScale = 0;
|
74 |
|
|
double iLength = 0;
|
75 |
|
|
bool bResult = true;
|
76 |
|
|
string sFilePath = Txt_PDFPath.Text;
|
77 |
4601d8de
|
Gyusu
|
|
78 |
391aa70f
|
gaqhf
|
if (Chk_Scale.Checked)
|
79 |
|
|
iScale = Convert.ToInt32(Combo_Scale.SelectedItem.ToString().Split(new char[] { ' ' })[1]);
|
80 |
|
|
else
|
81 |
4601d8de
|
Gyusu
|
{
|
82 |
391aa70f
|
gaqhf
|
if (!double.TryParse(Txt_Length.Text, out iLength) || iLength < 300)
|
83 |
|
|
bResult = false;
|
84 |
|
|
|
85 |
4601d8de
|
Gyusu
|
}
|
86 |
|
|
|
87 |
391aa70f
|
gaqhf
|
if (!File.Exists(sFilePath))
|
88 |
|
|
bResult = false;
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
if (bResult)
|
92 |
4601d8de
|
Gyusu
|
{
|
93 |
66be3f2d
|
Gyusu
|
string sPathNonExtension = Txt_PDFPath.Text.Replace(Path.GetExtension(Txt_PDFPath.Text), "");
|
94 |
391aa70f
|
gaqhf
|
PdfDocumentProcessor pdp = new PdfDocumentProcessor();
|
95 |
|
|
pdp.LoadDocument(sFilePath);
|
96 |
66be3f2d
|
Gyusu
|
|
97 |
50df80f6
|
gaqhf
|
splashScreenManager1.ShowWaitForm();
|
98 |
|
|
splashScreenManager1.SetWaitFormCaption("Convert Pdf File to Image Files");
|
99 |
391aa70f
|
gaqhf
|
try
|
100 |
66be3f2d
|
Gyusu
|
{
|
101 |
9f04ece0
|
gaqhf
|
int iPage = pdp.Document.Pages.Count;
|
102 |
|
|
string sPage = iPage.ToString();
|
103 |
391aa70f
|
gaqhf
|
for (int i = 0; i < pdp.Document.Pages.Count; i++)
|
104 |
66be3f2d
|
Gyusu
|
{
|
105 |
9f04ece0
|
gaqhf
|
int iPercent = i * 100 / iPage;
|
106 |
50df80f6
|
gaqhf
|
splashScreenManager1.SetWaitFormDescription(i + " / " + sPage + " Pages ( " + iPercent + "% )");
|
107 |
391aa70f
|
gaqhf
|
PdfPage page = pdp.Document.Pages[i];
|
108 |
|
|
|
109 |
|
|
double dWidth = page.CropBox.Width;
|
110 |
|
|
double dHeight = page.CropBox.Height;
|
111 |
|
|
|
112 |
|
|
if (Chk_Scale.Checked)
|
113 |
76f465d0
|
Gyusu
|
{
|
114 |
391aa70f
|
gaqhf
|
dWidth = dWidth * iScale;
|
115 |
|
|
dHeight = dHeight * iScale;
|
116 |
76f465d0
|
Gyusu
|
}
|
117 |
391aa70f
|
gaqhf
|
else
|
118 |
66be3f2d
|
Gyusu
|
{
|
119 |
391aa70f
|
gaqhf
|
if (Combo_LengthType.SelectedItem.ToString() == "Width")
|
120 |
66be3f2d
|
Gyusu
|
{
|
121 |
391aa70f
|
gaqhf
|
double dScale = dWidth / iLength;
|
122 |
|
|
dWidth = iLength;
|
123 |
|
|
dHeight = dHeight / dScale;
|
124 |
|
|
}
|
125 |
|
|
else
|
126 |
|
|
{
|
127 |
|
|
double dScale = dHeight / iLength;
|
128 |
|
|
dHeight = iLength;
|
129 |
|
|
dWidth = dWidth / dScale;
|
130 |
66be3f2d
|
Gyusu
|
}
|
131 |
|
|
}
|
132 |
391aa70f
|
gaqhf
|
|
133 |
|
|
double dMax = Math.Max(dWidth, dHeight);
|
134 |
|
|
|
135 |
|
|
using (Bitmap bitmap = pdp.CreateBitmap(i + 1, (int)dMax))
|
136 |
66be3f2d
|
Gyusu
|
{
|
137 |
391aa70f
|
gaqhf
|
bitmap.Save(sPathNonExtension + "_Page" + (i + 1) + ".png");
|
138 |
66be3f2d
|
Gyusu
|
}
|
139 |
9f04ece0
|
gaqhf
|
|
140 |
|
|
iPercent = (i + 1) * 100 / iPage;
|
141 |
50df80f6
|
gaqhf
|
splashScreenManager1.SetWaitFormDescription((i + 1) + " / " + sPage + " Pages ( " + iPercent + "% )");
|
142 |
66be3f2d
|
Gyusu
|
}
|
143 |
391aa70f
|
gaqhf
|
|
144 |
|
|
MessageBox.Show("변환완료");
|
145 |
|
|
}
|
146 |
|
|
catch (Exception ex)
|
147 |
|
|
{
|
148 |
|
|
MessageBox.Show("변환 이미지의 사이즈를 줄여주십시오");
|
149 |
66be3f2d
|
Gyusu
|
}
|
150 |
83615cfb
|
gaqhf
|
|
151 |
|
|
pdp.CloseDocument();
|
152 |
50df80f6
|
gaqhf
|
splashScreenManager1.CloseWaitForm();
|
153 |
4601d8de
|
Gyusu
|
}
|
154 |
|
|
else
|
155 |
|
|
{
|
156 |
391aa70f
|
gaqhf
|
MessageBox.Show("PDF 경로와 Scale 또는 Width or Height를 확인해주세요");
|
157 |
4601d8de
|
Gyusu
|
}
|
158 |
|
|
|
159 |
391aa70f
|
gaqhf
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
//Properties.Settings.Default._Dpi = Combo_Scale.Text;
|
163 |
|
|
//Properties.Settings.Default._Height = Txt_Length.Text;
|
164 |
|
|
//Properties.Settings.Default._Width = Txt_Width.Text;
|
165 |
|
|
//Properties.Settings.Default.Save();
|
166 |
|
|
///// ConvertPdfToImage(Txt_PDFPath.Text);
|
167 |
|
|
/////
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
//pdftron.PDFNet.Initialize("daelim.co.kr(Doftech Corp):CPU:2::W:AMC(20120315):EF6E886F25A414FFB5F8C1F2999CF2DA33DC6C5164315BAF7011B87AF0FA");
|
172 |
|
|
//using (PDFDoc doc = new PDFDoc(Txt_PDFPath.Text))
|
173 |
|
|
//{
|
174 |
|
|
// ImageCodecInfo DefaultImageCodecInfo = GetEncoderInfo("image/png");
|
175 |
|
|
// EncoderParameters DefaultEncoderParameters = new EncoderParameters(2);
|
176 |
|
|
// System.Drawing.Imaging.Encoder QualityEncoder = System.Drawing.Imaging.Encoder.Quality;
|
177 |
|
|
// System.Drawing.Imaging.Encoder ColorDepthEncoder = System.Drawing.Imaging.Encoder.ColorDepth;
|
178 |
|
|
// DefaultEncoderParameters.Param[0] = new EncoderParameter(QualityEncoder, 100L);
|
179 |
|
|
// DefaultEncoderParameters.Param[1] = new EncoderParameter(ColorDepthEncoder, 1L);
|
180 |
|
|
|
181 |
|
|
// #region 이미지 만들기
|
182 |
|
|
// for (int i = 1; i < doc.GetPageCount() + 1; i++)
|
183 |
|
|
// {
|
184 |
|
|
// string sFileName = "";
|
185 |
|
|
// string pagePath = sPathNonExtension;
|
186 |
|
|
// if (i > 1)
|
187 |
|
|
// {
|
188 |
|
|
// pagePath = sPathNonExtension + "_" + i;
|
189 |
|
|
// }
|
190 |
|
|
// try
|
191 |
|
|
// {
|
192 |
|
|
// using (pdftron.PDF.PDFDraw draw = new pdftron.PDF.PDFDraw())
|
193 |
|
|
// {
|
194 |
|
|
// ElementBuilder bld = new ElementBuilder();
|
195 |
|
|
// ElementWriter writer = new ElementWriter();
|
196 |
|
|
// if (Chk_Scale.Checked)
|
197 |
|
|
// {
|
198 |
|
|
// float fDpix = 600;
|
199 |
|
|
// float fDpiy = 600;
|
200 |
|
|
// try
|
201 |
|
|
// {
|
202 |
|
|
// fDpix = float.Parse(Combo_Scale.Text);
|
203 |
|
|
// fDpiy = float.Parse(Combo_Scale.Text);
|
204 |
|
|
// }
|
205 |
|
|
// catch
|
206 |
|
|
// { }
|
207 |
|
|
|
208 |
|
|
// var rotation = doc.GetPage(i).GetRotation();
|
209 |
|
|
|
210 |
|
|
// draw.SetDPI(fDpix);
|
211 |
|
|
// sFileName = pagePath + "_" + fDpix + ".jpeg";
|
212 |
|
|
// }
|
213 |
|
|
// else
|
214 |
|
|
// {
|
215 |
|
|
// var widthData =int.Parse(Txt_Width.Text);
|
216 |
|
|
// int heightData = int.Parse(Txt_Length.Text);
|
217 |
|
|
|
218 |
|
|
// var rotation = doc.GetPage(i).GetRotation();
|
219 |
|
|
// draw.SetImageSize(widthData, heightData, true);
|
220 |
|
|
// sFileName = pagePath + "_" + widthData + "_" + heightData + ".png";
|
221 |
|
|
// }
|
222 |
|
|
// draw.SetAntiAliasing(false);
|
223 |
|
|
// draw.SetImageSmoothing(false);
|
224 |
|
|
// Bitmap newBmp_ = draw.GetBitmap(doc.GetPage(i));
|
225 |
|
|
|
226 |
|
|
// using (MemoryStream _savestream = new MemoryStream())
|
227 |
|
|
// {
|
228 |
|
|
// try
|
229 |
|
|
// {
|
230 |
|
|
// newBmp_.Save(_savestream, DefaultImageCodecInfo, DefaultEncoderParameters);
|
231 |
|
|
// using (Bitmap bmpImage = new Bitmap(_savestream))
|
232 |
|
|
// {
|
233 |
|
|
// ObjSet objset = new ObjSet();
|
234 |
|
|
// Obj jbig2_hint = objset.CreateName("png");
|
235 |
|
|
// bmpImage.Save(sFileName, ImageFormat.Png);
|
236 |
|
|
// bmpImage.Dispose();
|
237 |
|
|
// // Do something with the Bitmap object
|
238 |
|
|
// }
|
239 |
|
|
// }
|
240 |
|
|
// catch (Exception ex)
|
241 |
|
|
// {
|
242 |
|
|
// MessageBox.Show("err" + "\n" + ex.ToString() + "\n" + ex.Message);
|
243 |
|
|
// }
|
244 |
|
|
|
245 |
|
|
// }
|
246 |
|
|
// GC.Collect();
|
247 |
|
|
// GC.WaitForPendingFinalizers();
|
248 |
|
|
// }
|
249 |
|
|
// }
|
250 |
|
|
// catch (Exception ex)
|
251 |
|
|
// {
|
252 |
|
|
// MessageBox.Show("err2" + "\n" + ex.ToString() + "\n" + ex.Message);
|
253 |
|
|
// // return false;
|
254 |
|
|
// }
|
255 |
|
|
// }
|
256 |
|
|
// if (doc.GetPageCount() > 0)
|
257 |
|
|
// {
|
258 |
|
|
// MessageBox.Show("변환완료");
|
259 |
|
|
// }
|
260 |
|
|
// #endregion
|
261 |
|
|
//}
|
262 |
4601d8de
|
Gyusu
|
}
|
263 |
391aa70f
|
gaqhf
|
|
264 |
|
|
|
265 |
4601d8de
|
Gyusu
|
}
|
266 |
|
|
} |