Tag : Python

Automatically print a PDF generated with ReportLab using JavaScript

It seems everyone is asking how to embed JavaScript in a PDF created with ReportLab.

Google also use this PDF feature to allow for printing of proprietary office documents from their Gmail service. Google's method is somewhat different and they bind the JavaScript to the first object in the document and trigger it by referencing it with the Names entity as shown below.

%PDF-1.4
%âãÏÓ
1 0 obj
<</S/JavaScript/JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)>>
endobj
2 0 obj
<</Names[(0000000000000000) 1 0 R]>>
endobj
3 0 obj

I was not able to use the ...

— Andrew


How to install and setup a Python Django development environment on Windows 7

Step 1: Install Cygwin & Python

To get started we need to setup a Python environment running under Cygwin. First make your way over to cygwin.com and run their installer.

Most of the installation is just clicking next, and accepting the defaults:

Cygwin Python Installation 1

Click next:

Cygwin Python Installation 2

Click next:

Cygwin Python Installation 3

Click next:

Cygwin Python Installation 4

Click next:

Cygwin Python Installation 5

Choose your closest Mirror. We like Internode!

Cygwin Python Installation 6

This is where we stop clicking next and select our packages.

Select Python:

Cygwin Python Django Installation - Package Selection 1

We'll probably need to install a Subversion client, so also select that:

Cygwin Python Django Installation - Package Selection 2

wget will make installing the Django stuff easier:

Cygwin Python Django Installation - Package Selection 3

gcc and gcc++ will be needed later to compile ...

— Andrew


Django PIL Error - The file you uploaded was either not an image or a corrupted image.

When uploading an image with Django admin, or a Django based CMS, you receive the following error:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

The solution, on CentOS, Red Hat and Fedora, is to ensure that Python Image Library (PIL) is installed and compiled after libjpeg-devel is installed:

sudo yum install libjpeg-devel
workon mysite
pip uninstall PIL
pip install PIL

This will compile PIL with the correct JPG support and fix the error above.

— Andrew


Django Resources

After spending the last 6 weeks trawling the Internet for Django resources, I thought it would be worthwhile putting together a page with the best Django resources. So here it is folks! NB. More to come in the following weeks! I will endeavor to keep this page updated over will be adding a lot more content as I have time. Updated, 14th May 2010.

Resource Sites

Documentation

Code

Deployment

— Andrew


How to install Django-CMS on CentOS 5.4 with Python 2.6

The other day I was playing around with Django CMS and battling to get it installed on CentOS 5.4. I thought I'd put these notes together in the hope that someone might find them useful. NB. These instructions are not 100% polished, but should be sufficient to get you up and running.

This will install Django 1.1.1 and Python 2.6 on CentOS 5.4, using Apache and mod_python!

Special thanks to fink from #django-cms on irc.freenode.net for his patience and advice, and the other bloggers around the globe that have written useful articles ...

— Andrew


Site theme originally by styleshout.com