Free Support Forum - aspose.com

Bug report : PdfFileEditor.Concatenate And/Or PdfFileEditor.Extract and temp files

Hi,

We’ve been encountering issues with those methods that we really had troubles to diagnostic and I think there’s a few thing you should that could prevent some of your users huge troubles.

When using PdfFileEditor.Concatenate And/Or PdfFileEditor.Extract some temp files are generated using System.IO.Path.GetTempFileName()
1 - That method has limitations : when more than a certain number of temp files already exist in Windows temp folder, this method fails (http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename.aspx) “The GetTempFileName method
will raise an IOException
if it is used to create more than 65535 files without deleting previous
temporary files.”.
When this happens an exception is raised in pdf kit saying “invalid pdf header” which is wrong, and the real exception is not shown in the raised exception’s stack.
2 - Those temp files are never deleted

Could you please fix those troubles in a later version ?
Thank you

Hi Pierre,

According to our observation such an issue occurs when the PDF file is not in proper format. Are you sure the files you’re trying to process are correct? Are they opening properly with other tools i…e Adobe Reader etc. If these input files are fine and you’re still having this trouble then please share the sample input PDF files along with your complete code snippet which can help us reproduce the same issue at our end. A small sample application along with the details of your working environment (OS, CPU, RAM etc.) would be helpful. We’ll investigate it in detail and update you with the fix or guidelines accordingly.

We’re sorry for the inconvenience and looking forward to help you out.
Regards,

Hi Shahzad,

And thank you your quick response.
Absolutely, the files are perfect. In fact our test was to take a PDF, split it using only PdfFileEditor.Extract and then rejoining it using PdfFileEditor.Concatenate.

We were saving resulting pdf to intermediates files.
After all the Extract calls, on the first concatenate, the error appeared.
We tryed to open each pdf using acrobat and no problem !

Then we took our little test software and used it on a exactly equivalent environment, but this time no errors.

Finally we discovered that when removing all the “tmp*” files from C:\Windows\Temp, then our problem was fixed.

OS : Windows Server 2003 32 bits.
CPU : Xeon 3GHZ
RAM : 6 Gbs
Disk size : 750 Gbs

Hi Pierre,

I have tried to test the issue at my end using your particular scenario, however I’m unable to reproduce this issue. I couldn’t see any temporary files being placed in the temp folder by Aspose.Pdf.Kit during the process, however I added some temp files manually to make it more than 70000 files in the temp folder; even then I was unable to reproduce this issue.

Could you please share a small sample application along with the sample input file(s) which can help us reproduce the same issue at our end? I would like to add that it is very important for our team to reproduce the same issue over here in order to understand and then resolve it.

We’re sorry for the inconvenience and appreciate your cooperation.
Regards,

Hi Shahzad,

The sample we used to reproduce the issue was this :

Sub Main()
Dim o
PdfFileEditor As New Aspose.Pdf.Kit.PdfFileEditor()
While (True)
oPdfFileEditor.Concatenate(“C:\a.pdf”, “C:\a.pdf”, “C:\tmp” & Guid.NewGuid().ToString() & “.pdf”)
End While
End Sub


But I’m unable to reproduce it now, and since it was on a production server, I don’t want to touch it.
It doesn’t matter anyway, we cleared the temp folder and added a plannified task to clear temp files if they would keep appearing.

I don’t want to spend too much time on this, if you confirm that no temp files are created even really quickly, then my diagnostic must be wrong, just close that issue saying “can’t reproduce” or something like this.

Thank you for trying anyway !

Hi Pierre,

This is good to know that this issue is not occurring anymore at your end. However, if you again face any such issue, kindly share the problematic PDF file along with the stacktrace so we could further investigate it.

Regards,

Hi,

The problem still occurs:

I concatenate 12 files in the c:\windows\temp\tempfoldername:

Dim files() As String = System.IO.Directory.GetFiles(path)
Dim inStreams(files.Length - 1) As System.IO.MemoryStream
Dim teller As Integer = 0
For Each File As String In files
Dim fs1 As New FileStream(File, FileMode.Open, FileAccess.Read)
Dim buffer1 As Byte() = New Byte(Convert.ToInt32(fs1.Length) - 1) {}
fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length))
inStreams(teller) = New System.IO.MemoryStream(buffer1)
fs1.Close()
teller += 1
Next

' below is where the temp file is created and never deleted.
pdfEditor.Concatenate(inStreams, pdfStream)

Hi,

Please share the input PDF files with us along with a sample project which can help us reproduce the same issue at our end. Also, please share the details regarding your working environment: OS, .NET Framework version, Desktop or Web application, and how the application is set up at your end etc. We’ll investigate the issue at our end and guide you accordingly.

We’re sorry for the inconvenience.
Regards,