close

1.前言:
sharpPDF是一個LGPLv2 license的開放原始碼的函式庫,可用來產生PDF格式的檔案。

2.說明:
sharpPDF是一個產生PDF檔案的元件,其優點是使用簡單,可以快速地整合到自己的專案中。

sharpPDF的說明可參考:
http://sharppdf.sourceforge.net/index.html

sharpPDF軟體下載網址:
http://sourceforge.net/projects/sharppdf/

本範例使用版本為sharpPDF_2_0_Beta2
軟體解壓縮後,將\sharpPDF_2_0_Beta2_dll\sharpPDF.dll的DLL檔複製到自己專案的bin目錄下

加入參考: sharpPDF.dll
加入命名空間:

using sharpPDF;
using sharpPDF.Fonts;
using sharpPDF.Elements;
using sharpPDF.Enumerators;

程式碼:

//範例一: 簡單的Hello World文件
string title = "Tutorial-Hello World!";//文件標題
string author = "einboch";//文件作者
pdfDocument myDoc = new pdfDocument(title, author);
pdfPage myPage = myDoc.addPage();//新增頁面
myPage.addText("Hello World!", 250, 650, myDoc.getFontReference("Courier"), 20);//座標系統左下為原點
myDoc.createPDF(@"d:\tmp\test.pdf");//產生PDF檔案
//清空資源
myPage = null;
myDoc = null;

//範例二: 將圖檔加入到PDF
string title = "Tutorial-Add image files";//文件標題
string author = "einboch";//文件作者
pdfDocument myDoc = new pdfDocument(title, author);
myDoc.addImageReference(@"d:\tmp\pic4.jpeg", "pic4");//加入影像檔參考
pdfPage myPage = myDoc.addPage();//新增頁面
myPage.addImage(myDoc.getImageReference("pic4"), 50, 300, 400, 500);//加入影像到頁面
myDoc.createPDF(@"d:\tmp\test.pdf");//產生PDF檔案
//清空資源
myPage = null;
myDoc = null;

圖例:

sharppdf  

arrow
arrow
    文章標籤
    C# sharpPDF PDF
    全站熱搜

    西夏普 發表在 痞客邦 留言(0) 人氣()