close

1.前言:
PDF Clown是一個LGPLv3 license的開放原始碼的函式庫,可用來產生PDF格式的檔案,由C#/.NET 4.0開發而成。

2.說明:
PDF Clown是另一款產生PDF檔案的函式庫,主要的功能除了產生PDF檔案,還可以讀取和編輯既有的PDF文件,對於影像格式的處理,目前僅支援JPEG的格式,另外要使用.NET 3.5來開發專案,需下載使用PDFClown-0.1.1-Beta的版本。

PDFsharp的說明可參考:
http://www.stefanochizzolini.it/en/projects/clown/

PDFsharp軟體下載網址:
http://sourceforge.net/projects/clown/

本範例使用版本為PDFClown-0.1.2-Beta
軟體解壓縮後,將\PDFClown-0.1.2-Beta\PDFClown\dotNET\pdfclown.lib\build\package\PDFClown.dll的DLL檔複製到自己專案的bin目錄下

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

using org.pdfclown.documents;
using org.pdfclown.documents.contents;
using org.pdfclown.documents.contents.fonts;
using org.pdfclown.documents.contents.xObjects;
using org.pdfclown.documents.contents.entities;
using org.pdfclown.documents.contents.composition;
using org.pdfclown.bytes;
using org.pdfclown.files;
using org.pdfclown.objects;

程式碼:

//範例一: 簡單的Hello World文件
File file = new File();
Document myDoc = file.Document;
myDoc.Information.Title = "Tutorial-Hello World!";//文件標題
myDoc.Information.Author = "einboch";//文件作者
Page myPage = new Page(myDoc);
myDoc.Pages.Add(myPage);//新增頁面
PrimitiveComposer pc = new PrimitiveComposer(myPage);
pc.SetFont(new StandardType1Font(myDoc, StandardType1Font.FamilyEnum.Courier, true, false), 32);
pc.ShowText("Hello World!", new PointF(32,48));
pc.Flush();
file.Save(@"d:\tmp\test.pdf", SerializationModeEnum.Standard);//產生PDF檔案

//範例二: 將圖檔加入到PDF
File file = new File();
Document myDoc = file.Document;
myDoc.Information.Title = "Tutorial-Add image files";//文件標題
myDoc.Information.Author = "einboch";//文件作者
Page myPage = new Page(myDoc);
myDoc.Pages.Add(myPage);//新增頁面
PrimitiveComposer pc = new PrimitiveComposer(myPage);
org.pdfclown.documents.contents.entities.Image image = org.pdfclown.documents.contents.entities.Image.Get(@"d:\tmp\pic6.jpeg");
XObject imageXObject = image.ToXObject(myDoc);//加入影像到頁面
pc.ShowXObject(imageXObject, new Point(20,20));
pc.Flush();
file.Save(@"d:\tmp\test.pdf", SerializationModeEnum.Standard);//產生PDF檔案

圖例:

pdfclown  

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

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