예제 #1
0
 public bool SavePdfFileResult(string viewPath, string relativeFilePath, object model = null)
 {
     byte[] data = RazorPdf.GeneratePdf(RenderViewToString(viewPath, model));
     if (!string.IsNullOrWhiteSpace(relativeFilePath))
     {
         try
         {
             System.IO.File.WriteAllBytes(Server.MapPath(relativeFilePath), data);
         }
         catch (Exception e)
         {                             //In case of exception, file write has failed
             return(false);
         }
         return(true);
     }
     return(false);
 }
예제 #2
0
    public FileContentResult PdfFileResult(string viewPath, object model = null)
    {
        List <PdfPageContent> content = new List <PdfPageContent>();

        content.Add(new PdfPageContent()
        {
            Location = PdfPageLocation.Footer, Alignment = Element.ALIGN_LEFT, Content = "FOOTER LEFT"
        });
        content.Add(new PdfPageContent()
        {
            Location = PdfPageLocation.Footer, Alignment = Element.ALIGN_RIGHT, Content = "FOOTER RIGHT"
        });
        content.Add(new PdfPageContent()
        {
            Location = PdfPageLocation.Header, Alignment = Element.ALIGN_LEFT, Content = "HEADER LEFT"
        });
        content.Add(new PdfPageContent()
        {
            Location = PdfPageLocation.Header, Alignment = Element.ALIGN_RIGHT, Content = "HEADER RIGHT"
        });
        return(new FileContentResult(RazorPdf.GeneratePdf(RenderViewToString(viewPath, model), content), "application/pdf"));
    }