Tag Archives: python

Double page numbers in XHTML2PDF/Pisa

I’ve been working on a django project recently that generates PDFs from html using the XHTML2PDF library (formerly Pisa). I have html successfully in a pdf in just a couple lines, so overall it’s fantastic, but there are some quirks to get around. I ran into one of these quirks today while trying to put page numbers in my footer template – when it rendered, every page was showing its page number twice (11, 22, 33). My code looked fine; no extra tags, everything was properly formatted, etc, but I could not stop it from happening. Here is my page/footer style and my extremely simple footer markup.

@page {
	size: {% if pagesize %}{{pagesize}}{% else %}letter{% endif %};
	margin: 1cm;
	@frame footer {
		-pdf-frame-content: footerContent;
		bottom: 1cm;
		margin-left: 1cm;
		margin-right: 1cm;
		margin-top: 0cm;
		height: 1.4cm;
	}
}

...

<div id="footerContent">Page <pdf:pagenumber /></div>

Finally I got smart and found this answer on the mailing list. Essentially its a bug in the xhtml2pdf parser – without a new line after the tag it freaks out and decides you meant it twice. Interesting bug, but not interesting enough for me to go look at their parser code to figure it out. :)

Anyway, this simple change fixed the problem and hopefully you won’t waste any time banging your head on the desk with page 11, 22, etc.

<div id='footerContent'>
 Page <pdf:pagenumber />
</div>

Another Chronolapse Update

I’ve been feeling productive and I knocked down the rest of the todo list for Chronolapse.

You can see the project page here

Here is the change log for version 1.0.3

  • fixed a bug with times under 1 second being fired 1000 times too fast
  • silently fails if set to capture 2 monitors but they are duplicated
  • added system wide hotkey — doesnt seem to work right in wx so it is only part implemented
  • added audio tab to dub audio onto your timelapse
  • added a drop shadow option for annotations
  • added a schedule tab for scheduling starts and/or stops

Building CX_Freeze on the Mac

This isn’t my info — it is from the SourceForge mailing list — but it is so damn helpful that I wanted to re-post it in case it helps someone find it in the future.

Where I originally saw it: http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00334.html

I had to make the following changes to get cx_Freeze to work on the Mac

Before building

change ldd in freezer.py to otool -L
mkdir -p Python.framework/Versions/2.6/
ln -s /Library/Frameworks/Python.framework/Versions/2.6/Python
Python.framework/Versions/2.6/

Before running a built executable

mkdir /lib /include
ln -s /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/lib/python2.6
ln -s /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6
/include/python2.6

Jeffery G. Smith
MedPlus, A Quest Diagnostics Company | Senior SCM Specialist | 4690 Parkway
Drive | Mason, OH 45040 USA | phone +1.513.204.2601 | fax +1.513.229.5505 |
mobile +1.513.335.1517 | jsm…@medplus.com | www.MedPlus.com

Flame Version 1.2.0 — Windows Installers made easy?

Flame is a tool I wrote last year to take the nightmare that is working with WIX and make it easy to create a nice looking installer on windows with some important features (Shortcuts, Registry, File types, Custom Branding). I absolutely detest writing their inane xml by hand and generating then looking up GUIDs makes me want to hurt someone. So, instead of all that nonsense, you can simple run Flame and create a .kflame file for your project. You pick your files and some simple options, set up shortcuts and registry entries, and it does the rest. You don’t even have to run any of the wix exes, it does it all for you. Next time you want to make the installer, you just open the file with Flame, hit go, and you’re done. No retyping, no looking up GUIDs, no insanity.

This week I needed to create an installer for one of my other projects and decided it would be a good time to dust off Flame, fix the bugs, and add some features. Behold, the fruits of my labor, version 1.2.0. It successfully built its own installer, as well as some test ones, with no problems. However, due to the vast differences in how developers set up their projects, it would be incredibly helpful to get some real world testing done and get feedback on success/failure.

Here is the keeyai.com page for Flame, and here is the sourceforge page where you can actually get the files. Good luck, and may you spend your precious time developing instead of pulling your hair out over WIX’s inanities.

Creating console-less executables with python and CX Freeze

Eventually when making apps in python you run into the problem of needing to distribute executables instead of just source code. Jumping this hurdle requires you to use one of a couple libraries, the common ones being py2exe (windows only), pyinstaller (win and *nix), and cxfreeze (win, *nix, and mac). Each one works a little differently and has its own quirks. Over the years I’ve created my own little build script that uses pyinstaller or cxfreeze (which I’ll release in a GUI one day to compliment Flame) which usually works and puts things where I want them. THIS time, however, I was running into issues with pyinstaller ( which I prefer over cxfreeze because of its 1 file option) and had to use cxfreeze. Unfortunately, my easy code for making cxfreeze work basically fakes running the script itself instead of using the “python setup.py build” format the docs seem to prefer and I could not for the life of me find how to build an executable that way WITHOUT the console open in the back. However, it actually is quite simple, so I’m documenting it here both for the world and for my own reference later on down the road.

The relevant part of my script looks like this:

from cx_Freeze import main
sys.argv = [sys.argv[0], '--target-dir', '%s'%DISTFOLDER, '--base', 'Win32GUI', entrypoint ]
main()

You’ll need to put in your target directory for DISTFOLDER and your entry point script for entrypoint. The console-less part is as simple as the –base Win32GUI tag, but good luck finding that anywhere.