Rotativa.AspNetCore icon indicating copy to clipboard operation
Rotativa.AspNetCore copied to clipboard

SaveOnServerPath not work

Open zanyar3 opened this issue 4 years ago • 1 comments

ViewAsPdf use to Save file on Server Path but not work by SaveOnServerPath Property

var pdfname = String.Format("{0}.pdf", Guid.NewGuid().ToString());
var path = Path.Combine(@"MyPathProject\wwwroot\doc\Claim\Request", pdfname);
path = Path.GetFullPath(path);
var pdfResult = new ViewAsPdf
{
     ViewName = "_ToPDF",
     Model = memo,
     FileName = pdfname,
     SaveOnServerPath = path
};

zanyar3 avatar Jun 13 '20 13:06 zanyar3

Late, but just for reference if anyone stumbles on this issue. This works:

var pdf = new ViewAsPdf()
{
    SaveOnServerPath = "wwwroot/output.pdf"
};

pdf.BuildFile(this.ControllerContext);

SaveOnServerPath is obsolete though. If you don't specify it, a byte array is returned, which you can use to save the file yourself:

var pdfFile = new ViewAsPdf().BuildFile(this.ControllerContext);
File.WriteAllBytes("wwwroot/output.pdf", pdfFile);

Added this as documentation in #92.

ArjanKw avatar Aug 18 '24 20:08 ArjanKw