0% found this document useful (1 vote)
2K views

Write Text To PDF With Itextsharp in

The document discusses how to write text to an existing PDF file using iTextSharp in VB.NET. It provides code to open an existing PDF file, create a PdfStamper object, get the content byte object, set font properties, write text to the PDF, add the text to a new page, close the objects, and save the file with a new name.

Uploaded by

cafjnk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views

Write Text To PDF With Itextsharp in

The document discusses how to write text to an existing PDF file using iTextSharp in VB.NET. It provides code to open an existing PDF file, create a PdfStamper object, get the content byte object, set font properties, write text to the PDF, add the text to a new page, close the objects, and save the file with a new name.

Uploaded by

cafjnk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

write text to pdf with itextsharp in vb.

net - Stack Overflow

http://stackoverflow.com/questions/18 !8888/write-text...

sign up

log in

tour

help

careers 2.0

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

write text to pdf with itextsharp in vb.net

I have a sub in vb.net like: Public Shared f_cb As BaseFont = BaseFont.CreateFont(Directory.GetCurrentDirectory() + Public Shared f_cn As BaseFont = BaseFont.CreateFont(Directory.GetCurrentDirectory()

Public Shared Sub GenPDF() Try Using fs As System.IO.FileStream = New FileStream(Directory.GetCurrentDirectory() + Dim document As New Document(PageSize.A4, 25, 25, 30, 1) Dim writer As Pdf riter = Pdf riter.Get!nstance(document, fs) document.AddTitle( test ) document."#en() Dim cb As PdfContentByte = writer.DirectContent Dim !n" As i#e$t%&'r!.te$t.!mage = i#e$t%&'r!.te$t.!mage.Get!nstance(Current !n".ScaleAbsolute((5, 52) !n".SetAbsolutePosition(40, ((0) cb.Add!mage(!n") cb.BeginTe$t() Dim )eft_m'r"in As !nteger = 40 Dim to!_m'r"in As !nteger = (50 write(cb, %treets %.*.+. , )eft_m'r"in, to!_m'r"in, f_cb, 10) write(cb, A,. -00, ..A./.A. (1001), 0eru , )eft_m'r"in, to!_m'r"in 1 12 write(cb, #e)2 43001214( 1 3'$2 430012144 , )eft_m'r"in, to!_m'r"in 1 write(cb, ..5.I.#. 2013060222(10 , )eft_m'r"in, to!_m'r"in 1 36, f_cn, write(cb, I.7.A. , )eft_m'r"in, to!_m'r"in 1 44, f_cn, 10) cb.%ndTe$t() document.Close() writer.Close() fs.Close() %nd Using Catch e$ As %$ce#tion Throw e$ %nd Try %nd Sub So it works ok, now I would like to write to an already created pdf, but I can not find analog for vb.net I was trying pdfStamper but had no succes, How does the code to append data to pdf using itextsharp in vb.net look like?
vb.net pdf itextsharp vb.net-2010

asked Sep 6 '13 at 2:22 cMinor 5,891 14 86 191

1 Answer
Here is an example of writing text to an existing PDF file and then saving it with a new name:

1 of "

"/1#/"$1! 1$:"! %&

write text to pdf with itextsharp in vb.net - Stack Overflow

http://stackoverflow.com/questions/18 !8888/write-text...

Dim o)d3i)e As String = Dim new3i)e As String =

%ome0't&89$istin".!df %ome0't&8:ew.!df

; .re'te re'der <im re'der As :ew 0df*e'der(o)d3i)e) <im si=e As *ect'n")e = re'der.>et0'"e%i=e?it&*ot'tion(1) <im document As :ew <ocument(si=e) ; Create t&e writer Dim fs As New FileStream(new3i)e, File&ode.Create, FileAccess. rite) Dim writer As Pdf riter = Pdf riter.Get!nstance(document, fs) document."#en() Dim cb As PdfContentByte = writer.DirectContent ; %et t&e font, co)or 'nd si=e !ro!erties for writin" te$t to t&e 0<3 <im bf As /'se3ont = /'se3ont..re'te3ont(/'se3ont.@9+79#I.A, /'se3ont..01252, /'se3ont.:O#_9A/9<<9<) cb.%et.o)or3i))(/'se.o)or.<A*B_>*AC) cb.%et3ontAnd%i=e(bf, 4) ; rite te$t in t&e 0<3 cb.BeginTe$t() Dim te$t As String = %ome te$t &ere ; %et t&e ')i"nment 'nd coordin'tes &ere cb.%&ow#e$tA)i"ned(1, te$t, 520, 640, 0) cb.9nd#e$t() ; Put t&e te$t on ' new !'"e in t&e 0<3 Dim !'"e As Pdf!m#ortedPage = writer.Get!m#ortedPage(re'der, 1) cb.AddTem#late(!'"e, 0, 0) ; .)ose t&e obDects document..)ose() fs..)ose()
answered Sep 6 '13 at 2:35 Karl Anderson 20.7k 6 14 33 @cMinor While doing it like this certainly is a solution, it is not necessarily the best one. Adding templates generated by 0df?riter.>etIm!orted0'"e makes you a) lose all page annotations (e.g. form elements) and b) wraps the whole page in a xobject. Whether either is a show stopper, depends on the requirements and use case. Generally a better approach is to use a 0df%t'm!er which can also add page content by means of its O,er.ontent and 5nder.ontent . mkl Sep 8 '13 at 6:26

Not the answer you're looking for? Browse other questions tagged vb.net pdf
itextsharp vb.net- !1! or ask your own question.

" of "

"/1#/"$1! 1$:"! %&

You might also like