Explorar o código

:octocat: QRFpdf::dump(): allow using external FPDF instance

smiley hai 1 ano
pai
achega
b9688a0862
Modificáronse 1 ficheiros con 6 adicións e 4 borrados
  1. 6 4
      src/Output/QRFpdf.php

+ 6 - 4
src/Output/QRFpdf.php

@@ -110,7 +110,10 @@ class QRFpdf extends QROutputAbstract{
 	 * Initializes an FPDF instance
 	 */
 	protected function initFPDF():FPDF{
-		return new FPDF('P', $this->options->fpdfMeasureUnit, $this->getOutputDimensions());
+		$fpdf =  new FPDF('P', $this->options->fpdfMeasureUnit, $this->getOutputDimensions());
+		$fpdf->AddPage();
+
+		return $fpdf;
 	}
 
 	/**
@@ -118,9 +121,8 @@ class QRFpdf extends QROutputAbstract{
 	 *
 	 * @return string|\FPDF
 	 */
-	public function dump(string $file = null){
-		$this->fpdf = $this->initFPDF();
-		$this->fpdf->AddPage();
+	public function dump(string $file = null, FPDF $fpdf = null){
+		$this->fpdf = ($fpdf ?? $this->initFPDF());
 
 		if($this::moduleValueIsValid($this->options->bgColor)){
 			$bgColor          = $this->prepareModuleValue($this->options->bgColor);