Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ABCpdf-为每页添加页边空白,并将页脚保留在一个块中_C#_Pdf Generation_Abcpdf - Fatal编程技术网

C# ABCpdf-为每页添加页边空白,并将页脚保留在一个块中

C# ABCpdf-为每页添加页边空白,并将页脚保留在一个块中,c#,pdf-generation,abcpdf,C#,Pdf Generation,Abcpdf,我已经开始在c#应用程序中使用abcpdf。首先我得到pdf,然后我得到一个屏幕截图,将其转换为pdf(我这样做是因为我加载了一些图表)。我有两个问题: 1-我可以在我的html顶部添加边距,但问题是当我的html的大小超过一页时,所以。。我有多个页面,我不知道如何在顶部和底部添加每页的xmargin 我发现一个人问了类似的问题,但他没有得到答案 2-我的页脚也有问题,因为我必须始终在底部打印条款和条件,这取决于我的html的大小,这打破了文字块,我不希望这样。我必须始终在底部打印,并且只打印一

我已经开始在c#应用程序中使用abcpdf。首先我得到pdf,然后我得到一个屏幕截图,将其转换为pdf(我这样做是因为我加载了一些图表)。我有两个问题:

1-我可以在我的html顶部添加边距,但问题是当我的html的大小超过一页时,所以。。我有多个页面,我不知道如何在顶部和底部添加每页的
x
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");
public FileStreamResult HtmlToPdf(Uri-pdfUrl、bool-landscape、int-screensolutionwidth、bool-enableCache)
{
var pdfStream=newmemoryStream();
使用(var theDoc=new Doc())
{
国际单项体育联合会(景观)
{
//应用旋转变换
双w=Doc.MediaBox.Width;
双h=Doc.MediaBox.Height;
双l=doc.MediaBox.Left;
双b=doc.MediaBox.Bottom;
DOC变换旋转(90,l,b);
阶变换平移(w,0);
//旋转我们的矩形
doc.Rect.Width=h;
DOC.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=doc.AddImageUrl(url,true,screenResolutionWidth,true);
while(doc.chaineable(pageRef))
{
theDoc.Page=theDoc.AddPage();
pageRef=Doc.AddImageToChain(pageRef);
}

对于(var i=1;i我找到了一种在顶部和底部获得利润的方法,但这并不完全是我想要的。无论如何,它是有效的,所以请看下面

Css:

Html:


并在里面设置你想要的边距


希望能有所帮助。

我在你提到的帖子中解决了我的问题

1:您可以将文档中已用空间的大小定义为
doc.Rect
。这对以下所有页面都有效。您还可以在处理过程中为Rect设置新大小


2:为了添加条款和条件,我将调用
doc.AddImageDoc(模板,1,doc.Rect)
在循环内部,在展平页面之前。只需确保事先调整
doc.Rect
的大小和位置。

除了@Tinelers comment之外,您还可以将以下值设置为在所有页面上具有固定页眉和页脚边距

insetX,insetY

doc.Rect.Inset(15, 15);

根据需要在插图中添加值。

这有助于我添加页边距。但是,页边距上/下边距似乎并不适用于每页,而是只影响第一页(上边距)和最后一页(下边距)。
<div class="header"></div>
doc.Rect.Inset(15, 15);