I want to insert image to the user upload file, when I tried to create pdfDocument from the stream I got the "You can't read from OutputStream" error
public ActionResult GetTemplate(IFormFile template)
{
byte[] pdfBytes;
using (var memoryStream = new MemoryStream())
{
template.CopyTo(memoryStream);
var writer = new PdfWriter(memoryStream);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(memoryStream));
var document = new Document(pdfDocument);
var pageCount = pdfDocument.GetNumberOfPages();
ImageData imageData = ImageDataFactory.CreatePng(System.Convert.FromBase64String(//));
var img = new Image(imageData).Scale(200, 100).SetFixedPosition(pageCount, 50, 120);
document.Add(img);
document.Close();
pdfBytes = memoryStream.ToArray();
}
return new FileContentResult(pdfBytes, "application/pdf");
}
If I changed it to new PdfDocument(new PdfReader(writer));
I got "PDF header not found" error instead.
This is my first time using iText, most of the answers I found on their website only worked with java. Any suggestion or help would be great, thank you for your time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…