資源簡介
獲取PDF文件中指定關鍵字的坐標,可用于對指定位置進行自動蓋章和簽字使用,附帶源碼
代碼片段和文件信息
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??pdf\pdf\
?????目錄???????????0??2018-10-24?14:30??pdf\pdf\.vs\
?????目錄???????????0??2018-10-24?14:30??pdf\pdf\.vs\pdf\
?????目錄???????????0??2018-10-24?14:30??pdf\pdf\.vs\pdf\v14\
?????文件???????23552??2018-10-24?14:30??pdf\pdf\.vs\pdf\v14\.suo
?????目錄???????????0??2018-10-24?14:38??pdf\pdf\pdf\
?????文件?????????189??2018-10-24?14:30??pdf\pdf\pdf\App.config
?????文件????????2023??2018-10-24?14:35??pdf\pdf\pdf\Form1.Designer.cs
?????文件????????5594??2018-10-24?14:38??pdf\pdf\pdf\Form1.cs
?????文件????????5817??2018-10-24?14:35??pdf\pdf\pdf\Form1.resx
?????文件?????????515??2018-10-24?14:30??pdf\pdf\pdf\Program.cs
?????目錄???????????0??2018-10-24?14:30??pdf\pdf\pdf\Properties\
?????文件????????1332??2018-10-24?14:30??pdf\pdf\pdf\Properties\AssemblyInfo.cs
?????文件????????2819??2018-10-24?14:30??pdf\pdf\pdf\Properties\Resources.Designer.cs
?????文件????????5612??2018-10-24?14:30??pdf\pdf\pdf\Properties\Resources.resx
?????文件????????1090??2018-10-24?14:30??pdf\pdf\pdf\Properties\Settings.Designer.cs
?????文件?????????249??2018-10-24?14:30??pdf\pdf\pdf\Properties\Settings.settings
?????目錄???????????0??2018-10-24?14:30??pdf\pdf\pdf\bin\
?????目錄???????????0??2018-10-24?14:38??pdf\pdf\pdf\bin\Debug\
?????文件?????8022976??2012-07-26?19:08??pdf\pdf\pdf\bin\Debug\Microsoft.mshtml.dll
?????文件???????55808??2015-04-28?11:55??pdf\pdf\pdf\bin\Debug\Spire.License.dll
?????文件????15364096??2016-11-10?16:37??pdf\pdf\pdf\bin\Debug\Spire.Pdf.dll
?????文件????19218432??2016-11-10?16:37??pdf\pdf\pdf\bin\Debug\Spire.XLS.dll
?????文件?????4055040??2018-10-10?19:29??pdf\pdf\pdf\bin\Debug\itextsharp.dll
?????文件???????10240??2018-10-24?14:38??pdf\pdf\pdf\bin\Debug\pdf.exe
?????文件?????????189??2018-10-24?14:30??pdf\pdf\pdf\bin\Debug\pdf.exe.config
?????文件???????22016??2018-10-24?14:38??pdf\pdf\pdf\bin\Debug\pdf.pdb
?????文件???????22696??2018-10-24?14:31??pdf\pdf\pdf\bin\Debug\pdf.vshost.exe
?????文件?????????189??2018-10-24?14:30??pdf\pdf\pdf\bin\Debug\pdf.vshost.exe.config
?????文件?????????490??2012-06-06?02:06??pdf\pdf\pdf\bin\Debug\pdf.vshost.exe.manifest
............此處省略22個文件信息
評論
共有 條評論