为什么我在使用abcAdf渲染html时会在底部和右边获得边框。 PS我获得了专业许可(ABCpdf9-64.dll)
我的流程是创建页面:
呈现的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呈现正常但我得到了我没有要求的边框。
渲染输出:
请注意图片底部的发际线。
答案 0 :(得分:1)
在abcpdf上关于设置保证金的谷歌搜索了几个小时之后,我什么也没找到,并把它作为挑战自己找到它。 我试着尝试在abcpdf文档中找到相关的所有内容,最后自己制作了一个图表 用于设置边距。我在很多情况下成功实现了这一点。希望这有助于其他人。
以下是显示如何设置边距的代码段 -
string 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);
注意:在此示例中,我明确设置了横向模式而不是纵向模式。但是方向与设置无关 边距。