Razorpdf2 - The Document has no pages

Asked

Viewed 320 times

2

I’m trying to use the Razorpdf2 to generate the PDF of a view. I put a breakpoint so much on the controller how much in the view and both are running without any error, but after the execution ends always returns the error:

The Document has no pages.

Description: An unhandled Exception occurred During the Execution of the Current web request. Please review the stack trace for more information about the error and Where it originated in the code.

Exception Details: System.IO.Ioexception: The Document has no pages.

Source Error:

An unhandled Exception was generated During the Execution of the Current web request. Information regarding the origin and Location of the Exception can be identified using the Exception stack trace Below.

Follow my controller:

public ActionResult Pdf(int? id)
{

    if (id == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }

    Orcamentos Orcamentos = db.Orcamento.Find(id);

    var pdf = new PdfActionResult( Orcamentos);
    pdf.FileDownloadName = "Pdf";
    pdf.ViewName = "Pdf";

    return pdf;// View(Orcamentos);

}

Follow the View (I left only the basics, but still will not):

@model OrcamentosSeal.Models.Orcamentos

@{
    ViewBag.Title = "Orcamento" + Model.Orcamento.CJ_NUM;
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
</head>
<body>
    <p>Teste</p>   
</body>
</html>

I reinstalled the package via Nugget and used the model _Pdfhtmllayout.cshtml and it worked.

  • I think I’ll update the package on Nuget so you can do one more test. PdfActionResult uses the method of another package, not Razorpdf2. If that’s the case, I’ll ask you to put the project in a public repository so I can run some tests here.

  • 1

    I tried using the example layout _Pdfhtmllayout.cshtml and nothing, so I reinstalled the package and tried again without making any changes and it was. Now it’s running 100%.

1 answer

0

If your intention is to see on screen, change to this:

 return new PdfActionResult("NomeDaView", Orcamentos));
  • Had already tested so much setando the property Filedownloadname when returning straight to view on screen, always gave the same error.

  • @Juansabino But in your example you don’t arrow the Layout in his View, where is: Layout = null;

  • I created the layout file and specified it in my view, but it remains the same. If I return with View(Budget); it displays the normal page, with the layout or without.

  • @Juansabino Try to pass the name of View together. I just edited the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.