Wordpress, Combining ContuttoPDF with Code Snippet Plugin to get your code sample printed on the PDF
Posted by Daniel - 2,112 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
Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.
-
Get my Full Feed Here
Popular Entries
- Passing arguments to your VB.NET console application
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- How to Get User Input and allowing more than 256 characters to be entered on .NET Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- An example: Using CPort Delphi Component to read data from your cellphone
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- CPort Component (Serial port interface component for Delphi)
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer













