File does not begin with PDF

I am having problem with code that would take stream of files and concatenate it to a new pdf is no longer working and I get the error File does not begin with PDF instead.

This is the code that I am using:

Stream[] allFileStreams = new Stream[c]; //load all of the files inthe stream array

FileStream documentInstream = new FileStream("C:\temp\pdf1.pdf", FileMode.Open, FileAccess.Read);

allFileStreams[0] = documentInstream;

//Instantiate PdfFileEditor object

PdfFileEditor pdfEditor = new PdfFileEditor();

//Call Concatenate method of PdfFileEditor object to concatenate all input streams into a single output stream

Response.ContentType = "application/pdf";

Response.AppendHeader("Accept-Ranges", "none");

pdfEditor.Concatenate(allFileStreams, Response.OutputStream);

Seems like the output pdf only has html in the pdf. No actual pdf content. See file uploaded as the newly formed concatenated version.

Please help asap.

Also, I'd like to make the note that this has failed suddenly on our live server.

Works on other servers. We tried rebooting the live server, but nothing is helping.

What can you tell us to help debug this problem about the .Concatenate function. Where does it do its work (in memory, does it create ANY temp files somewhere that may be corrupt)?

Anything at all that you can tell us would help. We don't understand how it could suddenly stop working.

Hi Mike,

Please call Response.End method after calling the Concatenate method. This will ensure that the HTML is not added to the PDF file, when the PDF file is rendered to the browser.

I hope this helps. If it still doesn’t resolve your issue then please share the input PDF files along with the complete code snippet with us, so we could test the issue at our end.

We’re sorry for the inconvenience.
Regards,

We have found the cause of the problem, but need to know more about it.

What we find is that every time the concatenate is called it creates a temp file in the default windows temp folder. After many months of usage there were simply too many temp files left behind in the folder (over 65K files which is a windows limit for a folder).

My question to ASPOSE is why are the temp files create not being automatically deleted after the concatenate has happened.

Unless we go in and manually delete from that folder, this problem will arise again. Is there something else we need to do to have the ASPOSE .dll automatically clean up after itself?

Hi Mike,

I’m sorry to inform you that currently Aspose.Pdf.Kit doesn’t remove the temporary files; however, I have logged an issue as PDFKITNET-25102 in our issue tracking system to investigate and remove the temporary files after the process is completed.

Nevertheless, in the meanwhile, you may try setting some other temporary folder using [Settings.TempPath] property and delete the temporary files from that. Please note that this property is available in our latest version – Aspose.Pdf.Kit for .NET 5.4.0.

You’ll be updated via this forum thread once the above mentioned issue is resolved.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as 25102) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)

Can you tell me if this problem is fixed in the latest version of ASPOSE PDF.dll package (using the legacy namespace) as I no longer use the PDF.KIT .dll anymore as it is no longer going to be supported?

Hi Mike,

This particular issue was fixed with the Aspose.Pdf.Kit for .NET; however, the new Aspose.Pdf for .NET uses improved PDF manipulation engine and we didn’t notice any such problem with the new version. Please try the merged version at your end. If you still find any problem please do let us know. Moreover, I’ll also discuss with our development team to make sure that this issue doesn’t occur in the new version in future.

Regards,