Skip to content

Commit 2024f3f

Browse files
committed
移除DPI参数简化操作和其他小优化
1 parent 5cb3faf commit 2024f3f

File tree

4 files changed

+353
-66
lines changed

4 files changed

+353
-66
lines changed

PDFQFZ/Form1.Designer.cs

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

PDFQFZ/Form1.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class Form1 : Form
2727
DataTable dtPos = new DataTable();//PDF各文件印章位置表
2828
DataTable dtYz = new DataTable();//PDF列表
2929
string sourcePath = "",outputPath = "",imgPath = "",previewPath = "",signText = "", password="",pdfpassword="";
30-
int wjType = 1, qfzType = 0, yzType = 0, djType = 0, qmType = 0, wzType = 3, yzIndex = -1, qbflag = 0, size = 40, rotation = 0, opacity = 100, wz = 50, yzr = 30, maximg = 500, maxfgs = 20, dpi = 72;
30+
int wjType = 1, qfzType = 0, yzType = 0, djType = 0, qmType = 0, wzType = 3, yzIndex = -1, qbflag = 0, size = 40, rotation = 0, opacity = 100, wz = 50, yzr = 36, maximg = 500, maxfgs = 20;
3131
Bitmap imgYz = null;
3232
Bitmap[] viewPdfimgs = null;
3333
X509Certificate2 cert = null;//证书
@@ -66,7 +66,6 @@ private void Form1_Load(object sender, EventArgs e)
6666
string WzType = iniFileHelper.ContentValue(section, "wzType");//骑缝章位置类型
6767
string Qbflag = iniFileHelper.ContentValue(section, "qbflag");//是否切边标记
6868
string Size = iniFileHelper.ContentValue(section, "size");//印章尺寸
69-
string Dpi = iniFileHelper.ContentValue(section, "dpi");//DPF的DPI
7069
string Rotation = iniFileHelper.ContentValue(section, "rotation");//旋转角度
7170
string Opacity = iniFileHelper.ContentValue(section, "opacity");//不透明度
7271
string Wz = iniFileHelper.ContentValue(section, "wz");//骑缝章位置
@@ -81,7 +80,6 @@ private void Form1_Load(object sender, EventArgs e)
8180
wzType = ToIntOrDefault(WzType, 3);
8281
qbflag = ToIntOrDefault(Qbflag, 0);
8382
size = ToIntOrDefault(Size, 40);
84-
dpi = ToIntOrDefault(Dpi, 72);
8583
rotation = ToIntOrDefault(Rotation, 0);
8684
opacity = ToIntOrDefault(Opacity, 100);
8785
wz = ToIntOrDefault(Wz, 50);
@@ -106,12 +104,13 @@ private void Form1_Load(object sender, EventArgs e)
106104
comboBoxWZ.SelectedIndex = wzType;
107105
comboBoxQB.SelectedIndex = qbflag;
108106
textCC.Text = size.ToString();
109-
textDpi.Text = dpi.ToString();
110107
textRotation.Text = rotation.ToString();
111108
textOpacity.Text = opacity.ToString();
112109
textWzbl.Text = wz.ToString();
113110
textMaxFgs.Text = maxfgs.ToString();
114111
textname.Text = signText;
112+
pictureBox2.Parent = this.pictureBox1;//设置盖章预览图片的父控件为盖章预览框
113+
pictureBox2.Location = new Point(220, 380);//盖章预览图片位置
115114
if (qmType == 0)
116115
{
117116
labelname.Text = "签名";
@@ -270,10 +269,6 @@ private void button1_Click(object sender, EventArgs e)
270269
{
271270
MessageBox.Show("印章尺寸设置错误,请输入正确的比例或尺寸。");
272271
}
273-
else if(!int.TryParse(textDpi.Text,out dpi))
274-
{
275-
MessageBox.Show("PDF的DPI设置错误,请输入正确的整数。");
276-
}
277272
else if (!int.TryParse(textRotation.Text, out rotation))
278273
{
279274
MessageBox.Show("印章角度设置错误,请输入正确的整数。");
@@ -305,7 +300,6 @@ private void button1_Click(object sender, EventArgs e)
305300
iniFileHelper.WriteIniString(section, "wzType", wzType.ToString());
306301
iniFileHelper.WriteIniString(section, "qbflag", qbflag.ToString());
307302
iniFileHelper.WriteIniString(section, "size", size.ToString());
308-
iniFileHelper.WriteIniString(section, "dpi", dpi.ToString());
309303
iniFileHelper.WriteIniString(section, "rotation", rotation.ToString());
310304
iniFileHelper.WriteIniString(section, "opacity", opacity.ToString());
311305
iniFileHelper.WriteIniString(section, "wz", wz.ToString());
@@ -332,7 +326,7 @@ private void pdfGz()
332326
Directory.CreateDirectory(outputPath);
333327
}
334328

335-
if (log.Text == "提示:建议使用300DPI的印章图片(如40mm的印章,对应的像素为472,计算公式为:40毫米 / 25.4毫米每英寸 * 300 DPI ≈ 472 像素).\r\nPDF文件常见的DPI有72/150/300,如果填写错误会导致盖出来的印章大小跟实际有差异.\r\n使用合并模式会导致文字不可编辑,并且原数字签名丢失.随意骑缝章和自定义加印章共用右边的预览定位,所以同时使用的时候会冲突,建议分开盖章.")
329+
if (log.Text == "提示:建议使用472像素以上且背景透明的印章图片.\r\n使用合并模式会导致文字不可编辑,并且原数字签名丢失.随意骑缝章和自定义加印章共用右边的预览定位,所以同时使用的时候会冲突,建议分开盖章.")
336330
{
337331
log.Text = "";//清空日志
338332
}
@@ -665,7 +659,7 @@ private static Bitmap[] subImages(Bitmap img, int n)//图片分割
665659
private bool PDFWatermark(string inputfilepath, string outputfilepath)
666660
{
667661
//float sfbl = 100f * size * xzbl * 2.842f / imgYz.Height;
668-
float sfbl = (100f * size * xzbl * dpi) / (25.4f * imgYz.Width);
662+
float sfbl = (100f * size * xzbl * 72) / (25.4f * imgYz.Width);
669663

670664
//PdfGState state = new PdfGState();
671665
//state.FillOpacity = 0.01f*opacity;//印章图片不透明度
@@ -1566,9 +1560,8 @@ private void pictureBox1_Click(object sender, EventArgs e)
15661560
dtPos.AcceptChanges();
15671561
}
15681562

1569-
Point pt1 = pictureBox1.Location;
15701563
pictureBox2.Visible = true;
1571-
pictureBox2.Location = new Point(pt1.X + pt.X, pt1.Y + pt.Y);
1564+
pictureBox2.Location = new Point(pt.X, pt.Y);
15721565

15731566
}
15741567
//文件/目录模式切换
@@ -1645,9 +1638,8 @@ public void viewPDFPage()
16451638
}
16461639
int X = Convert.ToInt32((pictureBox1.Width - 2 * yzr) * px);
16471640
int Y = Convert.ToInt32((pictureBox1.Height - 2 * yzr) * py);
1648-
Point pt1 = pictureBox1.Location;
16491641

1650-
pictureBox2.Location = new Point(pt1.X + X, pt1.Y + Y);
1642+
pictureBox2.Location = new Point(X, Y);
16511643

16521644
if (imgStartPage == 1)
16531645
{
@@ -1871,15 +1863,14 @@ private async void comboPDFlist_SelectionChangeCommitted(object sender, EventArg
18711863
imgStartPage = 1;
18721864
imgPageCount = viewPdfFile.PageCount;
18731865
viewPdfimgs = new Bitmap[imgPageCount];
1874-
int dpi = 72;
18751866

18761867
// 根据提供的数字填充 DataTable
18771868
for (int i = 1; i <= imgPageCount; i++)
18781869
{
18791870
dtPages.Rows.Add(new object[] { i, i });
18801871
}
18811872
// 加载第一页
1882-
viewPdfimgs[0] = viewPdfFile.GetPageImage(0, dpi);
1873+
viewPdfimgs[0] = viewPdfFile.GetPageImage(0, 72);
18831874
viewPDFPage();
18841875
// 启动一个任务
18851876
var task = Task.Run(() => LoadPageImagesAsync(viewPdfFile, token));
@@ -1920,7 +1911,7 @@ private void LoadPageImagesAsync(PDFFile viewPdfFile, CancellationToken token)
19201911
// 检查是否被请求取消
19211912
token.ThrowIfCancellationRequested();
19221913

1923-
viewPdfimgs[i] = viewPdfFile.GetPageImage(i, dpi);
1914+
viewPdfimgs[i] = viewPdfFile.GetPageImage(i, 72);
19241915
}
19251916

19261917
viewPdfFile.Dispose();

0 commit comments

Comments
 (0)