using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace SelectPdf.Samples.Pages
{
    public class PdfPortfolioModel : PageModel
    {
        public void OnGet()
        {

        }

        public IActionResult OnPost()
        {
            // the test files
            string filePdf = Startup.ServerPath + @"\wwwroot\files\doc.pdf";
            string fileHtml = Startup.ServerPath + @"\wwwroot\files\document.html";
            string fileImage = Startup.ServerPath + @"\wwwroot\images\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;

        }
    }
}