asp.net - How can I add an image as a pdf header? -


i using code below generate pdf. there way can point image , use header? "~/images/header.png"? appreciated. thank you.

dim myuniquefilename = string.format("{0}.pdf", random)     dim pdfwrite pdfwriter = pdfwriter.getinstance(doc1, new filestream(path & myuniquefilename, filemode.create))     dim ev new itsevents     pdfwrite.pageevent = ev      doc1.open()     dim test string     test = session("pdf")     doc1.add(new paragraph(test))      doc1.close() end sub public class itsevents     inherits pdfpageeventhelper     public overrides sub onstartpage(byval writer itextsharp.text.pdf.pdfwriter, byval document itextsharp.text.document)         dim ch new chunk("this header on page " & writer.pagenumber)         document.add(ch)     end sub end class 

try this:

dim imagepath string = server.mappath(".") & "/logo/anjanlogo.jpg" dim image itextsharp.text.image = itextsharp.text.image.getinstance(imagepath) image.scalepercent(24f) doc.add(image) 

note: 24f scaling comes fact that, default, embedded images 72 dpi , commercial printers use 300 dpi, 72/300 * 100 = 24%.

to move image around page can use setabsoluteposition method, this:

image.setabsoluteposition(36f, 36f) 

note: 36f margin of pdf, push logo top left of corner of pdf, still maintain border.


Comments