MvcRazorToPdf icon indicating copy to clipboard operation
MvcRazorToPdf copied to clipboard

The document has no pages

Open oyin-s opened this issue 9 years ago • 4 comments

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

oyin-s avatar Sep 17 '15 15:09 oyin-s

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.

DWAK-ATTK avatar Jan 19 '16 00:01 DWAK-ATTK

Did you find the solution for this? I am having same issue.

tajuddin335 avatar Feb 15 '17 04:02 tajuddin335

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.

shameen avatar Nov 13 '17 10:11 shameen