개정판 66be3f2d
update
DTI_PID/PDF_TO_IMAGE/ConvertImage.cs | ||
---|---|---|
58 | 58 |
pdftron.PDFNet.Initialize("daelim.co.kr(Doftech Corp):CPU:2::W:AMC(20120315):EF6E886F25A414FFB5F8C1F2999CF2DA33DC6C5164315BAF7011B87AF0FA"); |
59 | 59 |
using (PDFDoc doc = new PDFDoc(FilePath)) |
60 | 60 |
{ |
61 |
Bitmap newBmp_; |
|
61 |
|
|
62 | 62 |
ImageCodecInfo DefaultImageCodecInfo = GetEncoderInfo("image/png"); |
63 | 63 |
EncoderParameters DefaultEncoderParameters = new EncoderParameters(2); |
64 | 64 |
System.Drawing.Imaging.Encoder QualityEncoder = System.Drawing.Imaging.Encoder.Quality; |
... | ... | |
75 | 75 |
{ |
76 | 76 |
float fDpix = 600; |
77 | 77 |
float fDpiy = 600; |
78 |
//int iWidth = 10000; |
|
79 |
//int iHeight = 10000; |
|
80 | 78 |
try |
81 | 79 |
{fDpix = float.Parse(Combo_DPI.Text); |
82 | 80 |
fDpiy = float.Parse(Combo_DPI.Text);} |
83 | 81 |
catch |
84 | 82 |
{} |
85 |
//try |
|
86 |
//{iWidth = int.Parse(Properties.Settings.Default._Width); |
|
87 |
//iHeight = int.Parse(Properties.Settings.Default._Height); |
|
88 |
//}catch{ } |
|
89 | 83 |
ElementBuilder bld = new ElementBuilder(); |
90 | 84 |
ElementWriter writer = new ElementWriter(); |
91 |
//var widthData = (int)doc.GetPage(i).GetPageWidth(); |
|
92 |
//int heightData = (int)doc.GetPage(i).GetPageHeight(); |
|
93 | 85 |
var rotation = doc.GetPage(i).GetRotation(); |
94 |
// draw.SetImageSize((int)(widthData * 2), (int)(heightData * 2), true); |
|
95 |
// draw.SetImageSize(iWidth, iHeight, true); |
|
96 |
draw.SetAntiAliasing(true); |
|
86 |
draw.SetAntiAliasing(false); |
|
97 | 87 |
draw.SetDPI(fDpix); |
98 |
newBmp_ = draw.GetBitmap(doc.GetPage(i)); |
|
99 |
|
|
88 |
Bitmap newBmp_ = draw.GetBitmap(doc.GetPage(i));
|
|
89 |
|
|
100 | 90 |
using (MemoryStream _savestream = new MemoryStream()) |
101 | 91 |
{ |
102 |
newBmp_.Save(_savestream, DefaultImageCodecInfo, DefaultEncoderParameters); |
|
103 |
newBmp_ = new Bitmap(_savestream); |
|
104 |
ObjSet objset = new ObjSet(); |
|
105 |
Obj jbig2_hint = objset.CreateName("png"); |
|
106 |
string pagePath = sPathNonExtension; |
|
107 |
if (i > 1) |
|
92 |
try |
|
108 | 93 |
{ |
109 |
pagePath = sPathNonExtension + "_" + i; |
|
94 |
newBmp_.Save(_savestream, DefaultImageCodecInfo, DefaultEncoderParameters); |
|
95 |
newBmp_ = new Bitmap(_savestream); |
|
96 |
ObjSet objset = new ObjSet(); |
|
97 |
Obj jbig2_hint = objset.CreateName("png"); |
|
98 |
string pagePath = sPathNonExtension; |
|
99 |
if (i > 1) |
|
100 |
{ |
|
101 |
pagePath = sPathNonExtension + "_" + i; |
|
102 |
} |
|
103 |
newBmp_.Save(pagePath + "_" + fDpix + ".png"); |
|
104 |
newBmp_.Dispose(); |
|
110 | 105 |
} |
111 |
newBmp_.Save(pagePath + "_" + fDpix +".png"); |
|
112 |
newBmp_.Dispose(); |
|
106 |
catch(Exception ex) |
|
107 |
{ |
|
108 | ||
109 |
} |
|
110 |
|
|
113 | 111 |
} |
114 | 112 |
GC.Collect(); |
115 | 113 |
GC.WaitForPendingFinalizers(); |
... | ... | |
117 | 115 |
} |
118 | 116 |
catch (Exception ex) |
119 | 117 |
{ |
120 |
return false; |
|
118 |
// return false;
|
|
121 | 119 |
} |
122 | 120 |
} |
123 | 121 |
if(doc.GetPageCount() > 0) |
124 | 122 |
{ |
125 | 123 |
MessageBox.Show("변환완료"); |
126 | 124 |
} |
127 | ||
128 | 125 |
#endregion |
129 | 126 |
return true; |
130 | 127 |
} |
... | ... | |
140 | 137 |
Properties.Settings.Default._Height = Txt_Height.Text; |
141 | 138 |
Properties.Settings.Default._Width = Txt_Width.Text; |
142 | 139 |
Properties.Settings.Default.Save(); |
143 |
ConvertPdfToImage(Txt_PDFPath.Text); |
|
140 |
/// ConvertPdfToImage(Txt_PDFPath.Text); |
|
141 |
/// |
|
142 |
string sPathNonExtension = Txt_PDFPath.Text.Replace(Path.GetExtension(Txt_PDFPath.Text), ""); |
|
143 | ||
144 | ||
145 |
pdftron.PDFNet.Initialize("daelim.co.kr(Doftech Corp):CPU:2::W:AMC(20120315):EF6E886F25A414FFB5F8C1F2999CF2DA33DC6C5164315BAF7011B87AF0FA"); |
|
146 |
using (PDFDoc doc = new PDFDoc(Txt_PDFPath.Text)) |
|
147 |
{ |
|
148 | ||
149 |
ImageCodecInfo DefaultImageCodecInfo = GetEncoderInfo("image/png"); |
|
150 |
EncoderParameters DefaultEncoderParameters = new EncoderParameters(2); |
|
151 |
System.Drawing.Imaging.Encoder QualityEncoder = System.Drawing.Imaging.Encoder.Quality; |
|
152 |
System.Drawing.Imaging.Encoder ColorDepthEncoder = System.Drawing.Imaging.Encoder.ColorDepth; |
|
153 |
DefaultEncoderParameters.Param[0] = new EncoderParameter(QualityEncoder, 100L); |
|
154 |
DefaultEncoderParameters.Param[1] = new EncoderParameter(ColorDepthEncoder, 8L); |
|
155 | ||
156 |
#region 이미지 만들기 |
|
157 |
for (int i = 1; i < doc.GetPageCount() + 1; i++) |
|
158 |
{ |
|
159 |
try |
|
160 |
{ |
|
161 |
using (pdftron.PDF.PDFDraw draw = new pdftron.PDF.PDFDraw()) |
|
162 |
{ |
|
163 |
float fDpix = 600; |
|
164 |
float fDpiy = 600; |
|
165 |
try |
|
166 |
{ |
|
167 |
fDpix = float.Parse(Combo_DPI.Text); |
|
168 |
fDpiy = float.Parse(Combo_DPI.Text); |
|
169 |
} |
|
170 |
catch |
|
171 |
{ } |
|
172 |
ElementBuilder bld = new ElementBuilder(); |
|
173 |
ElementWriter writer = new ElementWriter(); |
|
174 |
var rotation = doc.GetPage(i).GetRotation(); |
|
175 |
draw.SetAntiAliasing(false); |
|
176 |
draw.SetDPI(fDpix); |
|
177 |
Bitmap newBmp_ = draw.GetBitmap(doc.GetPage(i)); |
|
178 | ||
179 |
using (MemoryStream _savestream = new MemoryStream()) |
|
180 |
{ |
|
181 |
try |
|
182 |
{ |
|
183 |
newBmp_.Save(_savestream, DefaultImageCodecInfo, DefaultEncoderParameters); |
|
184 |
newBmp_ = new Bitmap(_savestream); |
|
185 |
ObjSet objset = new ObjSet(); |
|
186 |
Obj jbig2_hint = objset.CreateName("png"); |
|
187 |
string pagePath = sPathNonExtension; |
|
188 |
if (i > 1) |
|
189 |
{ |
|
190 |
pagePath = sPathNonExtension + "_" + i; |
|
191 |
} |
|
192 |
newBmp_.Save(pagePath + "_" + fDpix + ".png"); |
|
193 |
newBmp_.Dispose(); |
|
194 |
} |
|
195 |
catch (Exception ex) |
|
196 |
{ |
|
197 | ||
198 |
} |
|
199 | ||
200 |
} |
|
201 |
GC.Collect(); |
|
202 |
GC.WaitForPendingFinalizers(); |
|
203 |
} |
|
204 |
} |
|
205 |
catch (Exception ex) |
|
206 |
{ |
|
207 |
// return false; |
|
208 |
} |
|
209 |
} |
|
210 |
if (doc.GetPageCount() > 0) |
|
211 |
{ |
|
212 |
MessageBox.Show("변환완료"); |
|
213 |
} |
|
214 |
#endregion |
|
215 |
} |
|
216 | ||
217 | ||
144 | 218 |
} |
145 | 219 |
else |
146 | 220 |
{ |
내보내기 Unified diff