0
일부 pdf를 병합하려면 날카롭게 사용했습니다. 그 후, 나는 그들을 삭제하고 싶다. 그러나 itextsharp가 파일을 닫지 않으며 File.Delete가 throw되고 예외가 발생합니다.ItextSharp가 모든 파일을 잠급니다.
Dim mergedPdf As Byte() = Nothing
Using ms As New MemoryStream()
Using document As New Document()
Using copy As New PdfCopy(document, ms)
document.Open()
'_listaPath is a List (of String) with the paths off all pdf to merge
For i As Integer = 0 To _listaPDF.Count - 1
Dim reader As New PdfReader(_listaPDF(i))
' loop over the pages in that document
Dim n As Integer = reader.NumberOfPages
Dim page As Integer = 0
While page < n
copy.AddPage(copy.GetImportedPage(reader, System.Threading.Interlocked.Increment(page)))
End While
Next
End Using
End Using
mergedPdf = ms.ToArray()
End Using
File.WriteAllBytes(fileexplorer.FileName, mergedPdf)
For Each pdfTMP In _listaPDF
If File.Exists(pdfTMP) Then
File.Delete(pdfTMP)
End If
Next
_listaPDF = New List(Of String)
이 필요합니다. 스트림을 풀려면 문서를 닫으십시오. 나는 reader.Close()를 어디에도 볼 수 없다. 리더 인스턴스를 닫아 스트림을 릴리스합니다. –
"사용"은 나를 위해 그것을해야합니다. 비록 내 테스트 중 하나, 내가 쓰기 : x.dispose() 및 x.close 모든 "끝 사용"전에. 나는 그 질문의 코드를 업데이트한다. 같은 결과 – Rumpelstinsk