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.– Leonel Sanches da Silva
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%.
– Juan Sabino