jason
jason

Reputation: 7164

How to give PdfReader a HttpPostedFileBase

As I see itextsharp's PdfReader object accepts a filename. But I have HttpPostedFileBase in my controller, how can I give HttpPostedFileBase to PdfReader. Here is the code :

    public ActionResult Index(HttpPostedFileBase file)
    {

        PdfReader myReader = new PdfReader(file); // this gives error.

Upvotes: 0

Views: 1203

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Given a HttpPostedFileBase named file, then you could do this:

byte[] pdfbytes = null;
BinaryReader rdr = new BinaryReader(file.InputStream);
pdfbytes = rdr.ReadBytes((int)file.ContentLength);
PdfReader reader = new PdfReader(pdfbytes);

You could, of course, first save the PDF to a file, and then provide the path to that file, but usually, that's not what you want.

Upvotes: 2

Related Questions