【问题标题】:Landscape and Portrait in same pdf同一pdf中的横向和纵向
【发布时间】:2019-12-02 03:57:35
【问题描述】:

我需要从我们应用程序中的 URL 生成 pdf 报告。是否可以在生成的同一个 pdf 文档中同时拥有横向和纵向页面?

我希望将条形图设为纵向,将表格设为横向(水平)。查看 EVO 文档,我不知道这是否可能。

我知道你可以定义横向或纵向

htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation

但这适用于整个文档。我想要一些我可以定义的 html,它会告诉 EVO 将此部分打印为 Landscape。

【问题讨论】:

    标签: c# evopdf evo


    【解决方案1】:

    您可以在同一个 PDF 中包含纵向和横向部分。为此,您可以创建一个空白 Document 对象并向该文档添加具有所需方向的 PDF 页面。在新创建的 PDF 页面上,您可以添加一个 HtmlToPdfElement 对象来呈现 HTML,并自动添加与您最初创建的 PDF 页面具有相同方向的 PDF 页面。可以对不同方向的 PDF 页面重复该过程。在Merge Multiple HTML Pages into a Single PDF 演示中有一个带有此方法的 C# 代码的实时示例。代码示例也复制如下:

    protected void convertToPdfButton_Click(object sender, EventArgs e)
    {
        // Create the PDF document where to add the HTML documents
        Document pdfDocument = new Document();
    
        // Create a PDF page where to add the first HTML
        PdfPage firstPdfPage = pdfDocument.AddPage();
    
        try
        {
            // Create the first HTML to PDF element
            HtmlToPdfElement firstHtml = new HtmlToPdfElement(0, 0, firstUrlTextBox.Text);
    
            // Optionally set a delay before conversion to allow asynchonous scripts to finish
            firstHtml.ConversionDelay = 2;
    
            // Add the first HTML to PDF document
            AddElementResult firstAddResult = firstPdfPage.AddElement(firstHtml);
    
            PdfPage secondPdfPage = null;
            PointF secondHtmlLocation = Point.Empty;
    
            if (startNewPageCheckBox.Checked)
            {
                // Create a PDF page where to add the second HTML
                secondPdfPage = pdfDocument.AddPage();
                secondHtmlLocation = PointF.Empty;
            }
            else
            {
                // Add the second HTML on the PDF page where the first HTML ended
                secondPdfPage = firstAddResult.EndPdfPage;
                secondHtmlLocation = new PointF(firstAddResult.EndPageBounds.Left, firstAddResult.EndPageBounds.Bottom);
            }
    
            // Create the second HTML to PDF element
            HtmlToPdfElement secondHtml = new HtmlToPdfElement(secondHtmlLocation.X, secondHtmlLocation.Y, secondUrlTextBox.Text);
    
            // Optionally set a delay before conversion to allow asynchonous scripts to finish
            secondHtml.ConversionDelay = 2;
    
            // Add the second HTML to PDF document
            secondPdfPage.AddElement(secondHtml);
    
            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();
    
            // Send the PDF as response to browser
    
            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");
    
            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Merge_Multipe_HTML.pdf; size={0}", outPdfBuffer.Length.ToString()));
    
            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);
    
            // End the HTTP response and stop the current page processing
            Response.End();
        }
        finally
        {
            // Close the PDF document
            pdfDocument.Close();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-09
      • 2012-03-29
      相关资源
      最近更新 更多