Skip to content

Commit 8d32dbd

Browse files
committed
调整加印章的类型,更符合常用场景
1 parent 8c270ca commit 8d32dbd

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

PDFQFZ/Form1.Designer.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PDFQFZ/Form1.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

PDFQFZ/Form1.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<data name="pictureBox2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
125125
<value>
126126
iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAYAAADbcAZoAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
127-
wgAADsIBFShKgAAAThFJREFUeF7t3e2RGzmyKNDrx535N07IkDVEjqwha0g7op/7xob7Mimwh02hWyQB
127+
wQAADsEBuJFr7QAAThFJREFUeF7t3e2RGzmyKNDrx535N07IkDVEjqwha0g7op/7xob7Mimwh02hWyQB
128128
VAFV50RkxIzUQrHJYuIb9T8AAAAA0NXf//vXHzfxrcS/SnzP+O+ff/37Pf746z//74+/3m7iR4n/q8T1
129129
7y4/m//2PUp55RrX62VcX8PlNZWXCQAA7K000rOx3tpRWC2e7djoyAAAwCOy8Rxx6WRkw7o0uo/Skdg6
130130
flw7Kvl+RuicAABwPtkIjtDJ2DkqnZNv5SMCAIB1REP2dn+FTsaacVnqlZ9fhM4JAAD7igapWYzzxs99

pdfqfz.jpg

-32.2 KB
Loading

0 commit comments

Comments
 (0)