Tag Archives: PDF Creation Station

Using Kalin’s PDF Creation Station when wp-config.php is in a Non-Standard Location

If you are trying to use my PDF Creation Station WordPress plugin and you have moved your WordPress installation’s wp_config.php file to a different location, the creation script will fail. You can fix this easily (I’m assuming if you know enough to move around your wp_config.php file that you know a little about PHP) if you go into your plugin directory /kalins-pdf-creation-station/kalins_pdf_create.php and go to the line, require_once("../../../wp-config.php"); and simply change this to refer to your wp-config.php location.

Using Foreign Characters in Kalin’s PDF Creation Station

The following are instructions for fixing font and character related problems such as foreign character sets in Kalin’s PDF Creation Station WordPress plugin.

First,  download the full version of TCPDF Engine. This is the same PDF engine that is included in Creation Station, except it has more fonts and other stuff I originally removed to conserve file size.

Now, extract the tcpdf folder to a workspace on your desktop. Go into the tcpdf/config folder and open tcpdf_config.php. In this file you can find some configuration variables that you can play with to adjust fonts, margins and whatnot. Find the line, define (‘PDF_FONT_NAME_MAIN’, ‘helvetica’); and, define (‘PDF_FONT_NAME_DATA’, ‘helvetica’); Now simply change ‘helvetica’ (or whatever font might be set) to whichever included font you’d like, such as ‘courier’, ‘times’, ‘dejavusans’, ‘freemono’ etc. You can look in the fonts folder to see which other fonts are available. There seems to be many different versions of the same fonts. Experiment until you find one that includes the character set you need. For example, using dejavusans seems to solve some issues with Turkish characters. (If you can’t find the font you like, you can visit the TCPDF website to see how to add new fonts. It’s a little more complicated and requires running some command-line functions. I haven’t personally tried it, but I’ve heard that it works. If you can’t figure it out, send me your font and I’ll give it a shot.)

Next, FTP into your server, find your wordpress/wp-content/plugins/kalins-pdf-creation-station/ directory. Copy your new tcpdf folder into the directory, overwriting the original tcpdf folder. (You might want to make a backup first to be safe.) Now you should be ready to go. Just start creating PDF files and check to make sure the characters show properly. Obviously you can keep re-uploading the tcpdf_config.php file to its appropriate location to test new fonts if you don’t have a local development environment.

Remember to make a local copy of your new tcpdf folder because you will need to re-upload it every time you upgrade the plugin.

Edit: somebody emailed me about this topic and wrote the following. I’m not sure what he’s talking about as it’s been a long time since I’ve looked into the code for these plugins, but here’s what he said. It sounds like it could be helpful.

hint: if somebody with the same problem contact you, it’s right that the font has to be changed to font with type ‘TrueTypeUnicode’ in order to know which one is the correct type, it is necessary to open the [font-name].php in text editor or php editor and check the properties of the font.

PDF Creation Station – hard code PDF link into theme

This post is for users of Kalin’s PDF Creation Station WordPress Plugin who want PDF files automatically generated for pages/posts, but want more control over the placement/appearance of the link or want better performance over the automatic link generation method.

First, get into your theme files. You can hit ‘Editor’ under ‘Appearance’ in your WordPress admin which will allow you to edit your theme files directly. I’ve had issues with this, however, with mysterious bugs creeping into my code. I recommend using FTP to get your theme files, making a backup, then editing and re-uploading them.

Find the file you want to add the link to, probably sidebar.php, header.php or footer.php, or something like that, then add this code:

<?php
if(is_single()){
     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=po_' .$post->ID .'">Download this post as PDF</a>';
}else{
     if(is_page()){
          echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=pg_' .$post->ID .'">Download this page as PDF</a>';
     }
}
?>

Then replace ‘my-domain’ with your own domain. If you have a non-standard WordPress configuration you will need to look at the rest of the urls to make sure they match your directory structure.

This will add the link on any page or post, but show nothing on other pages.

If you are adding this to your single post or page templates, or inside “the loop” instead of into a footer, header or sidebar, you theoretically won’t need the check if it’s a page or post. Use this on the post template:

<?php
     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=po_' .$post->ID .'">Download this post as PDF</a>';
?>

And there’s only  a small change for use on the page template:

<?php
     echo '<a href="http://my-domain/wordpress/wp-content/plugins/kalins-pdf-creation-station/kalins_pdf_create.php?singlepost=pg_' .$post->ID .'">Download this post as PDF</a>';
?>

Now that you’ve hard-coded your link, you can optionally turn off the automatic link adding functionality in the plugin to get a slight performance increase. It won’t make a huge difference and you will need to re-do this every time I upgrade the plugin so it may or may not be worth your time.

FTP  into your plugins directory and find /kalins-pdf-creation-station/kalins-pdf-creation-station.php (or use the editor in your WordPress admin panel). Scroll to the very bottom of the file and find the line,

add_filter("the_content", "kalinsPDF_content_filter" );

Comment the line out so it looks like:

//add_filter("the_content", "kalinsPDF_content_filter" );

Commenting out this line will prevent the plugin from running any functions when a blog page is displayed to a user, minimizing the plugin’s server resource usage.

If you’re concerned about the performance of your admin panel you can then scroll up in the file (currently line 70, but this may change) to find and remove the following code (or something similar if something has changed since writing this post):

//--------------you may remove these three lines (comment them out) if you are using hard-coded PDF links in your theme. This will make your admin panels run slightly more efficiently.--------------
 add_action('save_post', 'kalinsPDF_save_postdata');
 add_meta_box( 'kalinsPDF_sectionid', __( "PDF Creation Station", 'kalinsPDF_textdomain' ), 'kalinsPDF_inner_custom_box', 'post', 'side' );
 add_meta_box( 'kalinsPDF_sectionid', __( "PDF Creation Station", 'kalinsPDF_textdomain' ), 'kalinsPDF_inner_custom_box', 'page', 'side' );
 //--------------------------------

If the code comments give you information that differs from what you read here, trust the code comments as they are more likely to be up-to-date.

I posted my WordPress Plugin

Keeping my fingers crossed that this is gonna work and people are gonna find this useful. I just posted Kalin’s PDF Creation Station to the WordPress.org directory. For some reason it doesn’t show up in the general terms search and I’m not sure why. Hopefully the data just needs some time to populate to whatever is running their searches. However, it does show up in the list of brand new plugins and is available for official download from WordPress and the stats say that 19 people have downloaded it.

Hopefully I didn’t just crash 19 websites 🙂

No, I’m just kidding. I actually think this plugin is probably safer than most other WordPress plugins, considering what I’ve been seeing lately as I delve into the code of various other plugins. I see PHP errors being thrown left and right, even in some of the most popular, highly rated plugins, to the point where turning error reporting on is not even an option in development unless I strip out most of the other plugins from my local WordPress installation. I see tons of old plugin garbage in my database and from what I’ve read from plugin reviewers, it’s rare for developers to implement security nonces in their ajax calls, and some don’t even give unique prefixes to their function names. For Creation Station I took time to make sure that I followed all the WordPress recommended coding procedures (with the exception of the whole translation system, but I can always add that in later if someone starts yelling at me in another language) including nonces (making sure I used them properly), function prefixes, deactivation procedure, only loading assets like jquery or CSS on the appropriate admin pages, loading assets in footer instead of header, using only two database entries for a multitude of configuration options and whatever other proper procedures I can’t think of at the moment.

Anyway, I’m excited that I’m contributing something physical and functional to the open-source community.

Code is poetry.

Can Anyone Test my PDF Creation Station WordPress Plugin?

So if anyone out there has a WordPress Blog, I built a WordPress plugin that I think is kinda awesome and would love you to test: Kalin’s PDF Creation Station that can be used to automatically build highly customizable PDF compilations of certain portions of your website, or to add a link to each page/post to download that page/post as a PDF. Plugins like this already exist for WordPress but none with nearly as many features.

According to the articles I’ve read about WordPress plugins, Kalin’s PDF Creation Station is probably safer than most of the other plugins out there. I was careful to implement all the recommended security procedures for all server calls. All my functions are properly prefixed to be unique and I have a full deactivate feature so that once deactivated, my plugin doesn’t leave any stray database garbage, something which, even in the big, professional plugins, isn’t always implemented.

However, despite my confidence in the solidity of my code, I’m still worried about jumping into this and simply posting the plugin to the community. Last time I released an application I had built to a community for free use, someone told me that I deserved to “rot in hell” because he had difficulty figuring out the user interface. That might be an extreme example, but I personally believe that even in the open source community, where no one is getting paid, we still have a moral obligation to provide decent quality assurance before release. If it’s not solid enough to work without making people scream at their computer, then it shouldn’t be released as anything more than an alpha test.

Unfortunately, my own testing and this blog post are really the only quality assurance systems that I have in place 🙁

So I know I probably won’t get any responses since I still have such a small reader base (though according to Google Analytics, my visitor count is growing rapidly), even so I was hoping someone would be willing to take this plugin and install it on their system and let me know if it’s usable and understandable and if anything blows up.

So here’s the plugin download.

Installation instructions are pretty much the same as any other WordPress plugin. Unzip the source code into your plugins directory in your WordPress installation then go into your plugins admin panel and activate it. PDF Creation Station then shows up in both the settings and tools sections in the left sidebar of your admin. The Creation Station Tool page is for compiling large PDF files of any portion of your site. The settings page is for setting defaults for automatic PDF generation for individual pages and posts.

PDF Creation Station Test

Last night I updated my first WordPress plugin, Kalin’s PDF Creation Station on this site, and somehow it all worked wonderfully. Now the links you see to download my posts as PDF files are coming from my own plugin instead of the AS-PDF plugin I was using earlier.

I was able to figure out how to get a simple regular expression to find and remove the image caption code, so if you go to spirit animals sketch, for example, and click the PDF link, you’ll see that the image actually shows up without all the extra code garbage you would see when I was using AS-PDF. You’ll also notice that the PDF link does not show up on certain pages like table-of-contents pages or this post. In the old plugin it was all or nothing and I couldn’t turn it off for individual pages. AS-PDF also wasted server resources by creating a PDF every time the link was clicked. With my plugin, each file is created once, then cached.

That’s for the single-post feature of this plugin. What this plugin is primarily for is to create large PDF documents with many pages and posts. That functionality is ready to go, but I still need to go through and create a PDF file that contains all my True Stories, one that contains all my ‘Stories of New Beginnings’ stories, one for the Against A Rock bonus materials and possibly one for all my blog entries. Once that’s all done, I just need to wait a week or two and make sure nothing gets hacked or blows up, then I’ll post this baby to the WordPress plugin repository and see what the community thinks of my little project.

My First WordPress Plugin: Kalin’s PDF Creation Station

I just installed my first self-written WordPress plugin, called Kalin’s PDF Creation Station, which adds a page into my admin panel where I can select any combination of pages and posts, then export them to a PDF file which is saved in the plugin directory. This has been something I’ve wanted to do for years, to be able to parse through my writings and dynamically create PDF files so that I can distribute my collections as single books, and I’ve never been able to find a way to do it until now. There’s a few other PDF creation plugins out there for WordPress, but they’re all quite limited. I based this plugin off of Marcos Rezende’s Blog as PDF and basically took his code (one of the beauties of open source is the ability to “steal” and improve upon other people’s work) and added a bunch of cool features like the ability to add pages as well as posts, to select individual pages and posts, to insert a custom title page, page titles, page headers, font size and to automatically save it to the server instead of forcing a download. I also ajaxified it so that the page never needs to reload throughout creating and deleting PDFs and altering input fields.

I have not released this plugin to the WordPress community yet because I want to test it a little more, tweak my default data, and write a decent plugin page and instructions. Hopefully I’ll be able to actually have people downloading and using it in the next couple weeks.

In the future, I hope to add a feature where PDF files will be automatically updated when you update a post, and if I can think of a good user interface, when you add new posts or pages. Then I want to replace the per-page PDF generator plugin I’m currently using with something that can be configured for each individual page and post so I don’t have a link to a PDF for a page that’s only a few paragraphs long. Then I want to create a stripped down version of the Kalin’s PDF Creation Station and pop it in a widget so that blog readers can select only the pages and posts and get a personalized PDF file. But first I need to finish the ‘change page order’ feature I’m currently working on.