using System.Web.Mvc;
using System.Configuration;
namespace SelectPdf.Samples.Controllers
{
    public class PdfPortfolioController : Controller
    {
        //
        // GET: /PdfPortfolio/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult SubmitAction(FormCollection collection)
        {
            // the test files
            string filePdf = Server.MapPath("~/files/doc.pdf");
            string fileHtml = Server.MapPath("~/files/document.html");
            string fileImage = Server.MapPath("~/files/logo.png");

            // instantiate the pdf portfolio manager
            PdfPortfolioManager portfolio = new PdfPortfolioManager();

            // add files to the portfolio
            PdfPortfolioFile pdfFilePdf = new PdfPortfolioFile(filePdf);
            pdfFilePdf.Description = "PDF document";
            portfolio.Files.Add(pdfFilePdf);

            PdfPortfolioFile pdfFileHtml = new PdfPortfolioFile(fileHtml);
            pdfFileHtml.Description = "HTML document";
            portfolio.Files.Add(pdfFileHtml);

            PdfPortfolioFile pdfFileImage = new PdfPortfolioFile(fileImage);
            pdfFileImage.Description = "Image file";
            portfolio.Files.Add(pdfFileImage);

            // set view mode
            portfolio.ViewMode = PdfPortfolioViewMode.Details;

            // set startup file
            portfolio.StartupFileName = "logo.png";

            // save pdf document
            byte[] pdf = portfolio.Save();

            // close pdf document
            portfolio.Close();
            
            // return resulted pdf document
            FileResult fileResult = new FileContentResult(pdf, "application/pdf");
            fileResult.FileDownloadName = "Document.pdf";
            return fileResult;
        }
    }
}
