Invalid pdf format:pdf head signature is not found! exception

Getting Invalid pdf format:pdf head signature is not found! exception, when trying to Concatenate multiple PDFs, please guide me to fix it.

int countpages = 0;

string[] files = System.IO.Directory.GetFiles(ConfigurationManager.AppSettings["TempDirectory"].ToString());

Stream[] inStreams = new Stream[files.Length];

foreach (string myFile in files)

{

FileStream inStream1 = new FileStream(myFile, FileMode.Open);

inStreams[countpages] = inStream1;

countpages++;

}

if (countpages != 0)

{

PdfFileEditor pdfEditor = new PdfFileEditor();

string strFileName = ConfigurationManager.AppSettings["TempDirectory"].ToString() + DateTime.Now.ToString("MMddyyyyHHmmsstt") + ".pdf";

FileStream outStream = new FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

pdfEditor.Concatenate(inStreams, outStream);

outStream.Close();

FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read);

BinaryReader br = new BinaryReader(fs);

byte[] img = br.ReadBytes((int)fs.Length);

br.Close();

fs.Close();

}

Hi Vamshi,

I have tested this issue using the code snippet you shared and the latest version of Aspose.Pdf.Kit for .NET. I couldn’t notice any problem at my end. Please download the latest version and try at your end.

If you still find any issues then please share the problematic PDF files with us, so we could test the issue using those files.

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