1212using iTextSharp . text ;
1313using iTextSharp . text . exceptions ;
1414using Org . BouncyCastle . Crypto . Generators ;
15+ using PDFQFZ . Library ;
1516
1617namespace PDFQFZ
1718{
@@ -24,11 +25,11 @@ public partial class Form1 : Form
2425 DataTable dtPos = new DataTable ( ) ; //PDF各文件印章位置表
2526 DataTable dtYz = new DataTable ( ) ; //PDF列表
2627 string sourcePath = "" , outputPath = "" , imgPath = "" , previewPath = "" , signText = "" , password = "" , pdfpassword = "" ;
27- int wjType = 1 , qfzType = 0 , yzType = 0 , djType = 0 , qmType = 0 , wzType = 3 , qbflag = 0 , size = 40 , rotation = 0 , opacity = 100 , wz = 50 , yzr = 10 , maximg = 250 , maxfgs = 20 ;
28+ int wjType = 1 , qfzType = 0 , yzType = 0 , djType = 0 , qmType = 0 , wzType = 3 , yzIndex = - 1 , qbflag = 0 , size = 40 , rotation = 0 , opacity = 100 , wz = 50 , yzr = 10 , maximg = 250 , maxfgs = 20 ;
2829 Bitmap imgYz = null ;
2930 X509Certificate2 cert = null ; //证书
3031 float xzbl = 1f ;
31-
32+ private string strIniFilePath = $@ " { Application . StartupPath } \config.ini" ; //获取INI文件路径
3233
3334
3435 System . Reflection . Assembly CurrentDomain_AssemblyResolve ( object sender , ResolveEventArgs args ) //把DLL打包到EXE需要用到
@@ -52,22 +53,123 @@ public Form1()
5253 //程序加载
5354 private void Form1_Load ( object sender , EventArgs e )
5455 {
56+ if ( File . Exists ( strIniFilePath ) ) //读取时先要判读INI文件是否存在
57+ {
58+ IniFileHelper iniFileHelper = new IniFileHelper ( strIniFilePath ) ;
59+ string section = "config" ;
60+ string WjType = iniFileHelper . ContentValue ( section , "wjType" ) ; //文件类型
61+ string QfzType = iniFileHelper . ContentValue ( section , "qfzType" ) ; //骑缝章类型
62+ string YzType = iniFileHelper . ContentValue ( section , "yzType" ) ; //印章类型
63+ string DjType = iniFileHelper . ContentValue ( section , "djType" ) ; //叠加类型
64+ string QmType = iniFileHelper . ContentValue ( section , "qmType" ) ; //签名类型
65+ string WzType = iniFileHelper . ContentValue ( section , "wzType" ) ; //骑缝章位置类型
66+ string Qbflag = iniFileHelper . ContentValue ( section , "qbflag" ) ; //是否切边标记
67+ string Size = iniFileHelper . ContentValue ( section , "size" ) ; //印章尺寸
68+ string Rotation = iniFileHelper . ContentValue ( section , "rotation" ) ; //旋转角度
69+ string Opacity = iniFileHelper . ContentValue ( section , "opacity" ) ; //不透明度
70+ string Wz = iniFileHelper . ContentValue ( section , "wz" ) ; //骑缝章位置
71+ string Maxfgs = iniFileHelper . ContentValue ( section , "maxfgs" ) ; //骑缝章最大分割数
72+ string YzIndex = iniFileHelper . ContentValue ( section , "yzIndex" ) ; //选择的印章索引
73+ signText = iniFileHelper . ContentValue ( section , "signText" ) ; //签名
74+ wjType = Int32 . Parse ( WjType ) ;
75+ qfzType = Int32 . Parse ( QfzType ) ;
76+ yzType = Int32 . Parse ( YzType ) ;
77+ djType = Int32 . Parse ( DjType ) ;
78+ qmType = Int32 . Parse ( QmType ) ;
79+ wzType = Int32 . Parse ( WzType ) ;
80+ qbflag = Int32 . Parse ( Qbflag ) ;
81+ size = Int32 . Parse ( Size ) ;
82+ rotation = Int32 . Parse ( Rotation ) ;
83+ opacity = Int32 . Parse ( Opacity ) ;
84+ wz = Int32 . Parse ( Wz ) ;
85+ maxfgs = Int32 . Parse ( Maxfgs ) ;
86+ yzIndex = Int32 . Parse ( YzIndex ) ;
87+ }
88+ fw = this . Width ;
89+ fh = this . Height ;
90+ if ( yzType != 0 || qfzType == 4 )
91+ {
92+ this . Size = new Size ( fw + 267 , fh ) ;
93+ }
94+ else
95+ {
96+ this . Size = new Size ( fw , fh ) ;
97+ }
5598 comboType . SelectedIndex = wjType ;
5699 comboQfz . SelectedIndex = qfzType ;
57100 comboYz . SelectedIndex = yzType ;
58101 comboDJ . SelectedIndex = djType ;
59102 comboQmtype . SelectedIndex = qmType ;
60103 comboBoxWZ . SelectedIndex = wzType ;
61104 comboBoxQB . SelectedIndex = qbflag ;
62- fw = this . Width ;
63- fh = this . Height ;
105+ textCC . Text = size . ToString ( ) ;
106+ textRotation . Text = rotation . ToString ( ) ;
107+ textOpacity . Text = opacity . ToString ( ) ;
108+ textWzbl . Text = wz . ToString ( ) ;
109+ textMaxFgs . Text = maxfgs . ToString ( ) ;
110+ textname . Text = signText ;
111+ if ( qmType == 0 )
112+ {
113+ labelname . Text = "签名" ;
114+ textname . Text = "" ;
115+ textpass . Text = "" ;
116+ textname . ReadOnly = true ;
117+ textpass . ReadOnly = true ;
118+ }
119+ else if ( qmType == 1 )
120+ {
121+
122+ textpass . Text = "" ;
123+ if ( ! File . Exists ( certDefaultPath ) )
124+ {
125+ labelname . Text = "签名" ;
126+ textname . Text = "" ;
127+ textname . ReadOnly = false ;
128+ }
129+ else
130+ {
131+ labelname . Text = "证书" ;
132+ textname . Text = certDefaultPath ;
133+ textname . ReadOnly = true ;
134+ }
135+
136+ textpass . ReadOnly = false ;
137+ }
138+ else
139+ {
140+ labelname . Text = "证书" ;
141+ textname . Text = "" ;
142+ textpass . Text = "" ;
143+ textname . ReadOnly = true ;
144+ textpass . ReadOnly = false ;
145+
146+ OpenFileDialog file = new OpenFileDialog ( ) ;
147+ file . Filter = "证书文件|*.pfx" ;
148+ if ( file . ShowDialog ( ) == DialogResult . OK )
149+ {
150+ textname . Text = file . FileName ;
151+ }
152+ else
153+ {
154+ comboQmtype . SelectedIndex = 0 ;
155+ labelname . Text = "签名" ;
156+ textname . ReadOnly = true ;
157+ textpass . ReadOnly = true ;
158+ }
159+ }
64160 dtYz . Columns . Add ( "Name" , typeof ( string ) ) ;
65161 dtYz . Columns . Add ( "Value" , typeof ( string ) ) ;
66162 comboBoxYz . DisplayMember = "Name" ;
67163 comboBoxYz . ValueMember = "Value" ;
68164 comboBoxYz . DataSource = dtYz ;
69165 if ( ! File . Exists ( yzLog ) )
70166 {
167+ yzIndex = - 1 ;
168+ //为了避免误删印章记录,然后下次打开又不盖章,再打开可能的报错,这里先重置下印章索引
169+ IniFileHelper iniFileHelper = new IniFileHelper ( strIniFilePath ) ;
170+ string section = "config" ;
171+ iniFileHelper . WriteIniString ( section , "yzIndex" , yzIndex . ToString ( ) ) ;
172+
71173 File . Create ( yzLog ) . Close ( ) ;
72174 }
73175 else
@@ -84,6 +186,7 @@ private void Form1_Load(object sender, EventArgs e)
84186 sr . Close ( ) ;
85187 sr . Dispose ( ) ;
86188 }
189+ comboBoxYz . SelectedIndex = yzIndex ;
87190 dt . Columns . Add ( "Name" , typeof ( string ) ) ;
88191 dt . Columns . Add ( "Value" , typeof ( string ) ) ;
89192 comboPDFlist . DisplayMember = "Name" ;
@@ -105,6 +208,7 @@ private void button1_Click(object sender, EventArgs e)
105208 qmType = comboQmtype . SelectedIndex ;
106209 wzType = comboBoxWZ . SelectedIndex ;
107210 qbflag = comboBoxQB . SelectedIndex ;
211+ yzIndex = comboBoxYz . SelectedIndex ;
108212
109213 if ( qfzType == 1 && yzType == 0 && qmType == 0 )
110214 {
@@ -152,6 +256,24 @@ private void button1_Click(object sender, EventArgs e)
152256 else
153257 {
154258 pdfGz ( ) ;
259+
260+ //自动保持最后一次盖章的配置信息到配置文件
261+ IniFileHelper iniFileHelper = new IniFileHelper ( strIniFilePath ) ;
262+ string section = "config" ;
263+ iniFileHelper . WriteIniString ( section , "wjType" , wjType . ToString ( ) ) ;
264+ iniFileHelper . WriteIniString ( section , "qfzType" , qfzType . ToString ( ) ) ;
265+ iniFileHelper . WriteIniString ( section , "yzType" , yzType . ToString ( ) ) ;
266+ iniFileHelper . WriteIniString ( section , "djType" , djType . ToString ( ) ) ;
267+ iniFileHelper . WriteIniString ( section , "qmType" , qmType . ToString ( ) ) ;
268+ iniFileHelper . WriteIniString ( section , "wzType" , wzType . ToString ( ) ) ;
269+ iniFileHelper . WriteIniString ( section , "qbflag" , qbflag . ToString ( ) ) ;
270+ iniFileHelper . WriteIniString ( section , "size" , size . ToString ( ) ) ;
271+ iniFileHelper . WriteIniString ( section , "rotation" , rotation . ToString ( ) ) ;
272+ iniFileHelper . WriteIniString ( section , "opacity" , opacity . ToString ( ) ) ;
273+ iniFileHelper . WriteIniString ( section , "wz" , wz . ToString ( ) ) ;
274+ iniFileHelper . WriteIniString ( section , "maxfgs" , maxfgs . ToString ( ) ) ;
275+ iniFileHelper . WriteIniString ( section , "yzIndex" , yzIndex . ToString ( ) ) ;
276+ iniFileHelper . WriteIniString ( section , "signText" , signText ) ;
155277 }
156278 }
157279 else
0 commit comments