My program use SQlite and iTextsharp.
One button allow the user to create and display a PDF inside a WebBrowser. It works fine the first time, and sometimes more than once, but after a few clicks (every one generating a new version of the PDF with different fonts, sizes...) I get a exception saying the file PDF is allready open. After the exception the program keep running.
I tried with pauses after the click or checking if the file was already open and force the close (The "IsFileOpen" function of this post How to check if the text file is open and close the text file? ), garbage collector, but still the same.
The code looks like this:
Try
Using (conn)
conn.Open()
Dim pdfWrite As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(MyPDFFile, FileMode.Create))
pdfDoc.Open()
'All the code to create the PDF
pdfDoc.Close()
End Using
Catch ex As Exception
'The code to show the exception
End Try
The Debug always point to the line "Dim pdfWrite As PdfWriter", meaning the pdfDOC is still open when the program reaches that line after a few clicks
Sometimes Adobe Reader say error 523:523 but the solution https://forums.adobe.com/thread/961724 " Is the protected mode enabled (Preferences > General > Enable Protected Mode at startup)?" didn't fix the problem
how can I fix that exception?