andyhutch77 / MvcRazorToPdf

Create pdf documents within an asp .net mvc project by generating your views as normal but returning a PdfActionResult. This converts regular produced razor/html to pdf documents in the browser using the iTextXmlWorker.
125 stars 105 forks source link

The document has no pages #36

Open oyin-s opened 9 years ago

oyin-s commented 9 years ago

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

DWAK-ATTK commented 8 years ago

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.

tajuddin335 commented 7 years ago

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

shameen commented 6 years ago

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.

1337GameDev commented 3 months ago

The is VERY COMMONLY due to non-strict html that's NOT 100% valid xml.

This means EVERY tag must have a closing tag, or be self closing:

<br> will cause this error, but <br /> won't.

Same for inputs, img, hr, etc.