开发者

Moving Items on a PDF Document

I have been charged with working on a feature for certificates my company prints out for clients when they completing specific training course. Currently we provide them with a basic PDF file that looks like the average Joe award but many of our customers want to be able to add and reposition content on the actual PDF and then print them. I began using an open source C# .NET code solution called PDFSharp and found that had a lot of great features but I am unsure as to how I would make new开发者_如何转开发ly placed items (let's say a user imported their own certificate ribbon or seal graphic) movable. Is there any C# features I should take a look at or any third-party software that will do all of this for me?

I am open to either route.

Thanks in advance!


I'm using Itext

The code is in Boo, Opens "template.pdf" and draw a rectangle and write "hello world" then create a new pdf file and open it

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");

Edit

Oop, It seems I did not understand the question....


Can PDFSharp create annotations on the PDF? I think that they would then be movable in Acrobat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜