首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用PDFsharp旋转PDF而不截断内容

使用PDFsharp旋转PDF而不截断内容
EN

Stack Overflow用户
提问于 2015-03-01 22:46:35
回答 2查看 1.9K关注 0票数 2

旋转到纵向视图后,如何确保所有内容都是可见的(在页面范围内)?

PDFsharp在旋转+90度时会截断我的页面,而当旋转到-90度时不会截断页面。

代码语言:javascript
运行
复制
PdfDocument outputDocument = new PdfDocument();
XPdfForm old = XPdfForm.FromFile(in_filename);
PdfPage newP = outputDocument.AddPage();

if (old.Page.Orientation == PageOrientation.Landscape)
{
    old.Page.Rotate= (old.Page.Rotate - 90) % 360;
    old.Page.Orientation = PageOrientation.Portrait;
}

newP.Height = old.Page.Height;
newP.Width = old.Page.Width;

// Get a graphics object for page1
XGraphics gfx = XGraphics.FromPdfPage(newP);

// Draw the page identified by the page number like an image
gfx.DrawImage(old, new XRect(0, 0, old.PointWidth, old.PointHeight));

上述方法适用于一些pdf测试用例,但我怀疑这是巧合/运气。

我使用的是PDFsharp 1.50测试版。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-02 07:28:50

在导入旋转PDF方面,PDFsharp 1.50 beta存在一个已知的问题。这个问题仍在调查中。

PDF文件有许多不同的变体,因此很难确保代码在所有情况下都能工作。

票数 1
EN

Stack Overflow用户

发布于 2019-12-19 09:07:46

最后我做了以下几件事:(注意,这只需要用一个风景来描绘)

代码语言:javascript
运行
复制
        var output = new PdfDocument();
        var outputPage = output.AddPage();            

        using (var stream = new MemoryStream(Convert.FromBase64String(pdfBase64String)))
        {
            using (var input = XPdfForm.FromStream(stream))
            {
                outputPage.Height = input.PointWidth;
                outputPage.Width = input.PointHeight;

                using (var graphics = XGraphics.FromPdfPage(outputPage))
                {
                    graphics.RotateAtTransform(90, new XPoint(input.PointHeight / 2, input.PointHeight / 2));
                    graphics.DrawImage(input, new XRect(0, 0, input.PointWidth, input.PointHeight));

                }

            }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28800150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档