【问题标题】:How to set particular page in landscape using Rotativa MVC?如何使用 Rotativa MVC 在横向中设置特定页面?
【发布时间】:2018-07-04 12:48:49
【问题描述】:

我创建了一个 MVC 5 项目。在这个项目中,我设计了一些局部视图。 使用 Rotativa.MVC,我可以将部分视图转换为 pdf。

我想为 pdf 设置横向页面。

使用Rotativa.MVC将部分视图转换为pdf时如何设置横向单页?

我使用下面的代码将部分视图转换为 pdf。

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

请为我提供上述功能的解决方案。

谢谢

【问题讨论】:

    标签: asp.net-mvc pdf rotativa


    【解决方案1】:

    请使用以下代码,

     public ActionResult TestAction(TestViewModel testViewModel)
     {
        return new Rotativa.MVC.ViewAsPdf("_testPartial", testViewModel)
                {
                    RotativaOptions = new Rotativa.Core.DriverOptions()
                    {
                        PageOrientation = Rotativa.Core.Options.Orientation.Landscape,
                    },
                };
      }
    

    【讨论】:

      【解决方案2】:
      public ActionResult DownloadViewPDF(List<GetPolice_Result> model)
      {
          return new Rotativa.ViewAsPdf("ViewRapor", model)
          {
              PageOrientation = Rotativa.Options.Orientation.Landscape,
              FileName = "EfegulViewAsPdf.pdf"
          };
      }
      

      【讨论】:

      • 这个解决方案似乎只适用于整个 PDF,所以它并不是问题中所问的,因为用户想知道如何将方向更改为 PDF 中特定的单个页面。跨度>
      【解决方案3】:

      Rotativa 没有提供内置解决方案来为生成的 PDF 中的单个页面分配不同的方向。最好的方法应该是对 WkHtmlToPdf 使用 CustomSwitches(Rotativa 使用它来生成 PDF),但是很久以前就有一个开放的请求,你可以看到,仍然没有明确的解决方案:

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

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

      我们尝试过一次,使用 CSS(size 属性和部分视图),但没有成功,但有一个使用 CSS transform 的现有解决方法:

      Mixing page orientations in wkhtmltopdf

      在这篇帖子的回答中提到了另一种可能的解决方法:使用 2 个不同的 PDF 文件并使用 Ghostscript 将它们合并。

      目前看来,这些替代方案是使这成为可能的唯一方法,还是等待WkHtmlToPdf命令解决。

      【讨论】:

        猜你喜欢
        • 2017-10-11
        • 1970-01-01
        • 2019-07-23
        • 2014-01-17
        • 1970-01-01
        • 2020-12-26
        • 1970-01-01
        • 1970-01-01
        • 2016-11-21
        相关资源
        最近更新 更多