From 4c5ab38bb12a9d646e33012e6ffeb1a2dd560068 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 28 Aug 2025 08:01:59 +1000 Subject: [PATCH] Allow settings X-Axis position --- app/Utils/Traits/Pdf/PDF.php | 23 +++++++++++++++++------ config/ninja.php | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Utils/Traits/Pdf/PDF.php b/app/Utils/Traits/Pdf/PDF.php index 997276284c..d9d79727ef 100644 --- a/app/Utils/Traits/Pdf/PDF.php +++ b/app/Utils/Traits/Pdf/PDF.php @@ -17,6 +17,7 @@ use setasign\Fpdi\Fpdi; class PDF extends FPDI { public $text_alignment = 'L'; + public $x_offset = 0; // New property for X-axis offset public function Footer() { @@ -33,16 +34,26 @@ class PDF extends FPDI // Set Y position $this->SetY(config('ninja.pdf_page_numbering_y_alignment')); + // Calculate X position with offset + $base_x = config('ninja.pdf_page_numbering_x_alignment'); + $x_position = $base_x + $this->x_offset; + // Set X position based on alignment if ($this->text_alignment == 'L') { - $this->SetX(5); - $this->Cell($this->GetPageWidth() - 10, 5, $trans, 0, 0, 'L'); + $this->SetX($x_position); + // Adjust cell width to account for X offset + $cell_width = $this->GetPageWidth() - $x_position - 10; + $this->Cell($cell_width, 5, $trans, 0, 0, 'L'); } elseif ($this->text_alignment == 'R') { - $this->SetX(0); - $this->Cell($this->GetPageWidth(), 5, $trans, 0, 0, 'R'); + $this->SetX($x_position); + // For right alignment, calculate width from X position to right edge + $cell_width = $this->GetPageWidth() - $x_position; + $this->Cell($cell_width, 5, $trans, 0, 0, 'R'); } else { - $this->SetX(0); - $this->Cell($this->GetPageWidth(), 5, $trans, 0, 0, 'C'); + $this->SetX($x_position); + // For center alignment, calculate appropriate width + $cell_width = $this->GetPageWidth() - ($x_position * 2); + $this->Cell($cell_width, 5, $trans, 0, 0, 'C'); } } diff --git a/config/ninja.php b/config/ninja.php index 08f96a7b93..39d2604458 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -257,7 +257,7 @@ return [ 'storecove_email_catchall' => env('STORECOVE_CATCHALL_EMAIL',false), 'qvalia_api_key' => env('QVALIA_API_KEY', false), 'qvalia_partner_number' => env('QVALIA_PARTNER_NUMBER', false), - 'pdf_page_numbering_x_alignment' => env('PDF_PAGE_NUMBER_X', 5), + 'pdf_page_numbering_x_alignment' => env('PDF_PAGE_NUMBER_X', 0), 'pdf_page_numbering_y_alignment' => env('PDF_PAGE_NUMBER_Y', -6), 'hosted_einvoice_secret' => env('HOSTED_EINVOICE_SECRET', null), 'e_invoice_quota_warning' => env('E_INVOICE_QUOTA_WARNING', 15),