MP_Email::generatePDF( array $pdf_data, string $pdf_file )

Function generate PDF.


Parameters Parameters

$pdf_data

(array) (Required) calculate data

$pdf_file

(string) (Required) pdf file name


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: mortgage-platform/Inc/MP_Email.php

	public function generatePDF( $pdf_data, $pdf_file ) {

		$pdf = new MP_MortgagePDF( PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false );

		$pdf->SetCreator( PDF_CREATOR );
		$pdf->SetAuthor( 'by ...' );
		$pdf->SetTitle( 'Mortgage Calculator' );
		$pdf->SetSubject( 'Mortgage Calculator' );
		$pdf->SetKeywords( 'Mortgage, Calculator, PDF' );

		$pdf->SetHeaderData(
			PDF_HEADER_LOGO,
			PDF_HEADER_LOGO_WIDTH,
			PDF_HEADER_TITLE . ' 001',
			PDF_HEADER_STRING,
			array( 0, 64, 255 ),
			array( 0, 64, 128 )
		);

		$pdf->setFooterData( array( 0, 64, 0 ), array( 0, 64, 128 ) );

		$pdf->setHeaderFont( array( PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN ) );
		$pdf->setFooterFont( array( PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA ) );

		$pdf->SetDefaultMonospacedFont( PDF_FONT_MONOSPACED );

		$pdf->SetMargins( PDF_MARGIN_LEFT, 20, PDF_MARGIN_RIGHT );
		$pdf->SetHeaderMargin( 0 );
		//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
		//$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
		$pdf->SetFooterMargin( PDF_MARGIN_FOOTER );

		$pdf->SetAutoPageBreak( true, PDF_MARGIN_BOTTOM );

		$pdf->setImageScale( PDF_IMAGE_SCALE_RATIO );

		$pdf->setCellPaddings( 5, 10, 5, 10 );

		$pdf->setFontSubsetting( true );

		if ( isset( $this->options_email['ltr_to_rtl'] ) && 'ltr_to_rtl' === $this->options_email['ltr_to_rtl'] ) {
			$pdf->setRTL( true );
		} else {
			$pdf->setRTL( false );
		}

		$pdf_font = MP_Settings::is_isset( $this->options_email['fonts_pdf'], 'helvetica' );

		$pdf_font_size = MP_Settings::is_isset( $this->options_email['fonts_pdf_size'], 8 );

		$pdf->SetFont( $pdf_font, '', $pdf_font_size, '', true );

		$pdf->AddPage();

		$pdf->setTextShadow(
			array(
				'enabled'    => false,
				'depth_w'    => 0.2,
				'depth_h'    => 0.2,
				'color'      => array( 196, 196, 196 ),
				'opacity'    => 1,
				'blend_mode' => 'Normal',
			)
		);

		$html = $this->get_pdf_content( $pdf_data );

		$pdf->writeHTMLCell( 0, 0, '', '', $html, 0, 1, 0, true, '', true );

		// write it to a file for attaching
		$upload_dir = wp_upload_dir();
		// upload directory folder creation
		$calc_dir = $upload_dir['basedir'] . '/calc_pdf';
		if ( ! file_exists( $calc_dir ) ) {
			wp_mkdir_p( $calc_dir );
		}

		$pdf->Output( $pdf_file, 'F' );

		$pdf_created = true;

		return $pdf_created;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.