【问题标题】:Where does bottom and right border come from in abcPdfabcPdf中的底部和右侧边框来自哪里
【发布时间】:2015-04-03 01:41:54
【问题描述】:

为什么在使用 abcAdf 渲染 html 时底部和右侧出现边框。 PS 我获得了使用 (ABCpdf9-64.dll) 的专业许可证

我的过程是创建页面:

  1. 我在 mvc 中使用主/子布局模板(作品)
  2. 我指向这个html使用abcPdf转换成pdf

Html 呈现

当我的 html 呈现(纯)格式时:每个都来自其各自的位置。

<h1>Layout</h1>
<p>
    content
</p>

渲染 pdf 的 C# 代码

我的代码如下:

        using (var pdf = new Doc())
        {
            pdf.HtmlOptions.Timeout = 600000;

            pdf.HtmlOptions.AddTags = true;
            pdf.Page = pdf.AddPage();

            var id = pdf.AddImageUrl(url, true, 1024, true);
            if (allowPaging)
            {
                while (true)
                {
                    if (!pdf.Chainable(id))
                    {
                        break;
                    }

                    pdf.Page = pdf.AddPage();
                    id = pdf.AddImageToChain(id);
                }

                for (int i = 1; i <= pdf.PageCount; i++)
                {
                    pdf.PageNumber = i;
                    pdf.Flatten();
                }

                ////reset back to page 1 so the pdf starts displaying there
                if (pdf.PageCount > 0)
                {
                    pdf.PageNumber = 1;
                }
            }

            return store(pdf);
        }

输出

我的文本/html 渲染正常,但我得到了我没有要求的边框。

渲染输出:

请注意图片底部的细线。

【问题讨论】:

  • 什么是abcPdf.GetPdfDoc?我在official ABCpdf documentation 中找不到任何此类电话。
  • @RossPresser 我已经通过删除应用许可证的函数更新了我的示例
  • 该边框实际上是在 PDF 中,还是由您的查看器呈现?
  • 当我将 html 转换为 pdf (ie9) 时它会呈现

标签: c# html abcpdf


【解决方案1】:

在谷歌上搜索了数小时关于在 abcpdf 中设置边距的问题后,我什么也没找到,并认为自己找到它是一个挑战。 我尝试尝试在 abcpdf 文档中发现的所有相关内容,最后自己制作了一张图表 用于设置边距。我已经在很多情况下成功地实现了这一点。希望这对其他人有帮助。

这里有一段代码 sn-p 显示如何设置边距-

字符串 html; // 我的 html 内容应该显示在 pdf 页面中

            Doc pdf = new Doc();

            // adjust the default rotation and save
            double w = pdf.MediaBox.Width;
            double h = pdf.MediaBox.Height;
            double l = pdf.MediaBox.Left;
            double b = pdf.MediaBox.Bottom;

            // explicitly giving page size
            pdf.MediaBox.String = "A4";
            pdf.Transform.Rotate(90, l, b);
            pdf.Transform.Translate(w, 0);
            pdf.Rect.Width = h;
            pdf.Rect.Height = w;

            int theID1 = pdf.GetInfoInt(pdf.Root, "Pages");
            pdf.SetInfo(theID1, "/Rotate", "90");

            int theID;
            pdf.Rect.String = "17 55 823 423";
            theID = pdf.AddImageHtml(html.ToString()); //Writes the HTML image to PDF

这是描述一些垃圾值的边距布局的图片。这里 20 表示您的内容从 pdf 页面左侧 20 像素处开始 770 表示您的内容在距您的 pdf 页面左侧 770 像素处结束 75 建议您的内容从 pdf 页面底部上方 55 像素开始 600 表示您的内容在 pdf 页面底部上方 600 像素处结束

在你的情况下,你必须添加

pdf.Rect.String = "20 75 770 600"; // giving junk values

就在之前

var id = pdf.AddImageUrl(url, true, 1024, true);

注意:在此示例中,我明确设置了横向模式而不是纵向模式。但是方向对于设置并不重要 边距。

【讨论】:

    猜你喜欢
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 1970-01-01
    相关资源
    最近更新 更多