Skip to content

Commit

Permalink
#180 Shift bottom margin by powered by line height
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacelord-XaN committed Apr 24, 2021
1 parent 567287e commit 168371b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/BraunauMobil.VeloBasar/Printing/PageFooterHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BraunauMobil.VeloBasar.Resources;
using BraunauMobil.VeloBasar.Models;
using BraunauMobil.VeloBasar.Resources;
using iText.IO.Font.Constants;
using iText.Kernel.Events;
using iText.Kernel.Font;
Expand All @@ -10,11 +11,15 @@ namespace BraunauMobil.VeloBasar.Printing
{
public class PageFooterHandler : IEventHandler
{
public const float Height = 6;

private readonly Margins _pageMargins;
private readonly Document _doc;
private readonly IStringLocalizer<SharedResource> _localizer;

public PageFooterHandler(Document doc, IStringLocalizer<SharedResource> localizer)
public PageFooterHandler(Margins pageMargins, Document doc, IStringLocalizer<SharedResource> localizer)
{
_pageMargins = pageMargins;
_doc = doc;
_localizer = localizer;
}
Expand All @@ -27,8 +32,8 @@ public void HandleEvent(Event ev)
var pageNumber = docEvent.GetDocument().GetPageNumber(page);
var canvas = new PdfCanvas(page);
canvas.BeginText();
canvas.SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.HELVETICA), 6);
canvas.MoveText(_doc.GetLeftMargin(), 10);
canvas.SetFontAndSize(PdfFontFactory.CreateFont(StandardFonts.HELVETICA), Height);
canvas.MoveText(_doc.GetLeftMargin(), _pageMargins.Bottom);
canvas.ShowText(_localizer["Seite {0} von {1}", pageNumber, docEvent.GetDocument().GetNumberOfPages()]);
canvas.ShowText(" - powered by https://github.com/braunau-mobil/velo-basar");
canvas.EndText().Release();
Expand Down
4 changes: 2 additions & 2 deletions src/BraunauMobil.VeloBasar/Printing/PdfPrintService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private byte[] CreateTransactionPdf(PrintSettings settings, Action<PdfDocument,
{
pdfDoc.SetDefaultPageSize(pageSize: PageSize.A4);
doc.SetFont(PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN));
doc.SetMargins(settings.PageMargins.Top, settings.PageMargins.Right, settings.PageMargins.Bottom, settings.PageMargins.Left);
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, new PageFooterHandler(doc, _localizer));
doc.SetMargins(settings.PageMargins.Top, settings.PageMargins.Right, settings.PageMargins.Bottom + PageFooterHandler.Height, settings.PageMargins.Left);
pdfDoc.AddEventHandler(PdfDocumentEvent.END_PAGE, new PageFooterHandler(settings.PageMargins, doc, _localizer));

decorate(pdfDoc, doc);
});
Expand Down

0 comments on commit 168371b

Please sign in to comment.