1
Answer

iTextSharp pdf stamping use for text on pdf

Gopal Mahale

Gopal Mahale

7y
415
1
DearTeam,
I am facing issue for iTextSharp pdf stamping. once stamping on any pdf, pdf file gets locked and unable to select any text appear on pdf. only added text allow to select..
So please help me for how i can able to select all data after stamping on pdf. 
 I write below function i am using for this 
 
Public Function RSNStampingPDF(ByVal oldFile As String, ByVal newFile As String, ByVal RSN As String) As Boolean
Try
      'create PdfReader object to read from the existing document
      Using reader As New PdfReader(oldFile)
      'create PdfStamper object to write to get the pages from reader
      Using stamper As New PdfStamper(reader, New FileStream(newFile, FileMode.Create))
      'select two pages from the original document
      ' reader.SelectPages("1-2")
      'gettins the page size in order to substract from the iTextSharp coordinates
      Dim pageSize = reader.GetPageSize(1)
 
      ' PdfContentByte from stamper to add content to the pages over the original content
      Dim pbover As PdfContentByte = stamper.GetOverContent(1)
 
   'add content to the page using ColumnText
      Dim font As New Font()
   font.Size = 20
 
   ' Set Red color for entered text
      font.SetColor(255, 0, 0)
'   setting up the X and Y coordinates of the document
Dim x As Integer = pageSize.Width
Dim y As Integer = pageSize.Height
 
      If x > 839 And y > 592 Then
             x = CInt(pageSize.Width - 300)
            y = CInt(pageSize.Height)
         Else
            x = CInt(pageSize.Width - 130)
            y = CInt(pageSize.Height - 30)
      End If   
         ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, New Phrase(RSN, font),          x,  y,    0)
      End Using
   End Using
   Return True
Catch ex As Exception
Return False
End Try
End Function
 
Answers (1)