The process that I am using to merge documents used to work perfectly fine. But after I updated the package to the latest version, I seem to be getting this same error with all my pdf documents. When I go to delete the temporary files that were used to merge into 1 file, I cannot. It throws an exception and tells me that the file is still being used. Any help would be great. My code for this process is as follows:
- Code: Select all
'Merges PDFs
Dim OutputFile As String = FileName
Using doc As Spire.Pdf.PdfDocumentBase = Spire.Pdf.PdfDocument.MergeFiles(array)
doc.Save(OutputFile, FileFormat.PDF)
End Using
I have also tried using doc.close() and doc.dispose() to no luck
I can provide more info as it is needed. Thanks!
EDIT:
I have come up with quite a janky solution but also one that I would rather not have. The reason I updated to the latest version to begin with is because Spire was creating blank pages when merging pdfs. There really was not any rhyme or reason for it too. So I updated. Fixed the issue of the blank doc but gave me the new issue shown above. It will generate the merged pdf perfectly but will not allow for the temp files to be deleted.
The way I circumvented the issue for now is if the array has only one file in it (basically if there is only one pdf to merge) Rename it and move it to the proper destination.
It looks like this:
- Code: Select all
Sub MergeEverythingSpire(filename As String, Folder As String, Array As String())
Try 'merges all files in passed folder path into one file using pdfsharp
If Array.Count = 1 Then
File.Move(Directory.GetFiles(ConversionFolder).First, filename)
Else
Dim OutputFile As String = filename
Using docFinal As Spire.Pdf.PdfDocumentBase = Spire.Pdf.PdfDocument.MergeFiles(Array)
Threading.Thread.Sleep(5000)
docFinal.Save(OutputFile, Spire.Pdf.FileFormat.PDF)
End Using
End If
Catch ex As System.Exception
End Try
End Sub
So now I resolved one problem by creating another. The temp files are able to be deleted but as a result my merged pdf is missing pages.
Is there a specific version that addresses these issues or am I doing something wrong? I would appreciate any input on this.
Thanks!