2

I have created a MVC 5 project. In this project, I have designed some partial view. Using Rotativa.MVC, I can convert partial view to pdf.

I want to set landscape page for pdf.

How to set a single page in landscape when partial view convert to pdf using Rotativa.MVC?

I have used below code for convert partial view to pdf.

   [HttpPost]
    public ActionResult TestAction(TestViewModel testViewModel)
    {
        return PartialView("_testPartial", testViewModel);
    }

Please suggest me solution for above functionality.

Thank you

3 Answers3

1

please use below code,

 public ActionResult TestAction(TestViewModel testViewModel)
 {
    return new Rotativa.MVC.ViewAsPdf("_testPartial", testViewModel)
            {
                RotativaOptions = new Rotativa.Core.DriverOptions()
                {
                    PageOrientation = Rotativa.Core.Options.Orientation.Landscape,
                },
            };
  }
Azhar
  • 333
  • 5
  • 10
1
public ActionResult DownloadViewPDF(List<GetPolice_Result> model)
{
    return new Rotativa.ViewAsPdf("ViewRapor", model)
    {
        PageOrientation = Rotativa.Options.Orientation.Landscape,
        FileName = "EfegulViewAsPdf.pdf"
    };
}
Fırat DİKMEN
  • 479
  • 5
  • 8
  • This solution seeems to only apply to entire PDF, so it's not exactly what is asked in the question, as the user whants to know hot to change orientation to a particular single page inside the PDF. – Dave Miller Aug 25 '21 at 11:14
0

There's is no built-in solution provided by Rotativa to asign different orientation for a single page within the generated PDF. The best way should be using CustomSwitches for WkHtmlToPdf (used by Rotativa to generate the PDF), but there's is an open request since long ago, and you can see, still no definitive solution:

https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1564

https://github.com/wkhtmltopdf/wkhtmltopdf/pull/4439

We've tried once, using CSS (size attribute and partial views), with no luck, but there is an existing workaround using CSS transform:

Mixing page orientations in wkhtmltopdf

On this post answer another possible workaround is mentioned: using 2 different PDF files and merging them usign Ghostscript.

At this time, it seems that these alternatives are the only way to make this possible, or wait for WkHtmlToPdf command solution.

Dave Miller
  • 536
  • 3
  • 19