Page truncate in right side for landscape orientation with trimmargins using PdfSharp

前端 未结 3 1745
忘掉有多难
忘掉有多难 2021-01-14 07:18

I am talking about PdfSharp. Portrait orientation works well with margin or without margin. But In case of landscape orientation, page truncate in right side once I set any

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 07:39

    Yes, this is a bug of PdfSharp

    We can set the margins with orientation like bellow

    page = document.AddPage();
    //page.Size = PdfSharp.PageSize.A4;
    XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4);
    if(page.Orientation == PageOrientation.Landscape)
    {
       page.Width  = size.Height;
       page.Height = size.Width;
    }
    else
    {
       page.Width  = size.Width;
       page.Height = size.Height;
    }
    
    // default unit in points 1 inch = 72 points
    page.TrimMargins.Top = 5;
    page.TrimMargins.Right = 5;
    page.TrimMargins.Bottom = 5;
    page.TrimMargins.Left = 5;
    

提交回复
热议问题