개정판 79a518e3
dev issue #569 : 폴더 기준으로 변경
Change-Id: Ie71113b8ad4e5449559381513239116d5eac5918
DTI_PID/PDF_TO_IMAGE/ConvertImage.cs | ||
---|---|---|
37 | 37 |
|
38 | 38 |
private void Btn_LoadPDF_Click(object sender, EventArgs e) |
39 | 39 |
{ |
40 |
FolderBrowserDialog dia = new FolderBrowserDialog(); |
|
41 |
if (dia.ShowDialog() == DialogResult.OK) |
|
42 |
{ |
|
43 |
Txt_PDFPath.Text = dia.SelectedPath; |
|
44 |
} |
|
45 |
|
|
46 |
return; |
|
40 | 47 |
OpenFileDialog OFD = new OpenFileDialog() { Filter = "PDF Files (.PDF)|*.PDF" }; |
41 | 48 |
OFD.Multiselect = true; |
42 | 49 |
if (OFD.ShowDialog() == DialogResult.OK) |
... | ... | |
190 | 197 |
{ |
191 | 198 |
if (!double.TryParse(Txt_Length.Text, out iLength) || iLength < 300) |
192 | 199 |
bResult = false; |
193 |
|
|
194 |
} |
|
195 |
|
|
196 |
if (!File.Exists(sFilePath)) |
|
197 |
bResult = false; |
|
198 | 200 |
|
201 |
} |
|
199 | 202 |
|
200 | 203 |
if (bResult) |
201 | 204 |
{ |
202 |
string sPathNonExtension = Txt_PDFPath.Text.Replace(Path.GetExtension(Txt_PDFPath.Text), ""); |
|
203 |
PdfDocumentProcessor pdp = new PdfDocumentProcessor(); |
|
204 |
pdp.LoadDocument(sFilePath); |
|
205 |
|
|
206 |
splashScreenManager1.ShowWaitForm(); |
|
207 |
splashScreenManager1.SetWaitFormCaption("Convert Pdf File to Image Files"); |
|
208 |
try |
|
205 |
DirectoryInfo directory = new DirectoryInfo(Txt_PDFPath.Text); |
|
206 |
if (directory.Exists) |
|
209 | 207 |
{ |
210 |
int iPage = pdp.Document.Pages.Count; |
|
211 |
string sPage = iPage.ToString(); |
|
212 |
for (int i = 0; i < pdp.Document.Pages.Count; i++) |
|
208 |
bool result = true; |
|
209 |
foreach (var item in directory.GetFiles("*.pdf",SearchOption.TopDirectoryOnly)) |
|
213 | 210 |
{ |
214 |
int iPercent = i * 100 / iPage; |
|
215 |
splashScreenManager1.SetWaitFormDescription(i + " / " + sPage + " Pages ( " + iPercent + "% )"); |
|
216 |
PdfPage page = pdp.Document.Pages[i]; |
|
217 |
|
|
218 |
double dWidth = page.CropBox.Width; |
|
219 |
double dHeight = page.CropBox.Height; |
|
211 |
string sPathNonExtension = item.FullName.Replace(Path.GetExtension(item.FullName), ""); |
|
212 |
PdfDocumentProcessor pdp = new PdfDocumentProcessor(); |
|
213 |
pdp.LoadDocument(item.FullName); |
|
220 | 214 |
|
221 |
if (page.Rotate == 90 || page.Rotate == 270) |
|
215 |
splashScreenManager1.ShowWaitForm(); |
|
216 |
splashScreenManager1.SetWaitFormCaption("Convert Pdf File to Image Files"); |
|
217 |
try |
|
222 | 218 |
{ |
223 |
double tempValue = dWidth; |
|
224 |
dWidth = dHeight; |
|
225 |
dHeight = tempValue; |
|
226 |
} |
|
227 |
|
|
228 |
if (Chk_Scale.Checked) |
|
229 |
{ |
|
230 |
dWidth = dWidth * iScale; |
|
231 |
dHeight = dHeight * iScale; |
|
232 |
} |
|
233 |
else |
|
234 |
{ |
|
235 |
if (Combo_LengthType.SelectedItem.ToString() == "Width") |
|
219 |
int iPage = pdp.Document.Pages.Count; |
|
220 |
string sPage = iPage.ToString(); |
|
221 |
for (int i = 0; i < pdp.Document.Pages.Count; i++) |
|
236 | 222 |
{ |
237 |
double dScale = dWidth / iLength; |
|
238 |
dWidth = iLength; |
|
239 |
dHeight = dHeight / dScale; |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
double dScale = dHeight / iLength; |
|
244 |
dHeight = iLength; |
|
245 |
dWidth = dWidth / dScale; |
|
246 |
} |
|
247 |
} |
|
223 |
int iPercent = i * 100 / iPage; |
|
224 |
splashScreenManager1.SetWaitFormDescription(i + " / " + sPage + " Pages ( " + iPercent + "% )"); |
|
225 |
PdfPage page = pdp.Document.Pages[i]; |
|
226 |
|
|
227 |
double dWidth = page.CropBox.Width; |
|
228 |
double dHeight = page.CropBox.Height; |
|
248 | 229 |
|
249 |
double dMax = Math.Max(dWidth, dHeight); |
|
230 |
if (page.Rotate == 90 || page.Rotate == 270) |
|
231 |
{ |
|
232 |
double tempValue = dWidth; |
|
233 |
dWidth = dHeight; |
|
234 |
dHeight = tempValue; |
|
235 |
} |
|
250 | 236 |
|
251 |
using (Bitmap bitmap = pdp.CreateBitmap(i + 1, (int)dMax)) |
|
237 |
if (Chk_Scale.Checked) |
|
238 |
{ |
|
239 |
dWidth = dWidth * iScale; |
|
240 |
dHeight = dHeight * iScale; |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
if (Combo_LengthType.SelectedItem.ToString() == "Width") |
|
245 |
{ |
|
246 |
double dScale = dWidth / iLength; |
|
247 |
dWidth = iLength; |
|
248 |
dHeight = dHeight / dScale; |
|
249 |
} |
|
250 |
else |
|
251 |
{ |
|
252 |
double dScale = dHeight / iLength; |
|
253 |
dHeight = iLength; |
|
254 |
dWidth = dWidth / dScale; |
|
255 |
} |
|
256 |
} |
|
257 |
|
|
258 |
double dMax = Math.Max(dWidth, dHeight); |
|
259 |
|
|
260 |
using (Bitmap bitmap = pdp.CreateBitmap(i + 1, (int)dMax)) |
|
261 |
{ |
|
262 |
bitmap.Save(sPathNonExtension + "_Page" + (i + 1) + ".png"); |
|
263 |
} |
|
264 |
|
|
265 |
iPercent = (i + 1) * 100 / iPage; |
|
266 |
splashScreenManager1.SetWaitFormDescription((i + 1) + " / " + sPage + " Pages ( " + iPercent + "% )"); |
|
267 |
} |
|
268 |
} |
|
269 |
catch (Exception ex) |
|
252 | 270 |
{ |
253 |
bitmap.Save(sPathNonExtension + "_Page" + (i + 1) + ".png"); |
|
271 |
result = false; |
|
272 |
MessageBox.Show("변환 이미지의 사이즈를 줄여주십시오"); |
|
273 |
break; |
|
254 | 274 |
} |
255 | 275 |
|
256 |
iPercent = (i + 1) * 100 / iPage;
|
|
257 |
splashScreenManager1.SetWaitFormDescription((i + 1) + " / " + sPage + " Pages ( " + iPercent + "% )");
|
|
276 |
pdp.CloseDocument();
|
|
277 |
splashScreenManager1.CloseWaitForm();
|
|
258 | 278 |
} |
259 | 279 |
|
260 |
MessageBox.Show("변환완료"); |
|
280 |
if (result) |
|
281 |
MessageBox.Show("변환완료"); |
|
261 | 282 |
} |
262 |
catch (Exception ex)
|
|
283 |
else
|
|
263 | 284 |
{ |
264 |
MessageBox.Show("변환 이미지의 사이즈를 줄여주십시오");
|
|
285 |
MessageBox.Show("PDF 경로와 Scale 또는 Width or Height를 확인해주세요");
|
|
265 | 286 |
} |
266 |
|
|
267 |
pdp.CloseDocument(); |
|
268 |
splashScreenManager1.CloseWaitForm(); |
|
269 | 287 |
} |
270 | 288 |
else |
271 | 289 |
{ |
내보내기 Unified diff