Wordpress, Combining ContuttoPDF with Code Snippet Plugin to get your code sample printed on the PDF
Posted by Daniel - 751 Views
I also use Code Snippet plugin. It’s a plugin to provide syntax highlight for programming code within the post. I want the formatted code produced by the Code Snippet is also printed in the PDF output with the same appearance as what Code Snippet does on the web page.
But unfortunately it won’t happen automatically, the ContuttoPDF does not recognize the Code Snippet formatting request tag when producing the PDF file, so you need to modify the code to get the intended result. Here is the list of steps you can follow to get the Code Snippet format printed on the PDF file:
1. Navigate to /wp-content/pdf-themes/default/ then open the pdf.php file with your text editor. Find this line of code within the file, if it has not changed yet it will be the line 135:
2. With the assumption you had the Code Snippet plugin installed, please change the line of code mentioned above with the following code:
$pdf_output .= ‘<p class="entry">’ .wpautop($CodeSnippet->;highlightCode($post->;post_content)) . ‘</p>’;
unset($CodeSnippet);
The trick is to create a new instance of Code Snippet and then pass the post_content to the highlight_code() function. You can save your pdf.php file now.
3. Open your style-print.css file with your text editor. style-print.css is located on the same path as above: /wp-content/pdf-themes/default/, then paste this CSS styling on the file:
.codesnip { text-align:left; direction: ltr; }
.codesnip .de1, .php-brief .de2, .php .de1, .php .de2 {font-weight:normal; background:transparent;color:#000; }
.codesnip .kw1, .php .kw1 {color: #a1a100;}
.codesnip .kw2, .php .kw2 {color: #000; font-weight: bold;}
.codesnip .kw3, .php .kw3 {color: #000066;}
.codesnip .kw4, .php .kw4 {color: #f63333;}
.codesnip .co1, .codesnip .co2, .codesnip .coMULTI, .codesnip .co1, .codesnip .co2, .codesnip .coMULTI {color: #808080;}
.codesnip .es0, .php .es0 {color: #000033; font-weight: bold;}
.codesnip .br0, .php .br0 {color: #66cc66;}
.codesnip .st0, .php .st0 {color: #ff0000;}
.codesnip .nu0, .php .nu0 {color: #ff33ff;}
.codesnip .me0, .php .me0 {color: #006600;}
Ok Done! Save the style-print.css then have it tested. Hope everything goes well, if you find anything which maybe incorrect please let me know - I could be wrong to sometimes :D
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
- ContuttoPDF (Wordpress Plugin to convert your Content to PDF)
- Customizing the PDF file created with ContuttoPDF Wordpress Plugin
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- The Modified Version of phoogle WordPress plugin - Eliminating the needs of Exec-PHP
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!

















