Commit 70dc6fd7 by 施晓雨

导入代码

parent 50479606
namespace Kivii.Pdf.Test
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(895, 619);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Kivii.Pdf.Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
......@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Kivii.Pdf.V4.0, Version=5.5.2020.6200, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Kivii.Pdf.5.5.2020.6200\lib\net40\Kivii.Pdf.V4.0.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -44,16 +47,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="frmMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="frmMain.Designer.cs">
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="frmMain.resx">
<DependentUpon>frmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
......@@ -64,6 +67,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
......@@ -15,7 +15,7 @@ namespace Kivii.Pdf.Test
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new frmMain());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Kivii.Pdf.Test
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void btnSelectFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Pdf文件|*.pdf";
if (ofd.ShowDialog() != DialogResult.OK) return;
tbxPdfFilePath.Text = ofd.FileName;
}
private void btnSelectStamp_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "图片|*.png;*.jpg;*.gif";
if (ofd.ShowDialog() != DialogResult.OK) return;
tbxStampFilePath.Text = ofd.FileName;
}
private void btnSelectPfx_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "数字证书|*.pfx";
if (ofd.ShowDialog() != DialogResult.OK) return;
tbxSignatureFilePath.Text = ofd.FileName;
}
private void btnSelectSaveFilePath_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Pdf文件|*.pdf";
if (sfd.ShowDialog() != DialogResult.OK) return;
tbxSaveFilePath.Text = sfd.FileName;
}
private StampSetting getSetting()
{
try
{
var rtns = new StampSetting();
rtns.StampFilePath = tbxStampFilePath.Text;
rtns.StampWidth = tbxStampWidth.Text;
rtns.Pages = tbxPages.Text;
rtns.OffsetX = tbxOffsetX.Text;
rtns.OffsetY = tbxOffsetY.Text;
rtns.MatchText = tbxMatchText.Text;
rtns.SignatureFilePath = tbxSignatureFilePath.Text;
rtns.SignatureFilePassword = tbxSignatureFilePassword.Text;
rtns.SignatureReason = tbxSignatureReason.Text;
rtns.SignatureLocation = tbxSignatureLocation.Text;
rtns.SignatureTimeStampAuthorityUrl = tbxSignatureTimeStampAuthorityUrl.Text;
rtns.StampType = (StampType)Enum.Parse(typeof(StampType), cbxStampType.Text.Split('-')[0]);
return rtns;
}
catch
{
return null;
}
}
private void btnStamp_Click(object sender, EventArgs e)
{
var setting = getSetting();
if (setting == null)
{
MessageBox.Show("参数设置有误");
return;
}
PdfReader reader = null;
if (tbxPdfFilePath.Text.StartsWith("http", StringComparison.CurrentCultureIgnoreCase))
{
reader = new PdfReader(new Uri(tbxPdfFilePath.Text));
}
else
{
reader = new PdfReader(tbxPdfFilePath.Text);
}
var result=reader.Stamp(setting, tbxSaveFilePath.Text);
reader.Close();
MessageBox.Show($"操作结果:{result}");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Kivii.Pdf" version="5.5.2020.6200" targetFramework="net40" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment