WP TCPDF Bridge Documentation

This fairly simple plugin allows you to use TCPDF in Wordpress to alter PDF files, in three main ways:

  1. Upon upload to the WP Media Library
  2. On the front end, using buttons, links, or forms created via shortcodes
  3. In the Wordpress admin TCPDF “test kitchen”

Upon upload to the WP Media Library

This method is optional and should be used with care. Bear in mind that once a PDF is altered by TCPDF, and especially if it is encrypted, it cannot be altered again, so if you are running a PDF through TCPDF while uploading to the media library, it will be saved to your library with a static watermark and might not be watermarked again. Dynamic shortcodes such as [FIRSTNAME] [LASTNAME] [EMAIL] etc. will not work for you, for hopefully obvious reasons. Skip to read about Test Kitchen or Shortcodes if you want to use these dynamic shortcodes. (Frankly, we don’t expect this method to be used as much as the other two methods.)

For this feature you’ll want to start with the TCPDF Bridge Settings page (yoursite.com/wp-admin/options-general.php?page=wptcpdfb-settings). Carefully review and fill out the options there. Assuming you have selected to alter all or just some of your PDFs, now when you upload those PDFs to your Wordpress media library, they will be altered. Embed, share, and download them off your site as you like.

On the front end, using buttons, links, or forms created via shortcode

The next tab in the TCPDF Bridge settings area is the shortcode generator. It looks like this, and will have a list of your shortcodes at the bottom if you create any:

Shows the settings for the Shortcode tab of the TCPDF Bridge plugin

The generator creates a small piece of code in [brackets] which you can place in your posts, pages, and widgets where you want a link to a particular PDF, and want that PDF altered upon download click. Experiment with the settings to get the type of link you desire. You can opt to collect user information (name, email) before the download continues, and use that personal information to mark the PDF. If your user is already logged in, you can opt to use their saved personal information to mark the PDF.

Your shortcode might look like this:
[wptcpdfb id=90210 /]
(replace 90210 with the shortcode ID you’ve created in the shortcode generator)

In the Wordpress admin TCPDF “test kitchen”

The Test Kitchen allows you to Watermark PDFs on-the-fly, anytime from the Wordpress admin panel. Just choose a PDF, set your watermarking options (font, color, text, placement, etc.), head over to the “Test Watermark” tab, and click a button. The watermarked file will appear in a new window (or via dialog for download, depending on your browser). The watermarked file is NOT saved to your Media Library, so if you need that, check out this feature. If you’d like to flesh out some dynamic shortcodes from your overlay and footer watermark content with actual personal information, use the fields under the “Test Watermark” tab.

Shows the settings available for Test watermarking/stamping PDFs with plugin

If you are familiar with WP and PHP you can use the filter hook ‘wptcpfb_wildcard’ to match your own content with the [WILDCARD] shortcode. Many other hooks are available in this plugin for customization, take a look!

Notes

Front-end watermarking stores watermarked files on your server. In order for TCPDF to watermark the same PDF file over and over again, the watermarked versions must be at least temporarily stored somewhere so they can be delivered. The plugin tries to use the system tmp folder, which is emptied regularly, but there are cases where it will not be used:

  1. When the ‘wptcpdfb_use_uploads_dir’ filter hook is set as TRUE
  2. When the inline link shortcoded, which uses AJAX to watermark and deliver, is used

In these cases you will find your watermarked PDFs in a ‘wp-tcpdf-bridge’ folder inside your Wordpress uploads folder. They will be organized by date and time. Over the years many users have expressed interest in keeping these files; others are concerned about the space they consume on the server. You can use the “Housekeeping” setting in the main settings panel to have them removed automatically once a week.


Recommendations

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. And remember, we fully support and maintain the Bridge, but not TCPDF. (tcpdf.org)

PHP Version

We recommend you run PHP version 7.0 or higher. WP TCPDF Bridge is PHP version 7.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 TCPDF demands much more efficiently! This is the first thing you should try if you’re running out of memory while processing PDFs.

Increase Memory

Increase your PHP memory allotment to at least 64MB. We recommend a 128MB, 256MB or maybe even 512MB setting (don’t keep increasing this expecting it to solve all your problems; though. You could cause problems). 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.

Large PDFs?

If you are having trouble sharing large PDF files, keep in mind that your hosting plan needs to be robust enough to support the memory and bandwidth necessary to fulfill these requests. Try these suggestions: https://tcpdf.org/docs/performances/. (FYI Thai characters are already disabled in TCPDF.) Keep your watermarks simple (avoid HTML if possible, and remember that file protections/passwording also make huge demands on your server).

Maybe it’s time for a server upgrade?

Opacity Shortcodes

The {OPAC} shortcode — and watermarking with opacity — is totally unique to this plugin is very helpful for people not wanting to obscure their PDF content, since the watermark sits on top. It doesn’t always play nice with HTML in your watermark, so sometimes some rearranging will need to be done. Consider wrapping your HTML inside {OPAC} tags if trying to get opacity, if the inverse isn’t working.
Examples:

{OPAC-0.5}This is sample text{/OPAC}

“This is sample text” will be at 50% transparency. The tag needs a dash, then a number representing the fraction of 100% opacity.

{OPAC-0.1}This is very transparent text{/OPAC}

“This is very transparent text” will be at 10% transparency.

Note there is an open tag and a close tag around the text. If text does not wrap when using this tag, you may have to use HTML
tags. {OPAC} tag is still beta.

Text alignment

Some HTML can be used in watermark content, so go ahead and experiment to see what you can get away with!

To style a link <a> or tag when using HTML, the following inline CSS options are available: font-style:italic, font-weight:bold, and text-align:center and text-align:right. This feature allows you to center text – yay!

Here’s an example of the code used to center some (bold) text.

<span style="text-align: center; font-weight: bold;">center some bold text</span>

This might also work:

<span style="text-align: center"><strong>center some bold text</strong></span>

In case you need it, RTL watermarking can be selected in the TCPDF Bridge settings by clicking a checkbox.

Other Topic?

WP TCPDF Bridge is built with TCPDF, just like EDDiMark and WaterWoo (also sold here). We recommend you review their documentation and blog posts about them, as they do have overlap in function.