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

asp.net, c#, pdf, pdfsharp

Solution

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;

Problem

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 margin using TrimMargins. I have tried same thing on sample code of pdfSharp and having same problem!! Look pdf rendered well for following code ``` page = document.AddPage(); page.Size = PdfSharp.PageSize.A4; page.Orientation = PageOrientation.Landscape; gfx = XGraphics.FromPdfPage(page); gfx.DrawString("A4 (landscape)", font,XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),XStringFormats.Center); ``` But for following code pdf is not rendered well, truncate in right side ``` page = document.AddPage(); page.TrimMargins.Top = 5; page.TrimMargins.Right = 5; page.TrimMargins.Bottom = 5; page.TrimMargins.Left = 5; page.Size = PdfSharp.PageSize.A4; page.Orientation = PageOrientation.Landscape; gfx = XGraphics.FromPdfPage(page); gfx.DrawString("A4 (landscape)", font,XBrushes.DarkRed, new XRect(0, 0, page.Width, page.Height),XStringFormats.Center); ``` Have any idea? Thanks

Original source