Skip to content

Commit df50962

Browse files
committed
支持自定义页添加印章
1 parent 8baf626 commit df50962

File tree

3 files changed

+60
-24
lines changed

3 files changed

+60
-24
lines changed

PDFQFZ/Form1.Designer.cs

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

PDFQFZ/Form1.cs

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
350350
signpage = numberOfPages;
351351
all = true;
352352
}
353+
else if (zyz == 4)
354+
{
355+
signpage = numberOfPages;
356+
all = true;
357+
}
353358

354359
for (int i = 1; i <= numberOfPages; i++)
355360
{
@@ -367,6 +372,10 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
367372
DataRow[] arrRow = dtPos.Select("Path = '" + inputfilepath + "' and Page = " + i);
368373
if (arrRow == null || arrRow.Length == 0)
369374
{
375+
if(zyz == 4)//自定义页加印章,如果没有印章定位的页就不盖
376+
{
377+
continue;
378+
}
370379
wbl = Convert.ToSingle(textPx.Text);//这里根据比例来定位
371380
hbl = 1 - Convert.ToSingle(textPy.Text);//这里根据比例来定位
372381
}
@@ -628,6 +637,7 @@ private void pictureBox1_Click(object sender, EventArgs e)
628637
}
629638
Point pt1 = pictureBox1.Location;
630639

640+
pictureBox2.Visible = true;
631641
pictureBox2.Location = new Point(pt1.X+pt.X-10, pt1.Y + pt.Y - 10);
632642

633643
}
@@ -705,11 +715,16 @@ private void buttonUp_Click(object sender, EventArgs e)
705715
DataRow[] arrRow = dtPos.Select("Path = '" + pdfInputPath + "' and Page = " + imgStartPage);
706716
if (arrRow == null || arrRow.Length == 0)
707717
{
718+
if (comboYz.SelectedIndex == 4)
719+
{
720+
pictureBox2.Visible = false;
721+
}
708722
px = Convert.ToSingle(textPx.Text);//这里根据比例来定位
709723
py = Convert.ToSingle(textPy.Text);//这里根据比例来定位
710724
}
711725
else
712726
{
727+
pictureBox2.Visible = true;
713728
DataRow dr = arrRow[0];
714729
px = Convert.ToSingle(dr["X"].ToString());
715730
py = Convert.ToSingle(dr["Y"].ToString());
@@ -738,11 +753,16 @@ private void buttonNext_Click(object sender, EventArgs e)
738753
DataRow[] arrRow = dtPos.Select("Path = '" + pdfInputPath + "' and Page = " + imgStartPage);
739754
if (arrRow == null || arrRow.Length == 0)
740755
{
756+
if (comboYz.SelectedIndex == 4)
757+
{
758+
pictureBox2.Visible = false;
759+
}
741760
px = Convert.ToSingle(textPx.Text);//这里根据比例来定位
742761
py = Convert.ToSingle(textPy.Text);//这里根据比例来定位
743762
}
744763
else
745764
{
765+
pictureBox2.Visible = true;
746766
DataRow dr = arrRow[0];
747767
px = Convert.ToSingle(dr["X"].ToString());
748768
py = Convert.ToSingle(dr["Y"].ToString());
@@ -814,32 +834,47 @@ private void comboQmtype_SelectionChangeCommitted(object sender, EventArgs e)
814834
private void comboPDFlist_SelectionChangeCommitted(object sender, EventArgs e)
815835
{
816836
pdfInputPath = comboPDFlist.SelectedValue.ToString();
817-
PDFFile pdfFile = PDFFile.Open(pdfInputPath);
818-
Bitmap pageImage = pdfFile.GetPageImage(0, 56 * 1);
819-
pictureBox1.Image = pageImage;
820-
imgStartPage = 1;
821-
imgPageCount = pdfFile.PageCount;
822-
pdfFile.Dispose();
823-
labelPage.Text = imgStartPage + "/" + imgPageCount;
824-
825-
float px, py;
826-
DataRow[] arrRow = dtPos.Select("Path = '" + pdfInputPath + "' and Page = " + imgStartPage);
827-
if (arrRow == null || arrRow.Length == 0)
837+
if (pdfInputPath != "")
828838
{
829-
px = Convert.ToSingle(textPx.Text);//这里根据比例来定位
830-
py = Convert.ToSingle(textPy.Text);//这里根据比例来定位
839+
PDFFile pdfFile = PDFFile.Open(pdfInputPath);
840+
Bitmap pageImage = pdfFile.GetPageImage(0, 56 * 1);
841+
pictureBox1.Image = pageImage;
842+
imgStartPage = 1;
843+
imgPageCount = pdfFile.PageCount;
844+
pdfFile.Dispose();
845+
labelPage.Text = imgStartPage + "/" + imgPageCount;
846+
847+
float px, py;
848+
DataRow[] arrRow = dtPos.Select("Path = '" + pdfInputPath + "' and Page = " + imgStartPage);
849+
if (arrRow == null || arrRow.Length == 0)
850+
{
851+
px = Convert.ToSingle(textPx.Text);//这里根据比例来定位
852+
py = Convert.ToSingle(textPy.Text);//这里根据比例来定位
853+
}
854+
else
855+
{
856+
DataRow dr = arrRow[0];
857+
px = Convert.ToSingle(dr["X"].ToString());
858+
py = Convert.ToSingle(dr["Y"].ToString());
859+
}
860+
int X = Convert.ToInt32(pictureBox1.Width * px);
861+
int Y = Convert.ToInt32(pictureBox1.Height * py);
862+
Point pt1 = pictureBox1.Location;
863+
864+
pictureBox2.Location = new Point(pt1.X + X - 10, pt1.Y + Y - 10);
831865
}
832866
else
833867
{
834-
DataRow dr = arrRow[0];
835-
px = Convert.ToSingle(dr["X"].ToString());
836-
py = Convert.ToSingle(dr["Y"].ToString());
868+
imgStartPage = 1;
869+
imgPageCount = 1;
870+
labelPage.Text = "1/1";
871+
Bitmap bmp = new Bitmap(177, 250);
872+
Graphics g = Graphics.FromImage(bmp);
873+
g.FillRectangle(Brushes.White, new Rectangle(0, 0, 177, 250));
874+
g.Dispose();
875+
pictureBox1.Image = bmp;
837876
}
838-
int X = Convert.ToInt32(pictureBox1.Width * px);
839-
int Y = Convert.ToInt32(pictureBox1.Height * py);
840-
Point pt1 = pictureBox1.Location;
841-
842-
pictureBox2.Location = new Point(pt1.X + X - 10, pt1.Y + Y - 10);
877+
843878
}
844879
//根据印章类型切换窗口大小
845880
private void comboYz_SelectionChangeCommitted(object sender, EventArgs e)

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
iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
127-
wQAADsEBuJFr7QAAAVpJREFUOE+VVCF2wzAMNRwc3BHGWmLZLWmPMDg4ODg4uFsU7hiDg4WDhYOFhW0S
127+
vwAADr8BOAVTJAAAAVpJREFUOE+VVCF2wzAMNRwc3BHGWmLZLWmPMDg4ODg4uFsU7hiDg4WDhYOFhW0S
128128
4EmKnCqKs6R67z8rkv6PUql2U3ZZrR6bELYZ1Xq9lNRtVsf41gAcmhgTCqXuJAD84vmRNps7KR836Wjf
129129
kS0ANA41QBTq0KoQXuoQztzNXOBLkPMuElejzmrvbxMjXLvfilRrGNjzZ5QI+rQ5AXZ5TIvFPYvxAChB
130130
gpaoSJM5gE8WxCRNrRW0xdYvCQlwQGdXeb/sinSH9nlCLIMm+8yFRM4CBC1SiudnA4eTfe1IBEvIvs7b

0 commit comments

Comments
 (0)