프로젝트

일반

사용자정보

개정판 224535bb

ID224535bb48a16d6e184a159912ed65a9d789b805
상위 2776a8d2
하위 7dcb95df

gaqhf 이(가) 5년 이상 전에 추가함

dev issue #569 : PDF To Image 변환툴 여러 파일 가능하게 수정 / OPC 작업을 위한 Drawing 정보 정리

Change-Id: I62beba4afda9acbeab9bfb5ace94ca221673c584

차이점 보기:

DTI_PID/PDF_TO_IMAGE/ConvertImage.cs
38 38
        private void Btn_LoadPDF_Click(object sender, EventArgs e)
39 39
        {
40 40
            OpenFileDialog OFD = new OpenFileDialog() { Filter = "PDF Files (.PDF)|*.PDF" };
41
            OFD.Multiselect = true;
41 42
            if (OFD.ShowDialog() == DialogResult.OK)
42 43
            {
43
                string pdfpath = OFD.FileName;
44
                if (OFD.FileNames.Length > 1)
45
                {
46
                    if (MessageBox.Show("여러 파일을 하나로 합치고 진행하시겠습니까?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
47
                    {
48
                        SaveFileDialog saveFileDialog = new SaveFileDialog();
49
                        saveFileDialog.Filter = "PDF Files (.PDF)|*.PDF";
50
                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
51
                        {
52
                            int iScale = 0;
53
                            double iLength = 0;
54
                            bool bResult = true;
55

  
56
                            if (Chk_Scale.Checked)
57
                                iScale = Convert.ToInt32(Combo_Scale.SelectedItem.ToString().Split(new char[] { ' ' })[1]);
58
                            else
59
                            {
60
                                if (!double.TryParse(Txt_Length.Text, out iLength) || iLength < 300)
61
                                    bResult = false;
62

  
63
                            }
64

  
65
                            if (bResult)
66
                            {
67
                                splashScreenManager1.ShowWaitForm();
68
                                splashScreenManager1.SetWaitFormCaption("Convert Pdf File to Image Files");
69

  
70
                                PdfDocumentProcessor pdp = new PdfDocumentProcessor();
71
                                pdp.CreateEmptyDocument();
72
                                foreach (var fileName in OFD.FileNames)
73
                                {
74
                                    PdfDocumentProcessor selectFile = new PdfDocumentProcessor();
75
                                    selectFile.LoadDocument(fileName);
76
                                    foreach (var page in selectFile.Document.Pages)
77
                                        pdp.Document.Pages.Add(page);
78
                                    selectFile.CloseDocument();
79
                                    selectFile.Dispose();
80
                                    selectFile = null;
81
                                }
82

  
83
                                pdp.SaveDocument(saveFileDialog.FileName);
84

  
85
                                string sPathNonExtension = saveFileDialog.FileName.Replace(Path.GetExtension(saveFileDialog.FileName), "");
86

  
87

  
88
                                try
89
                                {
90
                                    int iPage = pdp.Document.Pages.Count;
91
                                    string sPage = iPage.ToString();
92
                                    for (int i = 0; i < pdp.Document.Pages.Count; i++)
93
                                    {
94
                                        int iPercent = i * 100 / iPage;
95
                                        splashScreenManager1.SetWaitFormDescription(i + " / " + sPage + " Pages ( " + iPercent + "% )");
96
                                        PdfPage page = pdp.Document.Pages[i];
97

  
98
                                        double dWidth = page.CropBox.Width;
99
                                        double dHeight = page.CropBox.Height;
44 100

  
45
                Txt_PDFPath.Text = pdfpath;
101
                                        if (Chk_Scale.Checked)
102
                                        {
103
                                            dWidth = dWidth * iScale;
104
                                            dHeight = dHeight * iScale;
105
                                        }
106
                                        else
107
                                        {
108
                                            if (Combo_LengthType.SelectedItem.ToString() == "Width")
109
                                            {
110
                                                double dScale = dWidth / iLength;
111
                                                dWidth = iLength;
112
                                                dHeight = dHeight / dScale;
113
                                            }
114
                                            else
115
                                            {
116
                                                double dScale = dHeight / iLength;
117
                                                dHeight = iLength;
118
                                                dWidth = dWidth / dScale;
119
                                            }
120
                                        }
121

  
122
                                        double dMax = Math.Max(dWidth, dHeight);
123

  
124
                                        using (Bitmap bitmap = pdp.CreateBitmap(i + 1, (int)dMax))
125
                                        {
126
                                            bitmap.Save(sPathNonExtension + "_Page" + (i + 1) + ".png");
127
                                        }
128

  
129
                                        iPercent = (i + 1) * 100 / iPage;
130
                                        splashScreenManager1.SetWaitFormDescription((i + 1) + " / " + sPage + " Pages ( " + iPercent + "% )");
131
                                    }
132

  
133
                                    MessageBox.Show("변환완료");
134
                                }
135
                                catch (Exception ex)
136
                                {
137
                                    MessageBox.Show("변환 이미지의 사이즈를 줄여주십시오");
138
                                }
139

  
140
                                pdp.CloseDocument();
141
                                splashScreenManager1.CloseWaitForm();
142
                            }
143
                            else
144
                            {
145
                                MessageBox.Show("PDF 경로와 Scale 또는 Width or Height를 확인해주세요");
146
                            }
147
                        }
148
                    }
149
                }
150
                else
151
                {
152
                    string pdfpath = OFD.FileName;
153
                    Txt_PDFPath.Text = pdfpath;
154
                }
46 155
            }
47 156
        }
48 157

  
......
155 264
            {
156 265
                MessageBox.Show("PDF 경로와 Scale 또는 Width or Height를 확인해주세요");
157 266
            }
158

  
159
                
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 267
        }
263 268

  
264 269
        

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)