Giter Site home page Giter Site logo

Comments (5)

sumit0501 avatar sumit0501 commented on May 15, 2024 1

Hello,
Header and Footer are not coming on docker alpine image. Tried both with htmlurl or with Right=text option. It is coming on .netcore 2.1 runtime image but not with alpine. please help.

from dinktopdf.

rdvojmoc avatar rdvojmoc commented on May 15, 2024

If we continue from #28 you could add header and footer like that:

// set up the document
HtmlToPdfDocument doc = new HtmlToPdfDocument()
{
	GlobalSettings = {
		PaperSize = PaperKind.A4,
		Orientation = Orientation.Portrait,
		Margins = new MarginSettings() { Top = 10, Left = 10, Right = 10 },
	},
};

// add object settings to the document
foreach (var item in items)
{
	var page = new ObjectSettings()
	{
                // PagesCount must be true to use it on header and footer
		PagesCount = true,
                 // specifying HeaderSettings adds footer
		HeaderSettings = { Center = Guid.NewGuid().ToString(), Line = new Random().Next(100) % 2 == 0, Right = "Page [page] of [toPage]" },
                // specifying FooterSettings adds footer
		FooterSettings = { Center = Guid.NewGuid().ToString(), Line = new Random().Next(100) % 2 == 0, Right = "Page [page] of [toPage]" },
		WebSettings = { DefaultEncoding = "utf-8" },
		HtmlContent = item
	};
	doc.Objects.Add(page);
}

//convert
var pdf = _converter.Convert(doc);

PDF generated from code above.

from dinktopdf.

DaanAcohen avatar DaanAcohen commented on May 15, 2024

Thanks for your quick reply but this does not work work me. I have a

  • string with html content (really one, no list of items I can loop through). There is a lot of content so it covers multiple pages.
  • one header
  • one footer

So I need a method like this:


public MemoryStream GenerateDocument(string aLotOfContentWhichRequiresMultiplePages, string genericHeader, string genericfooter)
{
      // Implementation?
}

from dinktopdf.

rdvojmoc avatar rdvojmoc commented on May 15, 2024

Thanks for clarifying what is your use case. wkhtmltopdf doesn't support HTML strings in Header or Footer settings. For more on this you can check #26 . Stakcoverflow question that you linked talks about print selector. wkhtmltopdf by defaults uses screen selector. You can change this with WebSettings.PrintMediaType=true.

from dinktopdf.

AmbroiseCouissin avatar AmbroiseCouissin commented on May 15, 2024

@sumit0501 We solved it here: #53 (comment)

from dinktopdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.