使用iTextSharp讀取PDF文件

2022-08-04 22:15:21 字數 1030 閱讀 8459

網上有很多獲取pdf頁數方法有讀流判斷type/page的但是經過實際測試檔案太大的時候往往不是很準確,既然這樣我們就不用費心去自己寫了可以用itextsharp。

(1)建立乙個windows控制台應用程式,命名為readpdfdemo。

(2)新增對itextsharp的引用。

(3)在「program.cs」檔案中新增如下引用。

using system;

using system.io;

using itextsharp.text;

using itextsharp.text.pdf;

(4)直接修改「program.cs」檔案的**如下。

namespace readpdfdemo

if (i < n)

if (i < n)

cb.setrgbcolorstroke(255, 0, 0);

cb.moveto(0, height / 2);

cb.lineto(width, height / 2);

cb.stroke();

cb.moveto(width / 2, height);

cb.lineto(width / 2, 0);

cb.stroke();

basefont bf = basefont.createfont(basefont.helvetica, basefont.cp1252, basefont.not_embedded);

cb.begintext();

cb.setfontandsize(bf, 14);

cb.showtextaligned(pdfcontentbyte.align_center,

"page " + p + " of " + ((n / 4) + (n % 4 > 0 ? 1 : 0)), width / 2,

40, 0);

cb.endtext();

}// 關閉文件

document.close();

}catch (exception de)}}

}

c 使用itextsharp的例項

在程式設計中用到將一些報告生成pdf檔案,用到了itextsharp版本是4.1.2.0和最新的版本的某些函式有出入 document doc new document pagesize.a4,100,100,80,80 文件a4樣式,左右頁邊距100,上下80pdfwriter.getinstan...

使用iTextSharp中文無顯示

itextsharp匯出pdf遇到問題中文無顯示!一開始老是少幾個顯示不完整,一直找 問題 最後才注意到中文無顯示!需要像這樣 指定字型庫,並建立字型 basefont basefont basefont.createfont c windows fonts stsong.ttf basefont....

VS2008 使用itextsharp生成PDF

廢話不多說,上圖先。要用本文的方法生成pdf檔案,需要兩個控制項 itextsharp.dll和icsharpcode.sharpziplib.dll,由於示例 實在太多,我將 全部整理出來.利用itext五步建立乙個pdf檔案 helloword。第一步,建立乙個 itextsharp.text....