Skip to content

Commit c9cf6af

Browse files
committed
支持调整印章角度(不含骑缝章)
支持直接拖拽文件或目录 印章改为缩放比例添加 修复删除印章超出索引的BUG
1 parent b668f64 commit c9cf6af

File tree

3 files changed

+145
-53
lines changed

3 files changed

+145
-53
lines changed

PDFQFZ/Form1.Designer.cs

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

PDFQFZ/Form1.cs

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private void pdfGz()
183183
MessageBox.Show(ex.ToString());
184184
}
185185
}
186+
186187
//分割图片
187188
private static Bitmap[] subImages(String imgPath, int n)//图片分割
188189
{
@@ -209,8 +210,9 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
209210
int zyz = comboYz.SelectedIndex;//加印章方式
210211
int zqfz = comboQfz.SelectedIndex;//加骑缝章方式
211212
int sftype = comboBoxBL.SelectedIndex;//印章缩放方式
212-
float sfsize, qfzwzbl;
213+
float sfsize, yzrotation, qfzwzbl;
213214
float.TryParse(textBili.Text, out sfsize);//印章缩放尺寸
215+
float.TryParse(textRotation.Text, out yzrotation);//骑缝章位置比例
214216
float.TryParse(textWzbl.Text, out qfzwzbl);//骑缝章位置比例
215217
float picbl = 1.003f;//别问我这个数值怎么来的
216218
float picmm = 2.842f;//别问我这个数值怎么来的
@@ -269,23 +271,29 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
269271
//image.GrayFill = 20;//透明度,灰色填充
270272
//image.Rotation//旋转
271273
//image.ScaleToFit(140F, 320F);//设置图片的指定大小
272-
//image.RotationDegrees//旋转角度
274+
//image.RotationDegrees = yzrotation//旋转角度
273275
float sfbl, imageW, imageH;
274276
if (sftype == 0)
275277
{
276278
sfbl = sfsize * picbl;//别问我为什么要乘这个
277-
imageW = image.Width * sfbl / 100f;
278-
imageH = image.Height * sfbl / 100f;
279-
//image.ScalePercent(sfbl);//设置图片比例
280-
image.ScaleToFit(imageW, imageH);//设置图片的指定大小
279+
image.ScalePercent(sfbl);//设置图片比例
280+
281+
//imageW = image.Width * sfbl / 100f;
282+
//imageH = image.Height * sfbl / 100f;
283+
//image.ScaleToFit(imageW, imageH);//设置图片的指定大小
281284
}
282285
else
283286
{
284-
sfbl = sfsize * picmm;//别问我为什么要乘这个
285-
imageW = sfbl / tmp;
286-
imageH = sfbl;
287-
image.ScaleToFit(imageW, imageH);//设置图片的指定大小
287+
sfbl = 100f * sfsize * picmm / image.Height;
288+
image.ScalePercent(sfbl);//设置图片比例
289+
290+
//sfbl = sfsize * picmm;//别问我为什么要乘这个
291+
//imageW = sfbl / tmp;
292+
//imageH = sfbl;
293+
//image.ScaleToFit(imageW, imageH);//设置图片的指定大小
288294
}
295+
imageW = image.Width * sfbl / 100f;
296+
imageH = image.Height * sfbl / 100f;
289297

290298
//水印的位置
291299
float xPos, yPos;
@@ -310,7 +318,7 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
310318
if (zyz!=0|| comboQmtype.SelectedIndex != 0)
311319
{
312320
iTextSharp.text.Image img = null;
313-
float sfbl, imgW=0, imgH=0;
321+
float sfbl=100f, imgW=0, imgH=0;
314322
float xPos=0, yPos=0;
315323
bool all = false;
316324
int signpage = 0;
@@ -319,23 +327,28 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath, X509Certi
319327
{
320328
img = iTextSharp.text.Image.GetInstance(ModelPicName);//创建一个图片对象
321329
img.Transparency = new int[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//这里透明背景的图片会变黑色,所以设置黑色为透明
330+
img.RotationDegrees = yzrotation;
322331

323332
if (sftype == 0)
324333
{
325334
sfbl = sfsize * picbl;//别问我为什么要乘这个
326-
imgW = img.Width * sfbl / 100f;
327-
imgH = img.Height * sfbl / 100f;
328-
//img.ScalePercent(sfbl);//设置图片比例
329-
img.ScaleToFit(imgW, imgH);//设置图片的指定大小
335+
img.ScalePercent(sfbl);//设置图片比例
336+
//imgW = img.Width * sfbl / 100f;
337+
//imgH = img.Height * sfbl / 100f;
338+
//img.ScaleToFit(imgW, imgH);//设置图片的指定大小
330339
}
331340
else
332341
{
333-
sfbl = sfsize * picmm;//别问我为什么要乘这个
334-
imgW = sfbl;
335-
imgH = sfbl* img.Height/ img.Width;
336-
img.ScaleToFit(imgW, imgH);//设置图片的指定大小,实际只能指定宽度,高度还是按照图片比例计算的
342+
sfbl = 100f*sfsize * picmm / img.Height;
343+
img.ScalePercent(sfbl);//设置图片比例
344+
//sfbl = sfsize * picmm;//别问我为什么要乘这个
345+
//imgW = sfbl;
346+
//imgH = sfbl* img.Height/ img.Width;
347+
//img.ScaleToFit(imgW, imgH);//设置图片的指定大小,实际只能指定宽度,高度还是按照图片比例计算的
337348
}
338349
}
350+
imgW = img.Width * sfbl / 100f;
351+
imgH = img.Height * sfbl / 100f;
339352

340353
if (zyz == 1)
341354
{
@@ -577,20 +590,6 @@ private void GzPath_Click(object sender, EventArgs e)
577590
textGZpath.Text = file.FileName;
578591
}
579592
}
580-
//重置按钮
581-
private void clear_Click(object sender, EventArgs e)
582-
{
583-
pathText.Text = "";
584-
textBCpath.Text = "";
585-
textGZpath.Text = "";
586-
imgPageCount = 0;
587-
imgStartPage = 0;
588-
dt.Rows.Clear();
589-
dtPos.Rows.Clear();
590-
pdfInputPath = null;
591-
log.Text = "提示:印章图片默认是72dpi(那40mm印章对应的像素就是113),打印效果会很模糊,建议使用300dpi以上的印章图片然后调整印章比例,如300dpi(40mm印章对应像素472)对应的比例是72/300=24%,所以比例直接填写24即可";
592-
593-
}
594593
//程序加载
595594
private void Form1_Load(object sender, EventArgs e)
596595
{
@@ -784,11 +783,88 @@ private void pictureBox2_DoubleClick(object sender, EventArgs e)
784783
DataRow[] arrRow = dtPos.Select("Path = '" + pdfInputPath + "' and Page = " + imgStartPage);
785784
if(arrRow != null || arrRow.Length > 0)
786785
{
787-
dtPos.Rows.Remove(arrRow[0]);
786+
try
787+
{
788+
dtPos.Rows.Remove(arrRow[0]);
789+
}
790+
catch
791+
{
792+
793+
}
794+
788795
}
789796
}
790797
}
791798

799+
private void pathText_DragEnter(object sender, DragEventArgs e)
800+
{
801+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
802+
{
803+
e.Effect = DragDropEffects.All;//调用DragDrop事件
804+
}
805+
else
806+
{
807+
e.Effect = DragDropEffects.None;
808+
}
809+
}
810+
811+
private void pathText_DragDrop(object sender, DragEventArgs e)
812+
{
813+
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);//拖放的多个文件的路径列表
814+
815+
if (Directory.Exists(filePaths[0])&&comboType.SelectedIndex==0)
816+
{
817+
this.pathText.Text = filePaths[0];
818+
this.textBCpath.Text = filePaths[0] + "\\QFZ";
819+
}
820+
else
821+
{
822+
string pdfPaths = "";
823+
824+
foreach (string filePath in filePaths)
825+
{
826+
string extension = System.IO.Path.GetExtension(filePath);//文件后缀名
827+
if (extension == ".pdf")
828+
{
829+
//todo you code
830+
pdfPaths += filePath + ",";
831+
}
832+
}
833+
if(pdfPaths.Length > 0)
834+
{
835+
pdfPaths = pdfPaths.Substring(0, pdfPaths.Length - 1);
836+
this.pathText.Text = pdfPaths;
837+
this.textBCpath.Text = System.IO.Path.GetDirectoryName(filePaths[0]);
838+
}
839+
}
840+
841+
}
842+
843+
private void textGZpath_DragEnter(object sender, DragEventArgs e)
844+
{
845+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
846+
{
847+
e.Effect = DragDropEffects.All;//调用DragDrop事件
848+
}
849+
else
850+
{
851+
e.Effect = DragDropEffects.None;
852+
}
853+
}
854+
855+
private void textGZpath_DragDrop(object sender, DragEventArgs e)
856+
{
857+
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);//拖放的多个文件的路径列表
858+
859+
string extension = System.IO.Path.GetExtension(filePaths[0]);//文件后缀名
860+
if ((extension == ".gif") || (extension == ".bmp") || (extension == ".png") || (extension == ".jpg") || (extension == ".jpeg"))
861+
{
862+
//todo you code
863+
this.textGZpath.Text = filePaths[0];
864+
}
865+
}
866+
867+
792868
//数字签名类型
793869
private void comboQmtype_SelectionChangeCommitted(object sender, EventArgs e)
794870
{

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-
vgAADr4B6kKxwAAAAVpJREFUOE+VVCF2wzAMNRwc3BHGWmLZLWmPMDg4ODg4uFsU7hiDg4WDhYOFhW0S
127+
vAAADrwBlbxySQAAAVpJREFUOE+VVCF2wzAMNRwc3BHGWmLZLWmPMDg4ODg4uFsU7hiDg4WDhYOFhW0S
128128
4EmKnCqKs6R67z8rkv6PUql2U3ZZrR6bELYZ1Xq9lNRtVsf41gAcmhgTCqXuJAD84vmRNps7KR836Wjf
129129
kS0ANA41QBTq0KoQXuoQztzNXOBLkPMuElejzmrvbxMjXLvfilRrGNjzZ5QI+rQ5AXZ5TIvFPYvxAChB
130130
gpaoSJM5gE8WxCRNrRW0xdYvCQlwQGdXeb/sinSH9nlCLIMm+8yFRM4CBC1SiudnA4eTfe1IBEvIvs7b

0 commit comments

Comments
 (0)