Why HtmUrl property is not working correclty?

56 Views Asked by At

I'm using DinkToPdf library, and need to implement custom html header which must be generated dynamically. For some reason it shows unpredictable behavior. First of all, if pdf is showing content correctly, there is now header at all. That's works only when spacing property is 0. Second of all, if spacing property are not 0, is doesn't show content at all, only text that is contained between html text.

I though that the problem might be in styling or html, but it's not the case, because even with the most simple or empty html header file it's still the same and depends on spacing somehow.

Here is code:

    StringBuilder htmlCode = new StringBuilder("Adds image at the start of the pdf file");
    string path = HttpContext.Current.Server.MapPath("~\\assets\\header.html");
    StringBuilder table = new StringBuilder(withNewCell ? CreateTable(gridView, true) : CreateTable(gridView));
    htmlCode.Append(table.ToString());
    var test = htmlCode.ToString();
    var doc = new HtmlToPdfDocument()
    {
        GlobalSettings = {
            ColorMode = ColorMode.Color,
            Orientation = DinkToPdf.Orientation.Landscape,
            PaperSize = PaperKind.A4Plus,
        },
        Objects = {
            new ObjectSettings() {
                PagesCount = true,
                HtmlContent = test,
                WebSettings = { DefaultEncoding = "utf-8", PrintMediaType = true, },
                //Works normaly only when there is text property or is empty
                HeaderSettings = { HtmUrl= path, Spacing = 0}
            }
        }
    };
    byte[] pdf = _converter.Convert(doc);
    HttpContext.Current.Response.BinaryWrite(pdf);
    HttpContext.Current.Response.ContentType = "application/pdf";
    HttpContext.Current.Response.AddHeader("content-disposition", "inline;filename=" + DateTime.Now.Ticks.ToString() + ".pdf");
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.End();
0

There are 0 best solutions below