Git Product home page Git Product logo

wp-mpdf's Introduction

wp-mpdf

Contributors: fkrauthan
Donate link: fkrauthan.ca
Wordpress plugin page: wordpress.org/plugins/wp-mpdf/
Tags: print, printer, wp-mpdf, pdf, mpdf
Requires at least: 2.9
Tested up to: 6.4.2 Stable tag: 3.8.3

Print Wordpress posts as PDF. Optional with Geshi highlighting.

Description

Print Wordpress posts as PDF. Optional with Geshi highlighting. It also has support for password protected posts and only logged in users can print post as pdf support.

Changelog

3.8.3

  • Fixed deployment of 3.8.2

3.8.2

  • Downgraded psr/log to hopefully fix some runtime errors

3.8.1

  • Fixed deployment of 3.8

3.8

  • Updated mpdf version
  • Removed a file from geshi that could be abused

3.7.1

  • Added missing files to plugin

3.7

  • Updated mpdf to version 8
  • Added mpdf_adjust_settings filter to allow overwriting any mpdf settings

3.6.1

  • Fixed release tag to prevent install issues

3.6

  • Removed manual cron job and used wp-cron instead for cache population (as per wordpress guidelines)
  • Removed PHP 4 support (don't think anyone is running that anymore)

3.5.2

  • Added some small security improvements for the admin page
  • Fixed a PHP notice when "allow to print all pages" is disabled (thanks to grandeljay)

3.5.1

  • Added some small security fixes to the admin page

3.5

  • Added support to change page format inside template (thanks to conlaccento)

3.4

  • Made codebase PHP 7.3 compatible (thanks to nopticon)
  • Fixed issues with newer wordpress versions (thanks to nopticon)

3.3

  • Fixed some small bugs
  • Updated mpdf to version 6
  • Updated geshi to latest version
  • Made plugin compatible with PHP 7

Earlier versions

For the changelog of earlier versions, please refer to the separate changelog.md file.

Installation

  1. Upload the whole plugin folder to your /wp-content/plugins/ folder.
  2. Set write permission (777) to the plugin dir folder => /wp-content/plugins/wp-mpdf/cache
  3. Go to the plugins page and activate the plugin.
  4. Add to your template "<?php if(function_exists('mpdf_pdfbutton')) mpdf_pdfbutton(); ?>" as a small button or "<?php if(function_exists('mpdf_pdfbutton')) mpdf_pdfbutton(false, 'my link', 'my login text'); ?>" as a textlink. The second text specifies the text which should displayed if you have checked "needs login" and a user isn't loggend in. (if you wish to open the pdf print in a new tab you may pass "true" for the first parameter)
  5. You can adjust some options: in your admin interface, click on plugins and then on wp-mpdf. For allowing or disabling pdf export you can use the checkbox when creating/editing a post or a page.
  6. Place your templates into /wp-content/wp-mpdf-themes

The mpdf_pdfbutton function signature: function mpdf_pdfbutton($opennewtab=false, $buttontext = '', $logintext = 'Login!', $print_button = true, $nofollow = false, $options = array())

The options array supports 'pdf_lock_image' => '/my/image/path/relative/to/wordpress/route' and 'pdf_image' => '/my/image/path/relative/to/wordpress/route' to overwrite which icon should be used.

License

This file is part of wp-mpdf.

wp-mpdf is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

wp-mpdf is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with wp-mpdf. If not, see www.gnu.org/licenses/.

Publish to wordpress

Setup svn

You need to install the subversion client on your local system

Commit changes to git

Make sure that all your changes are committed to the repository. The deployment script will stop in case there are uncommitted changes to prevent any mistakes.

Publish new version

You just need to execute the release.sh script. It will take care of some basic validation, and the full publish process.

./release.sh

wp-mpdf's People

Contributors

conlaccento avatar fkrauthan avatar grandeljay avatar nickgreen avatar nopticon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-mpdf's Issues

Function 'mpdf_create_admin_menu' not found

After updating the plugin to Version 3.2.1 I have the following warning:

call_user_func_array() expects parameter 1 to be a valid callback, function 'mpdf_create_admin_menu' not found or invalid function name in /www/.../wp-includes/plugin.php on line 525

Getting the Post image

Good afternoon,

I have been trying to get the post's thumbnail using the the_post_thumbnail(); function and using it in the deafult.php template.
I hasn't worked for me could you help me ?

Thank you

format_to_post deprecated

The file wp-mpdf.php uses a deprecated hook to sanitize the_content. Somewhere around line 264, it calls format_to_post('the_content');

FYI, format_to_post has been deprecated since WP 3.9, and hasn't been in use for a long time before that, so it wasn't really doing anything anyway.

My suggestion is to either get rid of that or replace it with wpdb::prepare()

How to add custom font to PDF?

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?

how to hide

Hello, i try your plugin. It is the only standalone that i found.
I have a probleme, i have au bar on top on all page. I don't understand how hide pdf bar when i 'm not on White List page.

Header & footer html problem

Hi in wp-mpdf.php line 226 :

if ( $pdf_html_header ) { $mpdf->SetHTMLHeader( $pdf_header ); } else { $mpdf->setHeader( $pdf_header ); } if ( $pdf_html_footer ) { $mpdf->SetHTMLFooter( $pdf_footer ); } else { $mpdf->setFooter( $pdf_footer ); }

You use $pdf_header and $pdf_footer in the 2 states of the condition. So $pdf_html_header and $pdf_html_footer are never used.

Thanks for this plugin :)

Regards,

Flex is not working for header

I am currently working on a template for a pdf of a post on Wordpress and I am pretty sure that my css works ( I've built the html/css on a different file) but when implementing it on the header, the FLEX is not working any idea on how to solve it?

Update mpdf

Hey,

I just added it to one of the pages I manage and it worked great, thanks a lot!

When I pushed it to production, I got server errors and the PDF did not render:

PHP Fatal error:  Array and string offset access syntax with curly braces is no longer supported in [...]/wp-content/plugins/wp-mpdf/mpdf/mpdf.php on line 2349

I got this because I use PHP 8. I am now using 7.3 to circumvent this.

I assume this would be fixed if mpdf would be updated, because the currently used version of mpdf (6.1) is pretty old.

I don't know how actively maintained this is and if it's too much to ask. I would look into it myself, but I am currently very short in time and also I don't have very deep php knowledge. I looked into it briefly, but not very deeply but I would love to be able to use a newer PHP version again.

Usage with output buffering

Hi,

I'm trying to do the most straightforward thing I can think of, which is simply output the entire page, as it would in HTML, to PDF.

In trying to achieve this, in wp-content/wp-mpdf-themes/default.php, I'm simply doing a require() of my template for this page type:

<?php 

ob_start();

require_once(dirname(__FILE__).'/../themes/mytheme/single-posttype.php');

ob_flush();

However, something is still breaking wp-mpdf:

mPDF error: Some data has already been output to browser, can't send PDF file

The page is then displayed, in HTML, exactly as it's supposed to, but not as PDF.

What would be the right way to do this? Can I somehow return the output buffer to wp-mpdf as string?

How to make the left content bigger in footer?

I'm generating PDF with this library, it works quite good, but I have a problem with footer. It generates content, but left one is not as I want.

image

In the attached image, I actually put the address for the German one like this:

'L' =>
		array(
			'content' => '<table class="footer" style="width: 600px !important; margin-left: 4px;">
			<tr>
				<td style="width: 100%;">
					<div class="left">
						<p>Metratec GmbH</p>
						<p>Niels-Bohr-Str. 5 | 39106 Magdeburg, Germany</p>
						<p>T: +49 (0)391 251906-00 | F: +49 (0)391 251906-01</p>
						<p>Mail: [email protected] | www.metratec.com</p>
						<br>
						<p>' . $currentDate . ' | ' . $currentHour . '</p>
					</div>
				</td>
			</tr>
			</table>',
			'font-size' => 8,
			'font-style' => 'BI',
			'font-family' => 'EuclidCircularB Regular',
		),

but it moves the city/country name part into the next line. Is it possible to make this part of the footer longer, so it will have no break in my p tags?

My full footer code is like following:

$pdf_footer = array(
	'odd' =>
	array(
		'R' =>
		array(
			'content' => '<img src="https://dev-itoito.io/img/metratec/logo.jpg" alt="logo" style="width: 200px;float:right;" />',
			'font-size' => 8,
			'font-style' => 'BI',
			'font-family' => 'EuclidCircularB Regular',
		),
		'L' =>
		array(
			'content' => '<table class="footer" style="width: 600px !important; margin-left: 4px;">
			<tr>
				<td style="width: 100%;">
					<div class="left">
						<p>Metratec GmbH</p>
						<p>Niels-Bohr-Str. 5 | 39106 Magdeburg, Germany</p>
						<p>T: +49 (0)391 251906-00 | F: +49 (0)391 251906-01</p>
						<p>Mail: [email protected] | www.metratec.com</p>
						<br>
						<p>' . $currentDate . ' | ' . $currentHour . '</p>
					</div>
				</td>
			</tr>
			</table>',
			'font-size' => 8,
			'font-style' => 'BI',
			'font-family' => 'EuclidCircularB Regular',
		),
		'C' =>
		array(
			'content' => '<table class="footer">
			<tr>
				<td style="width: 100%;">
					<div class="left">
						<p>US Office </p>
						<p>Metratec USA</p>
						<p>6 Liberty Square #2073 02109 Boston, MA, United States</p>
						<p>T: +1 (857) 799-3795 | Mail: [email protected] </p>
						<br>
						<p>' . $currentDate . ' | ' . $currentHour . '</p>
					</div>
				</td>
			</tr>
			</table>',
			'font-size' => 8,
			'font-style' => 'BI',
			'font-family' => 'EuclidCircularB Regular',
		),
		'line' => 1,
		'line' => 1,

	),
);

PHP Warnings when I trying to use ul/ol lists in my custom wp-mpdf-theme template

I see a huge number of Warnings in error_log file when I use ul or ol lists in my template layout. Without lists, everything is fine.

[09-Dec-2021 09:24:20 UTC] PHP Warning:  A non-numeric value encountered in /domen/wp-content/plugins/wp-mpdf/mpdf/Tag.php on line 1889
[09-Dec-2021 09:27:11 UTC] PHP Warning:  A non-numeric value encountered in /domen/wp-content/plugins/wp-mpdf/mpdf/Tag.php on line 2003
[09-Dec-2021 09:24:20 UTC] PHP Warning:  A non-numeric value encountered in /domen/wp-content/plugins/wp-mpdf/mpdf/Tag.php on line 2006
[09-Dec-2021 09:27:11 UTC] PHP Warning:  A non-numeric value encountered in /domen/wp-content/plugins/wp-mpdf/mpdf/mpdf.php on line 6387

issue with images

Hi,

I have noticed that the plugin does not seem to handle images well that have a src set that doesn't contain the website URL.

Example:https://www.corelan.be/index.php/2009/07/19/exploit-writing-tutorial-part-1-stack-based-overflows/

The first image (under "Verify the bug") is created as:

<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="/wp-content/uploads/2009/07/image_thumb4.png" width="407" height="172" scale="0">

(the "src" does not contain the website URL)

The resulting PDF file shows these images as "missing"

thanks

PHP 8.0 compatibility issues

Good day sir.

I was just checking to see if all is well with PHP 8.0. I'm getting the following error whenever I update to PHP 8.1. and I can't quite seem to point out the issue. I understand you are one busy man, maybe share with us your to-do list and we will assist.

Error:

Fatal error: Uncaught Mpdf\MpdfException: Data has already been sent to output (/usr/www/users/mintopfwbf/wp-content/themes/jobboard_v2/admin/framework/autoload.php at line 162), unable to output PDF file in /usr/www/users/mintopfwbf/wp-content/plugins/wp-mpdf/vendor/mpdf/mpdf/src/Mpdf.php:9549 Stack trace: #0 /usr/www/users/mintopfwbf/wp-content/plugins/wp-mpdf/wp-mpdf.php(293): Mpdf\Mpdf->Output('manthako.pdf', 'I') #1 /usr/www/users/mintopfwbf/wp-content/plugins/wp-mpdf/wp-mpdf.php(504): mpdf_output(' apply_filters(NULL, Array) #4 /usr/www/users/mintopfwbf/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #5 /usr/www/users/mintopfwbf/wp-includes/template-loader.php(13): do_action('template_redire...') #6 /usr/www/users/mintopfwbf/wp-blog-header.php(19): require_once('/usr/www/users/...') #7 /usr/www/users/mintopfwbf/index.php(17): require('/usr/www/users/...') #8 {main} thrown in /usr/www/users/mintopfwbf/wp-content/plugins/wp-mpdf/vendor/mpdf/mpdf/src/Mpdf.php on line 9549

Category url dosen't work after changing it at wp settings

If you change the category url at the wordpress settings the url printed in the pdf is wrong. It is an issue in the templates:

/mpdf/themes/default.php:144
// FIX! URL-Pfad zu Kategorien fehlt
$cat_links .= '<a href="' . get_bloginfo('home') . '/category/' . $cat->category_nicename . '" title="' . $cat->category_description . '">' . $cat->cat_name . '</a>, ';

Reported by another user

Can not disable "needs login" with PHP 8

Hey,

if I try to disable the checkbox "needs login" in the admin panel, it re-enables itself when I click "save". So, effectively, I can not turn it off. Sometimes, it stays unchecked but after re-loading the page, it is enabled again.

I did not see an error in the logs.

It just happens with PHP 8, with php 7.4 it works fine.

And thanks so much for updating mpdf! It will also be OK for me to use 7.4 for now, just wanted to raise this.

PHP Fatal error after update

PHP Fatal error: Uncaught Error: Class 'Mpdf\Mpdf' not found in /domen/wp-content/plugins/wp-mpdf/wp-mpdf.php:195

It looks like some files were not included in bundle after the update.
(PHP - 7.4, WP - 5.8.2, template - default)

PHP Fatal error - reference to files that don't exist

Hi,

The current version of wp-mpdf throws this error when trying to generate pdf files:

PHP Fatal error: require_once() [function.require]: Failed opening required '/xxxxxxxxxx/wp-content/plugins/wp-mpdf/mpdf/mpdfi/pdf_context.php' (include_path='.:/usr/share/php:/usr/share/pear') in /xxxxxxxxxx/wp-content/plugins/wp-mpdf/mpdf/mpdf.php on line 32335

For some reason I can't seem to find wp-mpdf/mpdf/mpdfi/pdf_context.php on my system

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.