Hello @asad.ali
Still working on the flatten pdf method, and having this error: Aspose.Pdf.InvalidPdfFileFormatException: âIncorrect file headerâ
I have seen examples of people using BindPDF on memoryStream and I have done the exact same thing
Hereâs my code snippet:
public FileContentResult FlattenPdf(IFormFile uploadedFile, string flattenResult = âflattened.pdfâ)
{
flattenResult = Path.GetExtension(flattenResult).Equals(".PDF", StringComparison.OrdinalIgnoreCase) ? flattenResult : string.Format("{0}.pdf", flattenResult);
using var mem = new MemoryStream();
var openFilePath = Path.Combine(@"c:\Users\john.doe\Downloads", uploadedFile.FileName);
using var stream = new FileStream(openFilePath, FileMode.Open);
uploadedFile.CopyToAsync(stream);
stream.CopyTo(mem);
Form pdfForm = new Form();
pdfForm.BindPdf(mem);
pdfForm.FlattenAllFields();
pdfForm.Save(mem);
var result = mem.ToArray();
return new FileContentResult(result, "application/pdf") { FileDownloadName = flattenResult };
}`
Still using the same pdf file as before if you need to test anything.
Please let me know if thereâs anything wrong with the code or something.
Thank you!