http://www.ujihara.jp/iTextdotNET/en/“rel=“nofollow noreferer”>
该守则载于Boo。 开放式“template.pdf”并引出一个 rec形和书写的“hello world”,然后创建新的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");
<><>Edit>/strong>
Oop, 我似乎不理解这个问题。