Cannot modify header information

This is one of the weirdest errors I ran into. The full error:

Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/some.php:23) in /home/mysite/public_html/someother.php on line 69

In most cases the solution to this is removing any leading and trailing spaces of your php open and close tags in the some.php file. In other words, remove all spaces before your < ?php tag and after your ?> tag

A simple but very strange solution…

Note: remove the space between the ‘<' and '?php', this is merely done so it gets displayed on this page. ;)

dompdf experiment pt3 – images

An image can be added for use with pdf in two ways:

  1. Let dompdf determine the size for the image acoording to the DOMPDF_DPI setting in dompdf_config.inc.php or
  2. Determine the size in CSS using a unit other than pixels

Method 1: place your image in your html doc and change the line following line to your preferred DPI setting:

define(“DOMPDF_DPI”, “300”);

Note: This gives you little control over the width/height of the image used in your pdf. (Keeping in mind that you might want to do this dynamically and let users upload their own images)

Method 2: set the image size in your CSS, ie:

img.fixedsize {
width: 150mm;
}

This gives the image (with class name ‘fixedsize’) a fixed width of 150mm. Very usefull to stay ‘true’ to a certain layout.
Note: The disadvantage of this method is that an image can be too small to decently use in your predefined size and thus appears grainy in your pdf file.

All in all this works fine and I ran into no trouble at all.

dompdf experiment pt2 – installing a font

The default fonts that come with pdf aren’t enough for me, so I want to install a new font. To do so you need to have ttf2pt1 installed on the webserver. Unfortunately that’s not the case for me. The dompdf manual says the following about having problems installing fonts:

Also, if you have problems installing the font files, you can try and use the distributed dompdf_font_family_cache.dist file in lib/fonts. Copy this file to lib/fonts/dompdf_font_family_cache and edit it directly to match the files present in your lib/fonts directory.

Let’s see if this will work…

EDIT: Ok, found a nice .afm font (serpentine), put it in the lib/fonts dir of dompdf 0.5.1 and edited the dompdf_font_family_cache file, the following has been added:

  1. 'serpentine' =&gt;
  2. array (
  3. 'normal' =&gt; DOMPDF_FONT_DIR . 'SerpeMed',
  4. 'bold' =&gt; DOMPDF_FONT_DIR . 'SerpeBol',
  5. 'italic' =&gt; DOMPDF_FONT_DIR . 'SerpeMedObl',
  6. 'bold_italic' =&gt; DOMPDF_FONT_DIR . 'SerpeBolObl',
  7. )

When I try to make a pdf using this font with dompdf an error is thrown and no pdf is generated…

To be continued…

Edit: An .atm AND .pfa or .pfb file are required to make it work. So now it works great! 🙂

dompdf experiment pt1 – tables

In order to make nice pdf documents from html pages I stumbled upon dompdf. This tool can actually read a html page and output it as a pdf file. The problem with the tool right now is that it doesn’t support ‘div’ positioning (yet), so you have to “layout” everything with tables.
The first test is making a bit more complex table and have that outputted the right way. For now only the rowspan attribute doesn’t seem to work correctly.

DHTML

The simplest of things can be so much fun.

Like changing the background color of a website when you change pages in a flash document. How you do this is quite simple. You just call a pice of JavaScript from Flash, like this:

ActionScript

  1. getURL("js:method(params)", "_self");

An example of this: http://vwg.net/test/su/

note: replace “js” above with “javascript”, somehow wordpress isn’t happy with me using that word… 😉

Class name conflict

Familiar with this error?

The name of this class, 'b', conflicts with the name of another class that was loaded, 'b'.

This can happen when you’re working with files on a server. If the server time is ahead of your computer’s time Flash (at least MX 2004) doesn’t want to compile them.

The solution is simple: either adjust your server’s or computer’s time (and date).