Sub AddTextandImagetopdf()
Private box As PDFBox
box.Initialize("",File.Combine(File.DirData("PDFBox"),"acroformtest.pdf")) ' PDF to start with
Dim r As PDRectangle
Dim hlp As FontandColorHelper
Dim doc As PDDocument = box.Document ' Get Document from PDF
Dim cat As PDDocumentCatalog = doc.DocumentCatalog ' Get DocumentCatalog
Dim p1 As PDPage = doc.GetPage(0) ' Get Page1
Dim acroform As PDAcroForm = cat.AcroForm ' Get Acroform
Dim res As PDResources
If acroform.DefaultResources <> Null Then
res = acroform.DefaultResources
Else
res.Initialize
res.putFont(hlp.COURIER,"Cour")
acroform.DefaultResources = res
End If
Dim contentStream As PDPageContentStream ' Create a PageContentStream
contentStream.Initialize("",doc,p1,"APPEND",False,False) ' Initialize it with Document and Page
contentStream.beginText()
contentStream.setFont(hlp.COURIER,20) ' needed before writing Text
contentStream.setNonStrokingColor(0,50,150)
contentStream.setStrokingColor(60,100,150)
contentStream.newLineAtOffset(60, 720) ' Position of "next Text" to add
contentStream.showText("Bla bla bla bla bla ;-)") ' Output the Text
contentStream.endText()
contentStream.addLine(60,715,330,715) ' Create a Line under the text
contentStream.closeAndStroke
Dim img As PDImageXObject ' Create PDImageXObject which holds an Image to add to the PDF
img.Initialize(doc,"d:\\donmanfred_avatar.bmp") ' The Image
contentStream.drawImage2(img,435,435,64,64) ' Draw Image on Page at x/y=435 with a size of 64x64
contentStream.close() ' Close the ContentStream
doc.save("d:/sample.pdf") ' Save PDF to Disc
doc.close() ' Close PDF
End Sub