Home > OS >  xfinium: How To generate PDF with differant orientations
xfinium: How To generate PDF with differant orientations

Time:07-13

I try to create a PdfFlowDocument with header and footer. The page from 1 to 3 in Portrait mode. Page 4 is in Landscape and the rest again in portrait. 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);
        }

CodePudding user response:

You handle the PageCreated event and set the page rotation to 90 for landscape based on your specific condition.

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);
    flowDocument.AddContent(flowContent);
}

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

Disclaimer: I work for the company that develops the XFINIUM.PDF library.

  • Related