Search code examples
c#.netitext7

Accepting Pdf through post request and passing to itext7 pdfreader in c# .net core


I am getting a pdf through post request from frontend as an IFormFile form and I want to take that and pass it to pdfreader() in itext7 package. so far i could only pass with the path as string i dont have any path to specify.


Solution

  • Pdfreader accepts System.IO.MemoryStream, or any generic System.IO.Stream, as can be seen in the API documentation: https://api.itextpdf.com/iText7/dotnet/7.1.11/classi_text_1_1_kernel_1_1_pdf_1_1_pdf_reader.html

    PdfReader (IRandomAccessSource byteSource, ReaderProperties properties)
    Constructs a new PdfReader. More...
    
    PdfReader (Stream @is, ReaderProperties properties)
    Reads and parses a PDF document. More...
    
    PdfReader (FileInfo file)
    Reads and parses a PDF document. More...
    
    PdfReader (Stream @is)
    Reads and parses a PDF document. More...
    
    PdfReader (String filename, ReaderProperties properties)
    Reads and parses a PDF document. More...
    
    PdfReader (String filename)
    Reads and parses a PDF document. More...
    

    So you can pass the data from the IFormFile form.