I am trying to read a string using PDF.Here i have a code which while running giving me error ..
Can not acess a closed file error in Itextsharp
I am not getting why is this error coming.My code is in VB and i am for the first time working with VB and Itext both so having the problem.Here is my code..
Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing
Dim cb As iTextSharp.text.pdf.PdfContentByte = Nothing
Me.Cursor = Cursors.WaitCursor
If File.Exists(SourceFile) Then
Dim pReader As New PdfReader(SourceFile)
stamper = New iTextSharp.text.pdf.PdfStamper(pReader, New FileStream(DestinationFile, FileMode.Create))
PB.Value = 0 : PB.Maximum = pReader.NumberOfPages
For page As Integer = 1 To pReader.NumberOfPages
Dim strategy As myLocationTextExtractionStrategy = New myLocationTextExtractionStrategy
cb = stamper.GetUnderContent(page)
'Send some data contained in PdfContentByte, looks like the first is always cero for me and the second 100, but i'm not sure if this could change in some cases
strategy.UndercontentCharacterSpacing = cb.CharacterSpacing
strategy.UndercontentHorizontalScaling = cb.HorizontalScaling
'It's not really needed to get the text back, but we have to call this line ALWAYS,
'because it triggers the process that will get all chunks from PDF into our strategy Object
Dim currentText As String = PdfTextExtractor.GetTextFromPage(pReader, page, strategy)
I am getting the error at the last line of the code..
Dim currentText As String = PdfTextExtractor.GetTextFromPage(pReader, page, strategy)
Code that is required as per comment
Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
'Parameter1: Search Text (1 word or many)
'Parameter2: Case Sensitiveness
'Parameter3: Source file with Path
'Parameter4: Destination File with Path
PDFTextGetter("Hello", StringComparison.CurrentCultureIgnoreCase, "D:\\pdf\\18.pdf", "D:\\Bill\\Test.pdf")
End Sub
Please help me .Thanks a lot!