2009-10-09 55 views
1

我已被指控爲我的公司在完成特定培訓課程時向客戶打印的證書的功能工作。目前,我們爲他們提供了一個基本的PDF文件,看起來像一般的Joe獎,但我們的許多客戶希望能夠在實際的PDF上添加和重新定位內容並打印出來。我開始使用一種名爲PDFSharp的開源C#代碼解決方案,並發現它有很多很棒的功能,但我不確定如何製作新放置的項目(比如說用戶導入了自己的證書功能區或密封圖形) 。有什麼C#功能我應該看看或任何第三方軟件,將爲我做這一切?在PDF文檔上移動項目

我對任何一條路線都開放。

在此先感謝!

回答

2

我使用Itext

的代碼是Boo,打開「template.pdf」,並繪製一個矩形,並寫上「世界你好」,然後創建一個新的PDF文件並打開它

import iTextSharp.text 
import iTextSharp.text.pdf 
import iTextSharp.text.Color 
import System.IO 
import iTextSharp.text 
import System.Diagnostics 

# we create a reader for a certain document 
reader = PdfReader("template.pdf") 

# we retrieve the size of the first page 
psize = reader.GetPageSize(1); 

# step 1: creation of a document-object 
Document.Compress = true 
documentGlobal = Document(psize, 50, 50, 50, 50) 
# step 2: we create a writer that listens to the document 

thePdfFile = MemoryStream() 
writer = PdfWriter.GetInstance(documentGlobal, thePdfFile) 

documentGlobal.Open() 
cbLocal = writer.DirectContent 

page1 = writer.GetImportedPage(reader, 1) 
cbLocal.AddTemplate(page1, 1f, 0, 0, 1f, 0, 0) 

#Drawing a rectangle 
rec = Rectangle(100, 100, 150, 150) 
rec.BackgroundColor = iTextSharp.text.Color(0,0,0) 
cbLocal.Rectangle(rec); 

#Writing some text 
#There are many ways to write text, check the examples 
bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED) 
font = Font(bf, 10, 0) 
font.SetColor(0, 0, 0) 
ColumnText.ShowTextAligned(cbLocal, 0, Phrase("Hello World", font), 50, 50, 0) 

documentGlobal.Close() 

tempFile = Path.GetTempFileName(); 
ms = MemoryStream(thePdfFile.ToArray()); 
stream = FileStream(tempFile + ".pdf", FileMode.Create); 
ms.WriteTo(stream); 
ms.Close(); 
stream.Close(); 
Process.Start(tempFile + ".pdf"); 

編輯

OOP,看來我不明白的問題....

+0

雖然答案很好= P – ajdams 2009-10-09 15:21:56

0

PDFSharp可以在PDF上創建註釋嗎?我認爲他們可以在Acrobat中移動。

+0

我其實只是迪斯科通過PDF編輯器對象2.6。這個軟件以最簡單的方式做我正在尋找的東西。 – ajdams 2009-10-09 14:58:19