Tag Archives: WordPress

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.

More WordPress theme stuff

I’m just going over my whole WordPress setup for this site in case anyone is interested or wants to give advice. If you know anything about WordPress and see me doing something stupid, please go ahead and write a “Hey dumbass” response to this post or my previous post about the wordpress plugins I use.

I use the Inanis Glass theme, basically because I couldn’t find anything better. Most of the free themes look like crap. I’m not a designer by any means, but I know enough to say that most of the wordpress themes I could find just don’t look good, especially for a science-fiction themed website. I did a search for “best SEO wordpress themes” and came up with this site: http://wphacks.com/best-search-engine-optimized-seo-wordpress-themes/ and this one: http://www.seohosting.com/blog/blogging-tips/5-free-seo-wordpress-themes/. Both sites list a bunch of wordpress themes that they claimed were well-optimized for search engine optimization (SEO), but only one or two of the ones listed actually existed when I searched for them in the theme listing in my dashboard.

However, based on their lists of criteria for a good SEO theme, Inanis Glass seemed decent. It’s got the content at the top and seems to come close to validating for properly formatted HTML, though I’m not sure why that’s relevant. I did make a couple changes though, like changing the <H1> tag at the top to show the name of the post instead of the blog title, since I’ve read that’s really important to SEO to have your keyword rich title at the top instead of the site title. I still need to figure out my tagline.

I also almost completely removed the footer where it had a little windows style start menu with search and login features and stuff, as well as some popup menus that didn’t look very good. The pages seem to load a little faster since getting rid of that.

If you have any suggestions for a better theme or other theme-alterations I could make (particularly SEO related), I would greatly appreciate it.

My WordPress SEO Plugins and stuff

I’ve been spending my evenings lately just working through all the ins and outs of this WordPress thing, studying Search Engine Optimization (SEO), link sharing and pouring through a multitude of WordPress plugins. I thought I would list off the plugins I have mostly decided on and describe some of my SEO strategies for this site in case anyone wanted to make some comments or give me advice, or if I happen to hire a WordPress SEO consultant to point out all the mistakes I’m making.

These are the plugins I use.

Add RSS – not totally sure what this does. I think it gives certain browsers some kind of access to my site’s RSS feeds, like if someone has their feed reader turned on within the browser.

AddToAny: Share/Bookmark/Email Button – the button in the upper right of the sidebar that gives the sharing menu

All in One SEO Pack – I use this to write my own descriptions, keywords and title tags, and because it has the feature of changing the link names in the sidebar because I don’t like multi-lined links but the real titles often need to be slightly longer than what will fit on  a line. SEO Ultimate, which I use for a few other things, doesn’t have this feature.

AWS Easy Page Link – adds a list of pages in the add link tool in the editor so I can easily make table of contents pages. I wish it added blog posts and scheduled pages/posts as well.

Breadcrumb NavXT – adds the breadcrumbs at the top of the posts, which is supposedly good if my content gets scraped (automatically plagairized) and suppedly helps search engines figure out my site architecture. I wonder if I should add them to the bottom of pages too, since some of my pages can be quite long.

cbnet Ping Optimizer – I tend to edit posts a lot so I needed a plugin that would make it only ping on the first post, so I don’t get marked as a spam. Also for the ping log so I can make sure they aren’t blocking me for whatever reason.

Contact Form 7 – just a simple email form on my contact page.

Contextual Related Posts – supposedly good for getting people back from scraped pages – adds a list of ‘related’ posts at the bottom of my posts and pages. Sometimes they don’t seem quite so ‘related’ so I named them ‘random pages’.

Full Text Feed – no idea what this does. I read that I need it to prevent the ‘more text’ thing coming up. I’ve never liked having to click on a more link when I go to blogs. Do I actually need this?

Global Translator – plugs into google translator and gives me the flag cloud in the sidebar – I wonder if the translated pages get indexed by search engines like my english pages do… I also wonder how accurate the translation is. Suppose I will never know since I only speak English 🙂

Google XML Sitemaps – supposedly helps search engines find their way around the site. I think I just turn this on and leave it. Don’t need to link to it or submit it or anything… at least, that’s my understanding.

JR_Compression – Apparantly pages can be zipped, then sent to the client and the browser automatically unzips and shows them, which decreases load times. I think I understand this correctly.

RSS Includes Pages – adds my pages (since the pages are the most important part of my site) into my RSS feeds.

SEO Ultimate – I use this for some of its peripheral features (canonicalizer, slug optimizer, 404 monitor) but use All In One SEO for the actual keyword/description stuff. Thankfully I can disable individual features of SEO Ultimate.

SexyBookmarks – creates the sharing functionity – similar to AddToAny button – to the bottom of every page and post. They claim that the pretty, animated nature encourages more interaction.

Simple Tags – I still need to figure out a good tagging strategy. Still need to explore this plugin a bit more. But since pages are more important on this site, I need pages to be included in the whole tagging system. Would like to be able to put pages into categories as well.

Ultimate Google Analytics – for my site statistics. Is this a good plugin for this? There sure are a lot to choose from.

WordPress Database Backup – absolutely necessary for those times when I do something stupid and overwrite my database.

WP Smush.it – to optimize my images without losing any quality. Not sure if this is necessary since most of my images I do myself through Photoshop or Gimp.

WP Super Cache – for server-side caching . How can I tell if this is working? Not all of my pages seem to be listed in the cached files and I always get a new file whenever I hit refresh.