mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 05:44:37 -04:00
Page numbering for PDFs
This commit is contained in:
parent
a2977ef1ad
commit
b6f48c0d8c
@ -17,6 +17,7 @@ use App\Transformers\ActivityTransformer;
|
|||||||
use App\Utils\HostedPDF\NinjaPdf;
|
use App\Utils\HostedPDF\NinjaPdf;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Utils\PhantomJS\Phantom;
|
||||||
|
use App\Utils\Traits\Pdf\PageNumbering;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -27,7 +28,7 @@ use stdClass;
|
|||||||
|
|
||||||
class ActivityController extends BaseController
|
class ActivityController extends BaseController
|
||||||
{
|
{
|
||||||
use PdfMaker;
|
use PdfMaker, PageNumbering;
|
||||||
|
|
||||||
protected $entity_type = Activity::class;
|
protected $entity_type = Activity::class;
|
||||||
|
|
||||||
@ -164,12 +165,35 @@ class ActivityController extends BaseController
|
|||||||
|
|
||||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||||
$pdf = (new Phantom)->convertHtmlToPdf($html_backup);
|
$pdf = (new Phantom)->convertHtmlToPdf($html_backup);
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
elseif(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||||
$pdf = (new NinjaPdf())->build($html_backup);
|
$pdf = (new NinjaPdf())->build($html_backup);
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$pdf = $this->makePdf(null, null, $html_backup);
|
$pdf = $this->makePdf(null, null, $html_backup);
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $activity->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($activity->invoice_id)) {
|
if (isset($activity->invoice_id)) {
|
||||||
|
@ -191,7 +191,6 @@ class InvitationController extends Controller
|
|||||||
return response()->json(["message" => "no record found"], 400);
|
return response()->json(["message" => "no record found"], 400);
|
||||||
|
|
||||||
$file_name = $invitation->{$entity}->numberFormatter().'.pdf';
|
$file_name = $invitation->{$entity}->numberFormatter().'.pdf';
|
||||||
nlog($file_name);
|
|
||||||
|
|
||||||
$file = CreateRawPdf::dispatchNow($invitation, $invitation->company->db);
|
$file = CreateRawPdf::dispatchNow($invitation, $invitation->company->db);
|
||||||
|
|
||||||
|
@ -190,15 +190,22 @@ class CreateEntityPdf implements ShouldQueue
|
|||||||
|
|
||||||
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
if(config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja'){
|
||||||
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||||
|
|
||||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity Ninja (https://entityninja.com).
|
* Entity Ninja (https://entityninja.com).
|
||||||
*
|
*
|
||||||
@ -34,6 +33,7 @@ use App\Utils\PhantomJS\Phantom;
|
|||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use App\Utils\Traits\Pdf\PageNumbering;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -46,7 +46,7 @@ use Illuminate\Support\Facades\Storage;
|
|||||||
|
|
||||||
class CreateRawPdf implements ShouldQueue
|
class CreateRawPdf implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash, PageNumbering;
|
||||||
|
|
||||||
public $entity;
|
public $entity;
|
||||||
|
|
||||||
@ -177,11 +177,22 @@ class CreateRawPdf implements ShouldQueue
|
|||||||
if($finfo->buffer($pdf) != 'application/pdf; charset=binary')
|
if($finfo->buffer($pdf) != 'application/pdf; charset=binary')
|
||||||
{
|
{
|
||||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
$pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true));
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -49,8 +49,11 @@ class PreviewPdf implements ShouldQueue
|
|||||||
{
|
{
|
||||||
$pdf = $this->makePdf(null, null, $this->design_string);
|
$pdf = $this->makePdf(null, null, $this->design_string);
|
||||||
|
|
||||||
$pdf = $this->pageNumbering($pdf, $this->company);
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
return $pdf;
|
return $pdf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,9 @@ class PaymentNotification implements ShouldQueue
|
|||||||
|
|
||||||
$analytics_id = $company->google_analytics_key;
|
$analytics_id = $company->google_analytics_key;
|
||||||
|
|
||||||
|
if(!strlen($analytics_id) > 2)
|
||||||
|
return;
|
||||||
|
|
||||||
$client = $payment->client;
|
$client = $payment->client;
|
||||||
$amount = $payment->amount;
|
$amount = $payment->amount;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
|||||||
use App\Utils\CurlUtils;
|
use App\Utils\CurlUtils;
|
||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Utils\Traits\Pdf\PageNumbering;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use Illuminate\Support\Facades\Response;
|
use Illuminate\Support\Facades\Response;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
@ -33,7 +34,7 @@ use Illuminate\Support\Str;
|
|||||||
|
|
||||||
class Phantom
|
class Phantom
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash, PageNumbering;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a PDF from the
|
* Generate a PDF from the
|
||||||
@ -99,6 +100,12 @@ class Phantom
|
|||||||
|
|
||||||
$this->checkMime($pdf, $invitation, $entity);
|
$this->checkMime($pdf, $invitation, $entity);
|
||||||
|
|
||||||
|
$numbered_pdf = $this->pageNumbering($pdf, $invitation->company);
|
||||||
|
|
||||||
|
if($numbered_pdf)
|
||||||
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
|
|
||||||
if(!Storage::disk(config('filesystems.default'))->exists($path))
|
if(!Storage::disk(config('filesystems.default'))->exists($path))
|
||||||
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||||
|
|
||||||
|
@ -20,14 +20,11 @@ class PDF extends FPDI
|
|||||||
|
|
||||||
function Footer()
|
function Footer()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->SetXY(0, -5);
|
$this->SetXY(0, -5);
|
||||||
|
|
||||||
$this->SetFont('Arial','I', 9);
|
$this->SetFont('Arial','I', 9);
|
||||||
$this->SetTextColor(135,135,135);
|
$this->SetTextColor(135,135,135);
|
||||||
|
|
||||||
$trans = ctrans('texts.pdf_page_info', ['current' => $this->PageNo(), 'total' => '{nb}']);
|
$trans = ctrans('texts.pdf_page_info', ['current' => $this->PageNo(), 'total' => '{nb}']);
|
||||||
|
|
||||||
$this->Cell(0,5, $trans ,0,0, $this->text_alignment);
|
$this->Cell(0,5, $trans ,0,0, $this->text_alignment);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,10 @@ trait PageNumbering
|
|||||||
{
|
{
|
||||||
private function pageNumbering($pdf_data_object, $company)
|
private function pageNumbering($pdf_data_object, $company)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// if(!$company->settings->page_numbering)
|
||||||
|
// return $pdf_data_object;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$pdf = new PDF();
|
$pdf = new PDF();
|
||||||
@ -39,9 +42,8 @@ trait PageNumbering
|
|||||||
|
|
||||||
$pdf->useTemplate($tplId);
|
$pdf->useTemplate($tplId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_end_flush();
|
return $pdf->Output('S');
|
||||||
return $pdf->Output();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(\Exception $e) {
|
catch(\Exception $e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user