Skip to content

Commit 2b4d63c

Browse files
committed
平均分割改为随机分割
1 parent 8105f33 commit 2b4d63c

File tree

3 files changed

+40
-52
lines changed

3 files changed

+40
-52
lines changed

PDFQFZ/Form1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PDFQFZ/Form1.cs

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -322,25 +322,48 @@ public Bitmap RotateImg(Image b, int angle)
322322
private static Bitmap[] subImages(Bitmap img, int n)//图片分割
323323
{
324324
Bitmap[] nImage = new Bitmap[n];
325-
int h = img.Height;
326-
int w = img.Width;
327-
int sw = w / n;
328-
for (int i = 0; i < n; i++)
325+
int H = img.Height;
326+
int W = img.Width;
327+
int w = W / n;
328+
n = n - 1;
329+
int tmpw = W;
330+
Random random = new Random();
331+
for (int i = 0; i <= n; i++)
329332
{
330-
Bitmap newbitmap = new Bitmap(sw, h);
333+
int sw;
334+
if(i == n)
335+
{
336+
sw = tmpw;
337+
}else if(i == 0)
338+
{
339+
sw =w* random.Next(11,15)/ 10;
340+
}
341+
else
342+
{
343+
sw = w * random.Next(8, 12) / 10;
344+
}
345+
Bitmap newbitmap = new Bitmap(sw, H);
331346
Graphics g = Graphics.FromImage(newbitmap);
332-
g.DrawImage(img, new System.Drawing.Rectangle(0, 0, sw, h), new System.Drawing.Rectangle(sw * i, 0, sw, h), GraphicsUnit.Pixel);
347+
g.DrawImage(img, new System.Drawing.Rectangle(0, 0, sw, H), new System.Drawing.Rectangle(W-tmpw, 0, sw, H), GraphicsUnit.Pixel);
333348
g.Dispose();
334349
nImage[i] = newbitmap;
335-
//newbitmap.Save("D://" + i +".png", ImageFormat.Png);//查看图片是否正常
350+
//newbitmap.Save("D:\\tmp\\img\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);//查看图片是否正常
351+
tmpw = tmpw - sw;
336352
}
337353
return nImage;
338354
}
339355
//PDF盖章
340356
private bool PDFWatermark(string inputfilepath, string outputfilepath)
341357
{
342-
float picbl = 1.003f;//别问我这个数值怎么来的
343-
float picmm = 2.842f;//别问我这个数值怎么来的
358+
float sfbl = 100f;
359+
if (sizeType == 0)
360+
{
361+
sfbl = size * 1.003f;//别问我为什么要乘这个
362+
}
363+
else
364+
{
365+
sfbl = 100f * size * 2.842f / imgYz.Height;
366+
}
344367

345368
//PdfGState state = new PdfGState();
346369
//state.FillOpacity = 0.01f*opacity;//印章图片不透明度
@@ -397,26 +420,8 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
397420
//image.Rotation//旋转
398421
//image.ScaleToFit(140F, 320F);//设置图片的指定大小
399422
//image.RotationDegrees = rotation//旋转角度
400-
float sfbl, imageW, imageH;
401-
if (sizeType == 0)
402-
{
403-
sfbl = size * picbl;//别问我为什么要乘这个
404-
image.ScalePercent(sfbl);//设置图片比例
405-
406-
//imageW = image.Width * sfbl / 100f;
407-
//imageH = image.Height * sfbl / 100f;
408-
//image.ScaleToFit(imageW, imageH);//设置图片的指定大小
409-
}
410-
else
411-
{
412-
sfbl = 100f * size * picmm / (image.Width * tmp);//印章尺寸*DPI转换比例/(分割后图片的宽度*分割份数),再转百分比
413-
image.ScalePercent(sfbl);//设置图片比例
414-
415-
//sfbl = size * picmm;//别问我为什么要乘这个
416-
//imageW = sfbl / tmp;
417-
//imageH = sfbl;
418-
//image.ScaleToFit(imageW, imageH);//设置图片的指定大小
419-
}
423+
float imageW, imageH;
424+
image.ScalePercent(sfbl);//设置图片比例
420425
imageW = image.Width * sfbl / 100f;
421426
imageH = image.Height * sfbl / 100f;
422427

@@ -443,7 +448,7 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
443448
if (yzType!=0|| qmType != 0)
444449
{
445450
iTextSharp.text.Image img = null;
446-
float sfbl=100f, imgW=0, imgH=0;
451+
float imgW=0, imgH=0;
447452
float xPos=0, yPos=0;
448453
bool all = false;
449454
int signpage = 0;
@@ -453,24 +458,7 @@ private bool PDFWatermark(string inputfilepath, string outputfilepath)
453458
img = iTextSharp.text.Image.GetInstance(imgYz, System.Drawing.Imaging.ImageFormat.Png);//创建一个图片对象
454459
//img.Transparency = new int[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//这里透明背景的图片会变黑色,所以设置黑色为透明
455460
//img.RotationDegrees = rotation;
456-
457-
if (sizeType == 0)
458-
{
459-
sfbl = size * picbl;//别问我为什么要乘这个
460-
img.ScalePercent(sfbl);//设置图片比例
461-
//imgW = img.Width * sfbl / 100f;
462-
//imgH = img.Height * sfbl / 100f;
463-
//img.ScaleToFit(imgW, imgH);//设置图片的指定大小
464-
}
465-
else
466-
{
467-
sfbl = 100f*size * picmm / img.Width;
468-
img.ScalePercent(sfbl);//设置图片比例
469-
//sfbl = size * picmm;//别问我为什么要乘这个
470-
//imgW = sfbl;
471-
//imgH = sfbl* img.Height/ img.Width;
472-
//img.ScaleToFit(imgW, imgH);//设置图片的指定大小,实际只能指定宽度,高度还是按照图片比例计算的
473-
}
461+
img.ScalePercent(sfbl);//设置图片比例
474462
}
475463
imgW = img.Width * sfbl / 100f;
476464
imgH = img.Height * sfbl / 100f;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# PDFQFZ
22
PDF加盖骑缝章的小工具
33

4-
选择需要盖章的PDF文件所在文件或文件夹
4+
选择需要盖章的PDF文件或文件夹
55
选择保存文件夹。
6-
选择完整的印章图片,工具会根据PDF页数做等份切割
6+
选择完整的印章图片,工具会根据PDF页数做随机分割
77
设定印章大小,骑缝章位置,印章位置等
8-
点盖章,骚等后在保存文件夹中即可看到盖好骑缝章PDF文件
8+
点盖章,骚等后在保存文件夹中即可看到盖好骑缝章的PDF文件
99

1010
![img](./pdfqfz.jpg)
1111

0 commit comments

Comments
 (0)