I have started to use abcpdf for a c# application. First I get the pdf and then I get a screenshot to convert it in pdf(I do it because I load some charts). I have 2 problems:
1- I can add margin to the top of my html but the problem is when I the size of my html is longer than a page so.. I have more than one page and I don't know how can I add x
margin per page in the top and in the bottom.
I found a guy asking something similar but he didn't get an answer. ABCpdf, render an HTML within a "template": How to add margin?
2- Also I have a problem with the footer because I have to print terms and conditions always in the bottom and depends on the size of my html it's breaking the block of wording and I don't want that. I have to print it always in the bottom and in only one block not in two.
Below is the code I have implemented.
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");
Thanks for your time.