2

I am building html views with stringbuilder and using DinkToPDF to convert this HTML to a pdf. I have been able to add a header and footer using the following(By creating static HTML pages:

var objectSettings = new ObjectSettings
        {
            PagesCount = true,
            HtmlContent = await _template.Build(data, hostUrl),
            //HeaderSettings = { HtmUrl = hostUrl + "/views/v1/getview?reportName=AcademicTranscript&viewName=test.html&themeName=SchoolTheme_SchoolId", 
            HeaderSettings = { HtmUrl = hostUrl + _swaggerConfig.BasePath + "/views/v1/getview?reportName=AcademicTranscript&viewName=portraitheader.html",
                Line = true, Right = "[page]/[sitepages]", Spacing = 5 },
            FooterSettings = { HtmUrl = hostUrl + _swaggerConfig.BasePath + "/views/v1/getview?reportName=AcademicTranscript&viewName=portraitfooter.html",
                Line = true },
        };

This works great, but I need to add a custom html view as part of the header, which contains details, such as Name, surname, address etc.

Is there a way of adding a custom built page(meaning Html tags etc. with information from the Database) to the header?

I hope my question makes sense.

Thanks for any help.

AxleWack
  • 1,801
  • 1
  • 19
  • 51

1 Answers1

1

It seems that at the moment there are 2 ways to setup a document header content in HeaderSettings in DinkToPDF:

  1. fill Left, Center, Right properties with a plain text
  2. pass a path to a header file in HTML format in HtmUrl property

So you can retrieve the needed data from a database, fill an HTML header file with HTML renderer like this one, pass the header file's path to HeaderSettings.HtmUrl property, generate your PDF document with DinkToPDF and delete the header file afterwards.

An example for generating HTML files by template can be found here

SvjMan
  • 589
  • 9
  • 18