简体   繁体   English

在 RazorPDF2 中更改页面方向

[英]Change Page Orientation in RazorPDF2

I am trying to use the NuGet package RazorPDF2 to convert a Razor View to a PDF.我正在尝试使用 NuGet package RazorPDF2 将 Razor 视图转换为 ZBCD1B686177B59ADDFC1Z08617BADFC16 The tool works wonderfully and is simple to use for just rendering a PDF, but I cannot figure out how to change the page orientation to landscape.该工具运行良好,并且易于使用,仅用于渲染 PDF,但我无法弄清楚如何将页面方向更改为横向。

I am using very simple controller code just to test the conversion to PDF.我正在使用非常简单的 controller 代码来测试到 PDF 的转换。 The conversion works, but I cannot change the orientation.转换有效,但我无法更改方向。

    public ActionResult TrainingCertificate()
    {
        var model = new CertificateModel();
        model.Name = "Michael White";
        return new PdfActionResult("TrainingCertificate", model);
    }

The "PdfActionResult" method does have an overload that looks like it might take configuration settings, but I cannot figure out how to use it because the parameter is an "encapsulated" "Action": “PdfActionResult”方法确实有一个重载,看起来它可能需要配置设置,但我不知道如何使用它,因为参数是一个“封装”“Action”:

    public PdfActionResult(string viewName, object model, Action<iTextSharp.text.pdf.PdfWriter, iTextSharp.text.Document> configureSettings) : base(viewName, model, configureSettings)
    {
        
    }

Does anyone have any experience with this tool or can help with figuring out what is needed for the "configurationSettings" parameter, please help.有没有人对这个工具有任何经验或者可以帮助弄清楚“configurationSettings”参数需要什么,请帮忙。 Thanks!谢谢!

Okay, so I figured this one out.好的,所以我想出了这个。 I changed the return "PdfActionResult" code to the following:我将返回“PdfActionResult”代码更改为以下内容:

        return new PdfActionResult("TrainingCertificate", model, (writer, document) =>
        {
            document.SetPageSize(iTextSharp.text.PageSize.LETTER.Rotate());
            document.SetMargins(50, 50, 50, 50);
            document.NewPage();
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM