I'm writing an app in c# that fills a bunch of pdf forms, concatenates them then puts in some page numbers. I'm having difficulty with the memorystream result from the pdfstamper. If I change the memorystream to a filestream it works fine but I don't want to use the filesystem. I've created the following code snippet that reproduces my error:
public static void TestStreams(string filepath)
{
PdfReader reader = new PdfReader(filepath);
MemoryStream ms = new MemoryStream();
PdfReader.unethicalreading = true;
PdfStamper stamper = new PdfStamper(reader, ms);
byte[] result = ms.ToArray();
//The error is in the following line
PdfReader reader2 = new PdfReader(result);
}
The error is:
iTextSharp.text.exceptions.InvalidPdfException was unhandled
HResult=-2146232800
Message=Rebuild failed: trailer not found.; Original message: PDF startxref not found.
Source=itextsharp
How can I fix it?