Skip to content

Forminator: ADD CSS to PDF Generator

add_filter( 'forminator_pdf_basic_template_markup', function( $html, $pdf_settings, $form_id, $entry_id ){

	if ( $form_id !=37063 ) { //Please change the form ID
		return $html;        
	}
	$css = '<style type="text/css" title="text/css" media="screen">

	.forminator-pdf-header.logo-container .pdf-logo {
		text-align:center !important;
		width: 100% !important;
		padding-left: 100px;
	}
	.forminator-pdf-header.logo-container .pdf-logo img {
		height: 140px !important;

	}
	.forminator-pdf-header.logo-container .pdf-title-wrapper {
		display: none !important;
	}
	
	/*
		table.forminator-pdf-header.logo-container {
			width: 100%;
		}
		.pdf-title {
			background: url(https://www.example.com/wp-content/uploads/2023/12/firstlex-pdf-logo.jpg);
			background-size: 1400px;
			height: 150px;
			background-position: center;
			background-repeat: no-repeat;
			text-align: right; 
			font-size: 8px;
			color: #fff !important; /*888*/
		}
	*/
	</style>'; 
	$html = str_replace( '</head>', $css.'</head>', $html );

	//FIX LINEBREAKS
	//https://mpdf.github.io/about-mpdf/limitations.html
	$html = str_replace( '</p>', '</p><br />', $html );

	//DATE
	//setlocale(LC_TIME, 'de_DE');
	//setlocale(LC_TIME, 'de_DE.UTF8');
	//echo strftime('%A').', der '.date('d.m.Y H:i').' Uhr.';
	//setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); //might bring error
	setlocale(LC_ALL, 'de_DE.utf8');
	$time2 = strftime("%e. %B %G", strtotime("now"));
	$html = str_replace( '[date]', $time2, $html ); 
	//echo date(get_option('date_format')); //date('j. F Y');

	/*	
	//ADD CUSTOM SHORTCODE [AKT]
		preg_match("'<p class=\"cpy\">(.*?)</p>'si", $html, $match);
		if( !empty( $match ) ) { 
			$aktenzeichen = date('ymd').'-ST-'.strtoupper(substr($match[1], 0, 3));
			$html = str_replace( '[AKT]', $aktenzeichen, $html );  //231218-ST-ADV
		}

		//ADD CUSTOM IMAGE WITH SHORTCODE {signature-1}

		$html = str_replace( '[sign-kai]', '<img src="https://www.example-cp.com/image.png" class="signature" />', $html );
		$html = str_replace( '[sign-kai]', '', $html );
	*/

	//INTEGRATE REGULAR SIGNATURE AS IMAGE NOT LINK
	if( preg_match_all('/<a[^>]+href=([\'"])(?<href>.+?)\1[^>]*>/i', $html, $img_url ) ){
		if( !empty( $img_url ) ) {
			if( strpos( $img_url['href'][0], 'signatures') !== false ) {
				$file_name = basename( $img_url['href'][0] );
				$html = str_replace( $img_url[0][0].$file_name.'</a>', '<img src="'. $img_url['href'][0] .'" class="signature"/>', $html );
			}
		}
	}

	return $html; //use echo show html or return to create pdf
},10, 4);

//CHANGE PAGINATION TEXT
function change_forminator_pdf_prefix($config, $settings) {
	$config['pagenumPrefix'] = esc_html__( 'Seite ', 'forminator-addons-pdf' );
	$config['nbpgPrefix'] = esc_html__( ' von ', 'forminator-addons-pdf' );
	return $config;
}
add_filter( 'forminator_pdf_config', 'change_forminator_pdf_prefix', 10, 2 );

Dieser Beitrag hat 0 Kommentare

Schreibe einen Kommentar

Deine E-Mail wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

An den Anfang scrollen