TCPDF Performances

Make sure to test your watermarking thoroughly before going live! TCPDF is a fallible third-party library which does its best to parse/understand and re-write your PDF with your desired changes (watermarks/encryption/etc), but it cannot possibly work on all PDFs and on all servers 100% of the time. Stay realistic, think carefully through the process, plan, and do your testing.

PHP Version

You should be running at least PHP version 5.6 for the plugin to work, but higher that for it to work WELL. WordPress recommends you run PHP version 7.2 or higher. Our plugins are PHP version 8.3 compatible, so don’t hesitate to upgrade after making backups. PHP 7.0 is twice as fast for WordPress as PHP 5.6, and processes demands much more efficiently! Updating the PHP version on your server is the first thing you should try if you’re running out of memory while processing PDFs.

Increase Memory

Increase your server’s PHP memory allotment to at least 64MB. We recommend a 128MB, 256MB or maybe even 512MB setting. If your host does not allow more than 16 or 32, it might be a good time to switch hosts or servers. If you expect your PDF to take more than 30 seconds to parse (gasp!), you may also need to increase your PHP max_execution_time.

Performance Tuning

If you have large PDFs, complex watermarks (HTML, images, fonts, encryption) and/or heavy customer traffic, you may also want to upgrade your hosting so you can use more CPUs if necessary. Trying to run this plugin on cheap shared hosting won’t always work out. Keep in mind that your hosting plan needs to be robust enough to support the memory and bandwidth necessary to fulfill PDF manipulation requests in PHP memory. Try these suggestions below to tune for performance. (FYI Thai characters are already disabled in Waterwoo.) Keep your watermarks simple. Avoid HTML and images if possible, use base fonts or fonts subsetted with the fewest characters possible, and remember that file protections/passwording also make huge demands on your server.

Processing PDFs on your server can be CPU-intensive. So if you have big PDFs, complex watermarks, and/or spikes in traffic, it’s possible your site could slow down or crash. If you are having troubles with this, review the information above to minimize memory use and get in touch with your hosting about a possible server upgrade.

Tuning for performance

If you want to use plugins like EDDiMark, WaterWoo or TCPDF Bridge with WordPress on your server, it’s really important that you tune your server so that it can handle the load. There are a lot of factors to account for if you are getting errors while watermarking. Some people bring huge PDFs, some people bring complex PDFs, some people bring complex watermarks, some people bring traffic spikes, some servers bring down time, some people bring a mix of all those factors. The best way to get reliable watermarking is by tuning your setup and performing initial and periodic testing of the setup.

Below are the original recommendations for “performances” of TCPDF (it came down off the web in late 2020 but is still available in the WayBack Machine). I have annotated them for clarification:

  • Install and configure a PHP opcode cacher like XCache
  • Edit the php.ini file and increase the maximum amount of memory a script may consume (memory_limit)
  • Edit the php.ini file and increase the maximum execution time of each script (max_execution_time)
  • Edit the config/tcpdf_config.php file: manually set the $_SERVER[‘DOCUMENT_ROOT’], K_PATH_MAIN and K_PATH_URL constants, and remove the automatic calculation part (not really necessary)
  • If you are not using the Thai language, edit the config/tcpdf_config.php file and set the K_THAI_TOPCHARS constant to false (this is done by default in Little Package plugins)
  • If you do not need UTF-8 Unicode, set the $unicode parameter on TCPDF constructor to false and the $encoding parameter to ‘ISO-8859-1’ or other character map
  • By default TCPDF enables font subsetting to reduce the size of embedded Unicode TTF fonts, this process, that is very slow and requires a lot of memory, can be turned off using setFontSubsetting(false) method
  • Use core fonts (helvetica, times, courier) instead of embedded fonts whenever possible
  • Avoid using the HTML syntax (writeHTML and writeHTMLCell methods) if not strictly required (Little Package plugins try to avoid using writeHTML/writeHTMLCell where possible)
  • Split large HTML blocks in smaller pieces
  • Avoid using transactions if not strictly required (This really won’t apply to most applications using the Little Package plugins)
  • Restart the webserver after server setup changes

(advertisement)