Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add custom font to PDF? #28

Closed
nijatmursali opened this issue May 24, 2023 · 1 comment
Closed

How to add custom font to PDF? #28

nijatmursali opened this issue May 24, 2023 · 1 comment

Comments

@nijatmursali
Copy link

Hello,

I'm currently working on a project and using this WordPress plugin. It works perfectly fine and I'm able to generate PDF with selected theme which is basically PHP code that includes HTML and CSS. I want to change the font family to custom one like:

body {
	padding: 0;
	margin: 0;
	height: 100%;
	width: 100%;
	font-family: "EuclidCircularB Regular";
}

but it does not work. The font is installed and added correctly. Is there any way to add this custom font to PDF?

My PDF generation code looks like this:

if (have_posts()) :
	while (have_posts()) : the_post();
		$relative_url = untrailingslashit(ABSPATH) . wp_make_link_relative(get_the_post_thumbnail_url());
		$pdf_output .= pdf_header();
		$pdf_output .= pdf_images($relative_url);
		// $pdf_output .= pdf_additional_images();
		$pdf_output .= pdf_description(the_title('', '', false), $post);
		$pdf_output .= pdf_header_next();

		$blocks = parse_blocks($post->post_content);

		$specifications = '';
		foreach ($blocks as $block) {
			if ('acf/metratec-specifications' === $block['blockName']) {
				$specifications .= render_block($block);
			}
		}

		$pdf_output .= pdf_specifications($specifications);
		$similar = '';
		foreach ($blocks as $block) {
			if ('acf/metratec-related-products' === $block['blockName']) {
				$similar .= render_block($block);
			}
		}

		$pdf_output .= pdf_similar($similar);
		$pdf_output .= pdf_ending();

	endwhile;

Functions are basically returning HTML content as a string. Is there any way to specify the specific font?

@fkrauthan
Copy link
Owner

You need to follow the mpdf instructions for adding custom fonts. I also recommend to use the mpdf_adjust_settings filter to modify the mpdf instance and to call the AddFontDirectory method (as if you place the font file inside the plugin folder it would be overwritten during an update).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants