Giter VIP home page Giter VIP logo

wp-pdf-templates's Introduction

WordPress PDF Templates

Latest Stable Version Total Downloads Latest Unstable Version License

This plugin creates a URL endpoint for WordPress e.g. /my-post/pdf/ that generates a downloadable PDF file.

Installation

The Composer Way (preferred)

Install the plugin via Composer

composer require anttiviljami/wp-pdf-templates

Activate the plugin

wp plugin activate wp-pdf-templates

The Old Fashioned Way

This plugin is available on the official WordPress.org plugin directory.

You can also install the plugin by directly uploading the zip file as instructed below:

  1. Download the plugin
  2. Upload to the plugin to /wp-content/plugins/ via the WordPress plugin uploader or your preferred method
  3. Activate the plugin

Screenshots

Plugin used on the Vetrospace.com website

Vetrospace

wp-pdf-templates's People

Contributors

anttiviljami avatar onnimonni avatar ottok avatar tnottu 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-pdf-templates's Issues

Can't get my template to be used by the plugin

Even if my theme contains a single-wine.php file, i copied the file and renamed it single-wine-pdf.php and still the plugins displays the default template... did i miss something ?

Otherwise great plugin, i'm building something that works with it :)

Any know plugin conflicts? Plugin suddenly stopped working...

Hi,

I was using your plugin effectively for the last 3 months, but suddenly (yesterday?) whenever I try to generate a pdf via the url endpoint I get a 502 server response because it times out.

Are there any known plugin conflicts. The site I'm using this on is in active development so there have been many plugins installed and tested over the last week alone.

The problem is that I have not seen anything in my error logs regarding the pdf plugin, so I have no clue as to what's going on.

I know it's a long shot, but I just thought I'd ask if you have heard of any plugin conflicts out there?

Thanks in advance,

  • Colin

Not working with custom post type

Hi, if you have a minute...
I solved some minoor issues with this plugin.
Seems that is not working with custom post type

https://mywebsite.com/post-title/pdf works as espected
https://mywebsite.com/category/category-title/pdf doesn't works

I tried:

 ```
   if( empty( $html ) ) {
        // if all else fails, try the public site url (not localhost)
        //$link = get_the_permalink();
        $link = get_post_permalink;
        $link = $link . (strpos($link, '?') === false ? '?' : '&') . 'pdf-template';
        $html = file_get_contents( $link , false, $context );
   }

but it doesn't work. Any idea?
Thanks

on managed hosting, pdfs return blank even though file_get_contents, curl, and permissions are ok

@anttiviljami hi - i know this is not your main gig and that you don't use this much these days.

i have spent tons of time trying to solve this issue.

i read all the forums posts on WP, and a lot of stackoverflows about this.

i have this working just fine on a VPS, on several websites, with the same hosting company (MT), exact same code.
on MANAGED HOSTING, the PDF returns blank. the error logs show nothing I can solve:

errors.zip
errors.log

i was told by the hosting's support that this can't work on this type of hosting, but i didn't believe it since file_get_content works, curl works, and i actually managed to generate a pdf with this test file:

<?php

	$test = file_get_contents('https://DOMAIN_NAME_REMOVED/professionals/erica-wolff/pdf-preview', false);
	require_once 'wp-content/plugins/wp-pdf-templates/vendor/autoload.php';

    $dompdf = new Dompdf\Dompdf();

	define("DOMPDF_ENABLE_HTML5PARSER", true);

	$dompdf->loadHtml($test);
	
	// Render the HTML as PDF
	$dompdf->render();

	// Output the generated PDF to Browser
	// stream(filename [without .pdf], 1 compress, 1 force save dialog)
	$dompdf->stream('/var/www/wp-content/test123f.pdf',array('compress'=>0,'attachment'=>1));

?>

...going around all the Wordpress stuff found in the actual plugin.

the result is very close the functioning one we have on our dev server, but only if i try to read from -template, from -preview it fails.

test123f.pdf (16).pdf

what i am asking is this:

  • obviously dompdf works on this environment
  • i am able to generate a pdf with the layout that we want from the wordpress post
  • /pdf-template and /pdf-preview work fine
  • the pdf is blank, the stream part is blank, i attached it if someone speaks PDF :D

if anybody has any insight on how to solve this, i would be grateful. i tried swapping dompdf versions, i tried outputting just the default template that comes with the plugin, i tried debugging verbosely... (by the way, how to get the same output as the debugger found on http://eclecticgeek.com/dompdf/debug.php ? the one that shows dependencies? i wasn't able to do that

i am able to generate basic pdfs with just things like "hello world" — what fails is when i try to read content from an html.

if anybody has had experience with that and solved it, i am willing to try your solution!

my guess is that the managed hosting restrictions prevent from reading or writing the temp file

i have to disable cache to make my test work, and the font cache folder never gets the .inc file or the font files.

happy to jump on a discord if you want to check this out with me, i am totally stuck.

thanks!

Generating all the posts in one pdf

Hi,
The plugin is awesome and great to work with. :)
I am having this small issue maybe I did something wrong. Whenever I try to generate the post as pdf by default it converts all the posts to pdf. I am using plain permalink for my website. When I tested in localhost its works like charm but when I moved to server I get this bug. Can you please let me know what I did wrong here.
Wordpress version - 5.2.4
Server architecture - Linux 3.10.0-1062.1.2.el7.x86_64 x86_64
Web server - Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.40
PHP version - 5.6.40 (Supports 64bit values)
PHP SAPI - apache2handler

Thanks,

Please update dompdf

I added this plugin to an empty Wordpress instance and tested it with PHP 8.1. It worked without issues. However, another project that had this plugin already, broke down with PHP 8.1. The issue has to do with dompdf trying to pass a null value as an argument to file_get_contents. I do not know why the issue presents itself in one instance and not the other, since the dompdf version is supposed to be the same in both. However, the issue is very easily fixed by just updating the packages.

Localhost misconfigured leading to blank PDFs

On shared hosting, localhost is often not configured correctly so it does not actually allow the writing of the PDF, leading to blank PDFs. The fix in this PR:
3a3c126

is not sufficient because $html is not empty, but localhost is not writable, so the PDF will not work.

404 Error

Hello,
I am getting 404 error when trying to access /pdf/

Can someone help me determine what is the issue as there is no errors in error_log.

(cookies enabled, cache disabled, support for post, page and custom post type added)

Test URL: http://sumodev.org/aphroditehomes/about-us/pdf/

intermittent failed http requests for file_get_contents

I was having a problem where certain browsers (mostly older browsers and Edge) were getting blank documents. The logged error indicated it was something to do with bad http requests. I was able to solve the issue by moving from file_get_contents to curl_get_contents. Can I submit a pull request with this option included?

WPML integration

This is not an issue but looking for some advice. I am using WPML translation plugin for my pages and I am having a difficult time generating the PDF for different languages.

I am looking for the best way to modify the plugin using a filter, if possible, without modifying the default code. But, if that is the only way that's fine too.

I am using a customized template added to my child theme's root folder index-pdf.php. The custom template works perfectly for displaying all my CPT information. Only problem is with getting the correct language.

So, if the URL for a translated page is something like this:
https://example.com/mypage/?lang=fr // french translation

currently my custom link in my button to the PDF generator looks like this (doesn't work though obviously):
https://example.com/mypage/pdf/?lang=fr

I am unable to $_GET the current language from my custom template, index-pdf.php. The only url param that exists at this point is the "pdf-template". Also, when referencing the current $post and ID, it thinks it's the default language's, "English in this case", not the current language French.

What can be done to get in front of the query var 'pdf' to add some information about the current language of the page, possibly add the language before /pdf/:
`https://example.com/mypage/fr/pdf/

Any help is appreciated if I can't figure this out I will need to manually create 100's of PDF's in different languages so hoping there is way.

Protected Content Solution (something other than FETCH_COOKIES_ENABLED)

Please reference this issue for some back story.

The issue began when PDF Templates stopped working in conjunction with a support plugin called Awesome Support. Eventually we were able to narrow it down to the following line which was added to my wp-config file in order to grant the PDF plugin access to restricted content:

define('FETCH_COOKIES_ENABLED', true);.

I have premium content which is restricted by a Woocommerce extension called Memberships.

Before implementing the suggested define('FETCH_COOKIES_ENABLED', true); line in my wp-config file, the PDF Templates plugin could not access the content, because it does not inherit the current user. The above line successfully allowed PDF Templates to access the content, BUT with the Awesome Support plugin installed, for some reason that same line caused any PDF request to time out and get a 502 response from the server. We tested this in multiple environments, and even though we weren't able to understand why that line causes that behavior, we were able to isolate the issue to that one line.

So we need another solution for granting the PDF Templates plugin access to the restricted content. Perhaps there is another method of passing the current user role to the plugin?

Unfortunately I don't quite understand how this all works, so I'm really hoping you can offer some advice on how to get around the above issue.

To summarize:

I need the members of my site to be able to export certain restricted pages and post type as PDFs, but I can't use the FETCH_COOKIES_ENABLED solution, because it breaks the PDF functionality when the Awesome Support plugin is enabled.

Let me know what you think.

Thanks in advance!

  • Colin

tfoot not rendered properly

Was trying to convert a html to pdf and noticed this bug,

I have table with thead, tfoot and tbody, as i know thead and tfoot should be repeated if i have multiple pdf pages. Thead works very well, its where it should be on every page on top. Problem is the tfoot, if i place tfoot after thead between and before tbody, the footer shows on top and only on the first page. If i place it after tbody it shows at the end of the pdf document and its not repeating. Is this a plugin issue or i should report this problem at dompdf guys?

Btw, this plugin is awesome,
Thanks

WordPress PDF Templates 'DOMPDF_Exception'

This error occurs in production server the same works fine in local server.
Please do the needful ASAP.

Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Requested HTML document contains no data.' in /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/dompdf/include/frame_tree.cls.php:122 Stack trace: /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/dompdf/include/dompdf.cls.php(676): Frame_Tree->build_tree() /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/dompdf/include/dompdf.cls.php(846): DOMPDF->_process_html() /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php(332): DOMPDF->render() /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php(239): _print_pdf('') [internal function]: _use_pdf_template('') /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-includes/plugin.php(496): call_user_func_array('_use_pdf_templa...', Array) /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-includes/temp in /home/vol12_6/byethost8.com/b8_16145668/htdocs/wp-content/plugins/wp-pdf-templates/dompdf/include/frame_tree.cls.php on line 122

Caching issues

@anttiviljami

I discovered an issue with the caching functionality.

First of all the post title needs to sanitized, or the post permalink should be used when creating the cached filename, otherwise, special characters in the post title (like /) will cause issues with the file_put_contents function (because it ends up trying to put the contents into multiple directories that do not exist).

But also, if cookies are enabled, allowing me to query $user info and restrict content based on user role, BUT caching is also enabled, the cached file gets served to the user, regardless of their role.

I would like to propose the addition of another configuration setting to the plugin which would restrict PDF templates only to logged in users, or only to users of a certain role/capability.

It could look something like this:

Add Conditional to PDF Templates function _use_pdf_template() to check if user is logged in:
i.e.

if ( isset($wp_query->query_vars['pdf-template']) && is_user_logged_in() && current_user_can('manage_options') ) {
    //... normal functionality runs
} else {
    // Redirect them to the my-account/login page:
    wp_redirect( home_url() . '/my-account/' ); 
    exit;
}

Let me know what you think about that. I'd love for there to be a filter for this, allowing me to turn on/off the restriction in my theme's functions, rather than having to edit the plugin files.

a proper way to override _locate_pdf_template

Dear Viljami, thanks for a great plug-in! It rocks.
Not really an issue. But how would you suggest to intercept add_filter('template_include', '_locate_pdf_template') to return same fixed path no matter what?

This is how i'm doing it now – theme's functions.php:

// PDF template handling
add_filter('template_include', 'theme_locate_pdf_template', 11);
function theme_locate_pdf_template($template) {
	global $wp_query;
	if (isset($wp_query->query_vars['pdf-template'])) {
		$template = get_template_directory() . '/pdf/pdf.php'; 		
	}
	return $template;
}

Can't display image in pdf-template?

No matter how i try i can't get a image to show in the PDF.
Or rather: When i try to include an image my PDF fails to open.
There is a error message saying "Fel, Det gick inte att läsa in PDF-dokumentet.", meaning "Error, unable to open the PDF document.".

Is there still any support for this plugin, cuz i don't think i will be able to solve it by my own. :(

No matching package

Hello!

Thanks for a great plugin.

Seems like composer.json needs to be updated from "dev-develop" to "develop":
Your requirements could not be resolved to an installable set of packages.

Problem 1
- anttiviljami/wp-pdf-templates 1.4.3 requires dompdf/dompdf dev-develop -> no matching package found.
- anttiviljami/wp-pdf-templates 1.4.2 requires dompdf/dompdf dev-develop -> no matching package found.
- anttiviljami/wp-pdf-templates 1.4.1 requires dompdf/dompdf dev-develop -> no matching package found.
- anttiviljami/wp-pdf-templates 1.4 requires dompdf/dompdf dev-develop -> no matching package found.
- Installation request for anttiviljami/wp-pdf-templates ^1.4 -> satisfiable by anttiviljami/wp-pdf-templates[1.4, 1.4.1, 1.4.2, 1.4.3].

update to latest dompdf and/or accommodate special characters

hi all,

thanks for a great plugin @anttiviljami — too bad this isn't interesting to you anymore as it seems some of us rely on it ;)

So — I tried to pull this and composer update the dependencies but the result is a big'ole blank pdf :P

anybody else here try to do that? too bad it's not up to date.

my real issue: I can't get   or similar to show up in the PDF, even though it works well in the HTML version of the PDF (if I trick my build to show me the HTML instead of the PDF, I see those characters just fine).

I wondered if this was an issue with the version of DomPDF, since the docs say that after .8 it got even better handling that type of thing. But I can't be sure.

I would love to hear what you all think/found in dealing with special characters like nbsp or no-break dashes, or even international fonts (Japanese, emoji, etc...)

thank you!

Fatal error causing 504 Gateway Time-Out -- Allowed memory bytes exhausted

So I'm using this plugin on my site but today when I visited the site I got a 504 Gateway Time-out error.

I contact my hosting provider ( Flywheel ) and asked them to do some debugging. When they poked around they found this in the logs as the culprit:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 130968 bytes) in /www/wp-content/plugins/wp-pdf-templates/vendor/dompdf/dompdf/src/LineBox.php on line 161

Since this occurred in your plugin I'm not sure if this is a bug on your end or if the way we're using your plugin is the cause, here.

Let me know if you need more details.

PHP warning on plugin activation

Hi! The plugin works fine, but on activation it spews some warnings, here's a trace:

[28-Sep-2016 08:15:01 UTC] PHP Warning:  copy(/app/htdocs/wp-content/plugins/wp-pdf-templatesvendor/dompdf/dompdf/lib/fonts/dompdf_font_family_cache.dist.php): failed to open stream: No such file or directory in /app/htdocs/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 173
[28-Sep-2016 08:15:01 UTC] PHP Stack trace:
[28-Sep-2016 08:15:01 UTC] PHP   1. {main}() /app/htdocs/wordpress/wp-admin/plugins.php:0
[28-Sep-2016 08:15:01 UTC] PHP   2. activate_plugin() /app/htdocs/wordpress/wp-admin/plugins.php:42
[28-Sep-2016 08:15:01 UTC] PHP   3. do_action() /app/htdocs/wordpress/wp-admin/includes/plugin.php:591
[28-Sep-2016 08:15:01 UTC] PHP   4. call_user_func_array:{/app/htdocs/wordpress/wp-includes/plugin.php:524}() /app/htdocs/wordpress/wp-includes/plugin.php:524
[28-Sep-2016 08:15:01 UTC] PHP   5. _init_dompdf_fonts() /app/htdocs/wordpress/wp-includes/plugin.php:524
[28-Sep-2016 08:15:01 UTC] PHP   6. copy() /app/htdocs/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php:173

Perhaps more scary from a regular user's perspective is that when activating the plugin WP gives an error like this:
"Lisäosa loi 2924 odottamatonta merkkiä käyttöönoton yhteydessä. Jos havaitset “headers already sent” viestejä, ongelmia syötteiden kanssa tai muita ongelmia ota lisäosa pois käytöstä tai poista se."
Screenshot: https://www.dropbox.com/s/v6ee11af7dgq2gm/Screenshot%202016-09-28%2011.18.47.png?dl=0

Plugin Conflicts (Easy Digital Downloads, and Awesome Support)

@anttiviljami
Hi again Antti,

I wanted to let you know that the developer of the Awesome Support plugin continued to troubleshoot the issue of your PDF templates not working when FETCH_COOKIES_ENABLED was set to true.

Please read this thread to better understand what I am referring to.

The consensus seems to be that it is an issue with how your plugin handles PHP Sessions. He actually couldn't get your plugin to work AT ALL on his site, whether or not FETCH_COOKIES_ENABLED was defined. He eventually discovered that it was a conflict between your plugin and Easy Digital Downloads (EDD), which is an extremely well known, popular, and quality plugin. So I thought you might want to look into this issue.

He provided a very temporary and "messy" fix, which you can see in the above-linked thread. It may help you to understand the root of the problem.

Pleas take a look and see if you can make a fix ASAP. I would really like to be able to use both your plugin as well as the Awesome Support plugin.

Thanks!

Use media type print

Hello,

how can I set dompdf to use media type print?

@media print {
   …
}

I tried to find list of options, but couldn't find them.

btw. thanks for the plugin, works really nice :)

Plugin could not be activated

I have downloaded the plugin directly from GIT, installed to the plugins upload directory and tried to activate.

Warning: require_once(vendor/autoload.php): failed to open stream: No such file or directory in /home/fuldemo/public_html/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 167

Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /home/fuldemo/public_html/wp-content/plugins/wp-pdf-templates/wp-pdf-templates.php on line 167

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.