@@ -267,7 +267,7 @@ private void button1_Click(object sender, EventArgs e)
267267 }
268268 else if ( ! int . TryParse ( textCC . Text , out size ) || size > 100 )
269269 {
270- MessageBox . Show ( "印章尺寸设置错误,请输入正确的比例或尺寸 。" ) ;
270+ MessageBox . Show ( "印章尺寸设置错误,请输入正确的尺寸 。" ) ;
271271 }
272272 else if ( ! int . TryParse ( textRotation . Text , out rotation ) )
273273 {
@@ -831,25 +831,32 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
831831 iTextSharp . text . Image img = null ;
832832 float imgW = 0 , imgH = 0 ;
833833 float xPos = 0 , yPos = 0 ;
834- bool all = false ;
834+ int no_page = 0 ; //不需要盖印章的页,0表示所有页都需要盖印章
835835 int signpage = 0 ;
836836
837- if ( yzType == 1 )
837+ if ( yzType == 1 ) //首页不加印章
838838 {
839- signpage = numberOfPages ; //尾页加印章
839+ if ( numberOfPages > 1 )
840+ {
841+ no_page = 1 ;
842+ }
843+ signpage = numberOfPages ;
840844 }
841- else if ( yzType == 2 )
845+ else if ( yzType == 2 ) //尾页不加印章
842846 {
843- signpage = 1 ; //首页加印章
847+ if ( numberOfPages > 1 )
848+ {
849+ no_page = numberOfPages ;
850+ }
851+ signpage = 1 ;
844852 }
845- else if ( yzType == 3 )
853+ else if ( yzType == 3 ) //所有页加印章
846854 {
847- signpage = numberOfPages ; //所有页加印章
848- all = true ;
855+ signpage = numberOfPages ;
849856 }
850- else if ( yzType == 4 )
857+ else if ( yzType == 4 ) //自定义页加印章
851858 {
852- signpage = 1 ; //自定义页加印章
859+ signpage = 1 ;
853860 // 遍历 DataTable 的所有行
854861 foreach ( DataRow row in dtPos . Rows )
855862 {
@@ -863,12 +870,11 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
863870 }
864871 }
865872 }
866- all = true ;
867873 }
868874
869875 for ( int i = 1 ; i <= numberOfPages ; i ++ )
870876 {
871- if ( all || i == signpage )
877+ if ( no_page == 0 || i != no_page || i == signpage )
872878 {
873879 waterMarkContent = pdfStamper . GetOverContent ( i ) ; //获取当前页内容
874880 int rotation = pdfReader . GetPageRotation ( i ) ; //获取指定页面的旋转度
@@ -920,7 +926,7 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
920926 if ( i != signpage )
921927 {
922928 Random random = new Random ( ) ;
923- RotationDegrees = random . Next ( - 10 , 11 ) ; //每页的印章设置个随机的角度
929+ RotationDegrees = random . Next ( - 5 , 6 ) ; //每页的印章设置个随机的角度
924930 }
925931 else
926932 {
@@ -986,13 +992,6 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
986992 ////结束
987993 //waterMarkContent.EndText();
988994
989-
990- //如果不是所有页都盖章,那对应页盖完后直接跳出循环
991- if ( ! all && i == signpage )
992- {
993- break ;
994- }
995-
996995 }
997996 }
998997
@@ -1624,11 +1623,11 @@ public void viewPDFPage()
16241623 {
16251624 pictureBox2 . Visible = false ;
16261625 }
1627- else if ( comboYz . SelectedIndex == 1 && imgStartPage == 1 && imgPageCount > 1 ) //页数大于1页时,尾页加盖时 ,首页不显示,只有一页则会显示
1626+ else if ( comboYz . SelectedIndex == 1 && imgStartPage == 1 && imgPageCount > 1 ) //首页不加印章 ,首页不显示,只有一页则会显示
16281627 {
16291628 pictureBox2 . Visible = false ;
16301629 }
1631- else if ( comboYz . SelectedIndex == 2 && imgStartPage == imgPageCount && imgPageCount > 1 ) //页数大于1页时,首页加章 ,尾页不显示章,只有1页也会显示
1630+ else if ( comboYz . SelectedIndex == 2 && imgStartPage == imgPageCount && imgPageCount > 1 ) //尾页不加印章 ,尾页不显示章,只有1页也会显示
16321631 {
16331632 pictureBox2 . Visible = false ;
16341633 }
0 commit comments