2

I am trying to put a copyright symbol at the bottom of each page when the PDF is generated but I cant seem to get it to work. How would I go about doing such a thing? I am using HtmlRenderer and PDFsharp, take my HTML body and convert it to a PDF file that the user can download.

I don't want to put a watermark over the top as it is a legal document for paying customers, I just wanted the little copyright symbol company name and date at the bottom.

Is there a way of saying to PDFsharp to use a say template PDF file that has a footer with the info at the bottom or is there a way of setting it in the physical code?

andy wilson
  • 665
  • 3
  • 11
  • 34

3 Answers3

2

I Worked it out if you add styling position:fixed and then a top position because it doesnt understand bottom it will add a text to every page wherever you align it to.

andy wilson
  • 665
  • 3
  • 11
  • 34
2

If anyone would like more information on this I've linked a pull request which details the use of position: fixed to create header/footers.

There is also a class in the generator itself PdfGenerateConfig which will allow you to create corresponding margins in the document.

https://github.com/ArthurHub/HTML-Renderer/pull/41

dkaramazov
  • 184
  • 1
  • 9
1

I don't know if HtmlRenderer allows to add headers and footers that will be repeated on every page. HtmlRenderer is not part of PDFsharp.

With PDFsharp it is simple to open a document, loop through the pages and draw a string at the bottom of each page.
The Watermark sample can be used to get started - just remove the Transformation part and draw the text at the bottom of the page.

Similarly you can draw a PDF page (template) over each page of an existing PDF document.

A third option: Draw the text on an XForm and draw that XForm on each page. Overkill for a simple text string, but could reduce file size for a complex footer.

Watermark sample:
http://pdfsharp.net/wiki/Watermark-sample.ashx

XForms sample:
http://pdfsharp.net/wiki/XForms-sample.ashx

  • The XForms solution worked for me to add text and images to the page footer. Ideally I would've preferred the CSS position solution to keep this presentation aspect within the HTML but unfortunately that did not work for me. I tried a few templates (using valid XHTML, HTML5, etc.) with no luck. – jcruz May 20 '18 at 18:19