获取pdf文件中指定文字的坐标
获取PDF文件中指定关键字的坐标,可用于对指定位置进行自动盖章和签字使用,附带源码
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-24 14:30 pdf
目录 0 2018-10-24 14:30 pdfpdf
目录 0 2018-10-24 14:30 pdfpdf.vs
目录 0 2018-10-24 14:30 pdfpdf.vspdf
目录 0 2018-10-24 14:30 pdfpdf.vspdfv14
文件 23552 2018-10-24 14:30 pdfpdf.vspdfv14.suo
目录 0 2018-10-24 14:38 pdfpdfpdf
文件 189 2018-10-24 14:30 pdfpdfpdfApp.config
文件 2023 2018-10-24 14:35 pdfpdfpdfForm1.Designer.cs
文件 5594 2018-10-24 14:38 pdfpdfpdfForm1.cs
文件 5817 2018-10-24 14:35 pdfpdfpdfForm1.resx
文件 515 2018-10-24 14:30 pdfpdfpdfProgram.cs
目录 0 2018-10-24 14:30 pdfpdfpdfProperties
文件 1332 2018-10-24 14:30 pdfpdfpdfPropertiesAssemblyInfo.cs
文件 2819 2018-10-24 14:30 pdfpdfpdfPropertiesResources.Designer.cs
文件 5612 2018-10-24 14:30 pdfpdfpdfPropertiesResources.resx
文件 1090 2018-10-24 14:30 pdfpdfpdfPropertiesSettings.Designer.cs
文件 249 2018-10-24 14:30 pdfpdfpdfPropertiesSettings.settings
目录 0 2018-10-24 14:30 pdfpdfpdfin
目录 0 2018-10-24 14:38 pdfpdfpdfinDebug
文件 8022976 2012-07-26 19:08 pdfpdfpdfinDebugMicrosoft.mshtml.dll
文件 55808 2015-04-28 11:55 pdfpdfpdfinDebugSpire.License.dll
文件 15364096 2016-11-10 16:37 pdfpdfpdfinDebugSpire.Pdf.dll
文件 19218432 2016-11-10 16:37 pdfpdfpdfinDebugSpire.XLS.dll
文件 4055040 2018-10-10 19:29 pdfpdfpdfinDebugitextsharp.dll
文件 10240 2018-10-24 14:38 pdfpdfpdfinDebugpdf.exe
文件 189 2018-10-24 14:30 pdfpdfpdfinDebugpdf.exe.config
文件 22016 2018-10-24 14:38 pdfpdfpdfinDebugpdf.pdb
文件 22696 2018-10-24 14:31 pdfpdfpdfinDebugpdf.vshost.exe
文件 189 2018-10-24 14:30 pdfpdfpdfinDebugpdf.vshost.exe.config
文件 490 2012-06-06 02:06 pdfpdfpdfinDebugpdf.vshost.exe.manifest
............此处省略22个文件信息
using iTextSharp.text.pdf;
using Spire.Pdf;
using Spire.Pdf.General.Find;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace pdf
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
///
/// 获取签名位置
///
/// 文件路径
/// 文件名称
/// 要识别的签名关键字
/// out pdf页数
/// out 签名left(距离左边边距距离)
/// out 签名top(距离上边边距距离)
/// out 当前页宽度
/// out 当前页高度
///
public bool GetLocation(string _path string _filename string Keywords out int _pageindex out float _width out float _height out float _pagewidth out float _pageheight)
{
if (!File.Exists(_path + _filename))
{
_pageindex = 0;
_width = 0;
_height = 0;
_pagewidth = 0;
_pageheight = 0;
return false;
}
#region 新建临时pdf
PdfReader pdfReader = null;
iTextSharp.text.Document document = null;
PdfWriter writer = null;
string temppath = _path + “temp_“ + _filename;
try
{
pdfReader = new PdfReader(_path + _filename);
document = new iTextSharp.text.Document(pdfReader.GetPageSize(1));
File.Delete(temppath);
writer = PdfWriter.GetInstance(document new FileStream(temppath FileMode.Create));
document.Open();
_pageindex = pdfReader.NumberOfPages;
PdfContentByte cb = writer.DirectContent;
document.NewPage();
PdfImportedPage newPage = writer.GetImportedPage(pdfReader _pageindex - 1);
cb.AddTemplate(newPage 0 0);
document.NewPage();
newPage = writer.GetImportedPage(pdfReader _pageindex);
cb.AddTemplate(newPage 0 0);
document.Close();
}
catch (Exception ex)
{
if (document != null)
document.Close();
_pageindex = 0;
_width = 0;
_height = 0;
_pagewidth = 0;
_pageheight = 0;
File.Delete(temppath);
return false;
}
#endregion
#region 获取签字位置
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-24 14:30 pdf
目录 0 2018-10-24 14:30 pdfpdf
目录 0 2018-10-24 14:30 pdfpdf.vs
目录 0 2018-10-24 14:30 pdfpdf.vspdf
目录 0 2018-10-24 14:30 pdfpdf.vspdfv14
文件 23552 2018-10-24 14:30 pdfpdf.vspdfv14.suo
目录 0 2018-10-24 14:38 pdfpdfpdf
文件 189 2018-10-24 14:30 pdfpdfpdfApp.config
文件 2023 2018-10-24 14:35 pdfpdfpdfForm1.Designer.cs
文件 5594 2018-10-24 14:38 pdfpdfpdfForm1.cs
文件 5817 2018-10-24 14:35 pdfpdfpdfForm1.resx
文件 515 2018-10-24 14:30 pdfpdfpdfProgram.cs
目录 0 2018-10-24 14:30 pdfpdfpdfProperties
文件 1332 2018-10-24 14:30 pdfpdfpdfPropertiesAssemblyInfo.cs
文件 2819 2018-10-24 14:30 pdfpdfpdfPropertiesResources.Designer.cs
文件 5612 2018-10-24 14:30 pdfpdfpdfPropertiesResources.resx
文件 1090 2018-10-24 14:30 pdfpdfpdfPropertiesSettings.Designer.cs
文件 249 2018-10-24 14:30 pdfpdfpdfPropertiesSettings.settings
目录 0 2018-10-24 14:30 pdfpdfpdfin
目录 0 2018-10-24 14:38 pdfpdfpdfinDebug
文件 8022976 2012-07-26 19:08 pdfpdfpdfinDebugMicrosoft.mshtml.dll
文件 55808 2015-04-28 11:55 pdfpdfpdfinDebugSpire.License.dll
文件 15364096 2016-11-10 16:37 pdfpdfpdfinDebugSpire.Pdf.dll
文件 19218432 2016-11-10 16:37 pdfpdfpdfinDebugSpire.XLS.dll
文件 4055040 2018-10-10 19:29 pdfpdfpdfinDebugitextsharp.dll
文件 10240 2018-10-24 14:38 pdfpdfpdfinDebugpdf.exe
文件 189 2018-10-24 14:30 pdfpdfpdfinDebugpdf.exe.config
文件 22016 2018-10-24 14:38 pdfpdfpdfinDebugpdf.pdb
文件 22696 2018-10-24 14:31 pdfpdfpdfinDebugpdf.vshost.exe
文件 189 2018-10-24 14:30 pdfpdfpdfinDebugpdf.vshost.exe.config
文件 490 2012-06-06 02:06 pdfpdfpdfinDebugpdf.vshost.exe.manifest
............此处省略22个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)