简体   繁体   English

xfinium:如何生成具有不同方向的 PDF

[英]xfinium: How To generate PDF with differant orientations

I try to create a PdfFlowDocument with header and footer.我尝试创建一个带有页眉和页脚的 PdfFlowDocument。 The page from 1 to 3 in Portrait mode.纵向模式下从 1 到 3 的页面。 Page 4 is in Landscape and the rest again in portrait.第 4 页是横向的,其余的又是纵向的。 Following my code code snippet:按照我的代码片段:

        PdfFlowDocument flowDocument = new PdfFlowDocument();
        //flowDocument.HeadersFooters.EvenPagesHeader = docHeader;
        //flowDocument.HeadersFooters.EvenPagesFooter = docFooter;
        Xfinium.Pdf.Core.PdfFile sourceFile = new Core.PdfFile(File.OpenRead(""));
        Xfinium.Pdf.Graphics.PdfPageContent[] pageContents = sourceFile.ExtractPageContent(0, sourceFile.PageCount - 1);

        foreach (Xfinium.Pdf.Graphics.PdfPageContent content in pageContents)
        {
            //content can be Portrait or Landscape
            //How can I rotate the orientation?
            //How can I scale the page?
            var flowContent = new Xfinium.Pdf.FlowDocument.PdfFlowFormXObjectContent(content);
            flowDocument.AddContent(flowContent);
        }

You handle the PageCreated event and set the page rotation to 90 for landscape based on your specific condition.您处理 PageCreated 事件并根据您的特定条件将页面旋转设置为横向 90。

PdfFlowDocument flowDocument = new PdfFlowDocument();
flowDocument.PageCreated += FlowDocument_PageCreated;

//flowDocument.HeadersFooters.EvenPagesHeader = docHeader;
//flowDocument.HeadersFooters.EvenPagesFooter = docFooter;
Xfinium.Pdf.Core.PdfFile sourceFile = new Core.PdfFile(File.OpenRead(""));
Xfinium.Pdf.Graphics.PdfPageContent[] pageContents = sourceFile.ExtractPageContent(0, sourceFile.PageCount - 1);

foreach (Xfinium.Pdf.Graphics.PdfPageContent content in pageContents)
{
    //content can be Portrait or Landscape
    //How can I rotate the orientation?
    //How can I scale the page?
    var flowContent = new Xfinium.Pdf.FlowDocument.PdfFlowFormXObjectContent(content);
    flowContent.SizeIsRelativeToAvailableSpace = true;
    flowContent.FormXObjectHeight = 100;
    flowContent.FormXObjectWidth = 100;

    flowDocument.AddContent(flowContent);
}

private void FlowDocument_PageCreated(object sender, PdfFlowPageCreatedEventArgs e)
{
    if (yourConditionHere)
    {
        e.Page.Rotation = 90;
    }
}

Update : you can set the flowContent.SizeIsRelativeToAvailableSpace property to true and flowContent.FormXObjectWidth and flowContent.FormXObjectHeight properties to 100. This means the content object will be scaled to take all available space (100%).更新:您可以将flowContent.SizeIsRelativeToAvailableSpace属性设置为 true, flowContent.FormXObjectWidthflowContent.FormXObjectHeight属性设置为 100。这意味着内容对象将被缩放以占用所有可用空间 (100%)。 It will also take care of the white page problem.它还将处理白页问题。

Disclaimer: I work for the company that develops the XFINIUM.PDF library.免责声明:我为开发XFINIUM.PDF库的公司工作。

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

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