【发布时间】:2015-06-03 11:44:39
【问题描述】:
我已经开始将 abcpdf 用于 c# 应用程序。首先我得到pdf,然后我得到一个截图来将它转换成pdf(我这样做是因为我加载了一些图表)。我有两个问题:
1- 我可以在我的 html 的顶部添加边距,但问题是当我的 html 的大小比一页长时,所以.. 我有多个页面,但我不知道如何添加x 顶部和底部每页边距。
我发现一个人问了类似的问题,但他没有得到答案。 ABCpdf, render an HTML within a "template": How to add margin?
2- 我的页脚也有问题,因为我必须始终在底部打印条款和条件,并且取决于我的 html 的大小,它打破了措辞的障碍,我不希望这样。我必须总是在底部打印它,并且只打印在一个块而不是两个块中。
下面是我实现的代码。
public FileStreamResult HtmlToPdf(Uri pdfUrl, bool landscape, int screenResolutionWidth, bool enableCache)
{
var pdfStream = new MemoryStream();
using (var theDoc = new Doc())
{
if (landscape)
{
// apply a rotation transform
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
}
theDoc.HtmlOptions.Engine = EngineType.Gecko;
theDoc.HtmlOptions.PageCacheClear();
theDoc.HtmlOptions.PageCachePurge();
theDoc.HtmlOptions.UseScript = true;
theDoc.HtmlOptions.Timeout = 90000;
theDoc.HtmlOptions.AddLinks = false;
var url = Uri.UnescapeDataString(pdfUrl.ToString());
var pageRef = theDoc.AddImageUrl(url, true, screenResolutionWidth, true);
while (theDoc.Chainable(pageRef))
{
theDoc.Page = theDoc.AddPage();
pageRef = theDoc.AddImageToChain(pageRef);
}
for (var i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
theDoc.Save(pdfStream);
theDoc.Clear();
}
var byteInfo = pdfStream.ToArray();
pdfStream.Write(byteInfo, 0, byteInfo.Length);
pdfStream.Position = 0;
return new FileStreamResult(pdfStream, "application/pdf");
感谢您的宝贵时间。
【问题讨论】:
标签: c# pdf-generation abcpdf