网页截在右侧,横向使用PdfSharp trimmargins [英] Page truncate in right side for landscape orientation with trimmargins using PdfSharp

查看:357
本文介绍了网页截在右侧,横向使用PdfSharp trimmargins的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我说的是PdfSharp。纵向保证金或保证金没有效果很好。但在横向,在右侧页面截的情况下,一旦我使用TrimMargins设置任何保证金。我曾尝试在pdfSharp样本code和有同样的问题!同样的事情

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!!

为以下code呈现良好外观的PDF

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);

但对于以下code PDF不会呈现良好,截断右侧

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

推荐答案

是的,这是PdfSharp的一个bug

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;

这篇关于网页截在右侧,横向使用PdfSharp trimmargins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆