MvcRazorToPdf
MvcRazorToPdf copied to clipboard
The document has no pages
hi, i keep getting this error The document has no pages The page is a replica of MVC Details page this is my code
public ActionResult CreatePDF(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return new PdfActionResult(movie, (writer, document) =>
{
document.SetPageSize(new Rectangle(500f, 500f, 90));
document.NewPage();
});
}
Am i missing something? pls help
There's a discussion thread around here somewhere that indicates this issue is caused by using an incorrectly formatted Layout. Try using the _PdfLayout.cshtml from the sample web site and see if that makes the error go away.
Did you find the solution for this? I am having same issue.
in case anyone still has this issue, this error happens to me when using any form of HtmlHelper, i had to remove all usages of @Html
and @helper
.
Also, try to move as much logic as possible into the model or controller if you have some in the view.